Latex颜色

本文概述

  • 新颜色
  • 文字突出显示
  • 文字背景
  • 页面背景色
  • 彩色线
xcolor软件包支持为文本添加颜色。使用此功能, 可以设置背景, 字体颜色和页面背景。你可以从预定义的颜色中选择颜色, 也可以使用RGB创建颜色。数学公式也可以是彩色的。
在代码或程序中导入的包写为:
\usepackage{xcolor}

下面列出了用于访问不同数量的颜色的命令:
  • usenames:允许访问16种基本颜色。
  • dvipsnames:它允许访问更多64种颜色。
  • svgnames:它允许访问大约150种颜色。
  • x11names:它提供300多种颜色。
上面提到的这些命令在代码中声明为:
\documentclass[dvipsnames, usenames]{beamer}

下面列出了用于输入彩色文本的命令:
有两种输入彩色文本的方法。一种是使用\ textcolor命令, 另一种是使用\ color命令。
textcolor命令被声明为\ textcolor {提及颜色} {text}。
color命令被声明为{\ color {提及颜色} some text}。
textcolor命令用于一个段落中的所有内容, 而color命令用于使文本在其他tex环境和多行上运行。
要更改背景颜色, 可以使用命令\ pagecolor {提及颜色}。此命令为整个页面的背景着色。
要为文本的背景着色, 你可以使用\ colorbox {提及颜色} {text}命令。
如果要同时更改背景和文本颜色, 则可以按以下方式使用命令:
\colorbox{mentioned-color}{text}{\color{mentioned-color}text}

随处使用的原色或所有这些原色的原色是红色, 黄色和蓝色(RYB)。三种主要颜色是橙色, 紫色和绿色, 它们是通过混合两种主要颜色而形成的。有六种第三色, 它们是通过混合原色和第二色形成的。
下面列出了所有系统上可用的预定义颜色:
Latex颜色

文章图片
下面列出了其他预定义的颜色:
Latex颜色

文章图片
让我们考虑一个简单的示例来为文本着色。代码如下:
\documentclass[12pt]{article}\usepackage[dvipsnames]{xcolor} % declaring the package is necessary to implement colors\begin{document}The text is written here.\\\textcolor{red}{the purpose of learning \LaTeX\ is great.}\\ %this \LaTeX\ pattern is used to print the default layout of the work Latex.This is also the text\end{document}

输出:
Latex颜色

文章图片
下面是给不同的行着色的代码:
\documentclass[12pt]{article}\usepackage[dvipsnames]{xcolor}\begin{document}\textcolor{red}{This the text} \\\textcolor{magenta}{the purpose of learning \LaTeX\ is great.} \\\textcolor{yellow}{the lines of different colors}\\\textcolor{pink}{the text is written above} \\\textcolor{green}{The software used is Texmaker.} \\\textcolor{orange}{the text is a combination of words and sentences.}\end{document}

输出:
Latex颜色

文章图片
新颜色 也有一些颜色。如果这些颜色不足, 则可以创建颜色。
要在包中定义新颜色, 你需要包括xcolor包。用于创建新颜色的命令是:
\definecolor{color name}{prototype}{specifications}

在这里, 规格表示颜色的描述, 原型就是模型。有五个基本模型或原型, 分别是灰色, RGB, RGB, HTML和cmyk。下面列出了不同型号的阴影范围以及原型和规格说明:
一世。灰色:灰色阴影的范围在0(黑色)和1(白色)之间。例如, 0.89将是非常浅的灰色, 而0.20将是深灰色。为浅灰色定义的命令将是:
\definecolor{light-gray}{gray}{0.92}\definecolor{dark-gray}{gray}{0.20}

ii。 rgb:定义了三种颜色, 分别是红色, 绿色和蓝色。范围是0到1。命令写为:
\definecolor{orange}{rgb}{1, 0.5, 0}

iii。 RGB:在此原型中, 数量用每种颜色的0到255之间的数字表示。该命令写为:
\definecolor{orange}{RGB}{255, 127, 0}

iv。 HTML:这是以RRGGBB格式编写的六个十六进制数字。格式类似于HTML中使用的格式。 html的命令写为:
\definecolor{orange}{HTML}{FF7F00}

v。cmyk:代表青色, 品红色, 黄色和黑色。颜色的数量表示在0到1之间。命令写为:
\definecolor{orange}{cmyk}{0, 1, 0.5, 0}.

混色命令的代码如下:
\documentclass[12pt]{article}\usepackage[dvipsnames]{xcolor}\begin{document}{\color{red!50!yellow}colored text}\\ % it is a mixture of 50 percent red and 50 percent yellow{\color{pink!80!yellow}\LaTeX\ text}\\{\color{white!60!red}Some text}\\{\color{blue!25!orange}this is text}\\ % it is a mixture of 25 percent blue and 75 percent orange{\color{blue!55!orange}Nice text}\\{\color{green!70!yellow}Any text}\\{\color{blue!20!white!30!green}Beautiful text}\\ % it is a mixture of (20*0.3) percent blue, ((100-20)*0.3) percent white and (100-30) percent green{\color{pink!40!red!50!yellow}colored text}\textcolor{blue}{This the text} \\\end{document}

输出:
你可以注意到新颜色和颜色百分比分布之间的差异。
Latex颜色

文章图片
原型命令的代码如下:
\documentclass[14pt]{article}\usepackage[dvipsnames]{xcolor}\begin{document}{\color[rgb]{0, 0, 1} The text will look blue-colored} \\\textcolor[rgb]{0, 1, 0}{The text will look green-colored} \\{\color[rgb]{1, 1, 0} The text will look red-green color mixture} \\\textcolor[rgb]{1, 0, 1}{The text will look red-blue color mixture} \\\end{document}

输出:
Latex颜色

文章图片
你也可以在一行中插入两种或多种颜色。这种类型的代码如下:
\documentclass[14pt]{article}\usepackage[dvipsnames]{xcolor}\begin{document}This is the {\color{red!80!yellow}\LaTeX\ text}\\{\color{blue!70!yellow}This topic contains} {\color{white!60!red}Some text}\\\end{document}

输出:
Latex颜色

文章图片
文字突出显示 有用于突出显示文本的命令。你可以根据需要选择任何颜色来突出显示文本。你需要一个带有xcolor包的soul包来实现突出显示的文本。
灵魂包写为\ usepackage {soul}
突出显示文本的命令写为\ hl {any text}。此处的“ hl”命令用作突出显示标题。
【Latex颜色】下面是突出显示文本的简单代码:
\documentclass[12pt]{article}\usepackage[dvipsnames]{xcolor}\usepackage{soul}\begin{document}\begin{center}\textbf{\color{red}The highlighted text below :}\end{center}The text given here is the \hl{highlighted text.}\end{document}

你可以在上面的示例中看到, 我们使用了粗体命令, 颜色和高亮命令。
输出如下图所示:
Latex颜色

文章图片
要指定颜色突出显示, 你需要使用\ sethlcolor {颜色名称}命令。你也可以在一个程序中使用许多颜色突出显示。
颜色高亮显示的代码如下:
\documentclass[12pt]{article}\usepackage{xcolor, soul}% you can also write both the packages in this format\begin{document}\begin{center}\textbf{\color{blue}The color highlighted text below :}\end{center}\sethlcolor{pink}The text given here is the \hl{highlighted text in pink.}\\\sethlcolor{orange}The text given here is the \hl{highlighted text in orange.}\end{document}

输出:
Latex颜色

文章图片
文字背景 你可以使用\ fcolorbox {框架的任何颜色} {任何背景的颜色} {text}命令来更改文本背景颜色以及该背景的框架/边界颜色。可以使用\ colorbox {anycolor} {text}命令更改文本背景。
要更改文本背景, 代码如下:
\documentclass[12pt]{article}\usepackage{xcolor, soul}\begin{document}\colorbox{green}{The text is written here}\\ \\\colorbox{lightgray}{The text is written here}\end{document}

输出:
Latex颜色

文章图片
要更改文本背景和框架, 代码如下:
\documentclass[12pt]{article}\usepackage{xcolor, soul}\begin{document}\fcolorbox{red}{white}{The text is the simple \LaTeX\ text}\\ \\\fcolorbox{red}{pink}{This is the normal text}\\ \\\fcolorbox{blue}{cyan}{text is here}% you can choose any color of your choice\end{document}

输出:
Latex颜色

文章图片
页面背景色 你可以使用\ pagecolor {颜色名称}命令更改页面的背景颜色。下面是更改背景颜色的代码:
\documentclass[12pt]{article}\usepackage{xcolor, soul}\begin{document}\fcolorbox{red}{white}{The text is the simple \LaTeX\ text}\\ \\\pagecolor{lightgray}\fcolorbox{blue}{cyan}{text is here}\end{document}

在这里, 我们选择了浅灰色。你可以根据需要更改颜色。
输出:
Latex颜色

文章图片
现在让颜色为橙色。输出将是:
Latex颜色

文章图片
如果选择粉红色, 则输出为:
Latex颜色

文章图片
彩色线 你可以在文档中的任何位置绘制彩色线条。线宽可以根据需要设置。代码如下:
\documentclass{article}\usepackage[dvipsnames]{xcolor}\colorlet{LightRubineRed}{RubineRed!70!}\colorlet{Mycolor1}{green!40!orange!60!}\begin{document}

\ LaTeX的彩色线如下所示:\\
\noindent{\color{LightRubineRed} \rule{\linewidth}{1mm} }\\\noindent{\color{Mycolor1} \rule{\linewidth}{1mm} }\end{document}

在这里, 我们首先创建了颜色, 然后将其用于绘制彩色线条。
输出:
Latex颜色

文章图片

    推荐阅读