Latex 颜色(Colors)

Latex 颜色(Colors) 首页 / Latex入门教程 / Latex 颜色(Colors)

xcolor软件包支持为文本添加颜色。使用此函数,可以设置背景,字体颜色和页面背景。您可以从预定义的颜色中选择颜色,也可以使用RGB创建颜色。数学公式也可以是彩色的。

在代码或程序中导入的包写为:

无涯教程网

\usepackage{xcolor}

下面列出了用于访问不同数量的颜色的命令:

链接:https://www.learnfk.comhttps://www.learnfk.com/latex/latex-colors.html

来源:LearnFk无涯教程网

  • usenames        -  它允许访问16种基本颜色。
  • dvipsnames    -  它允许访问更多64种颜色。
  • svgnames        -  它允许访问大约150种颜色。
  • x11names         -  它提供300多种颜色。

上面提到的这些命令在代码中声明为:

\documentclass[dvipsnames, usenames]{beamer}

下面列出了用于输入彩色文本(colored text)的命令:

有两种输入彩色文本的方法。一种是使用\textcolor 命令,另一种是使用\color 命令。

    textcolor -  命令声明为\textcolor {mentioned-color} {text}

    color           -  命令被声明为{\color {mentioned-color} some text}。

    textcolor    -  命令用于一个段落中的所有内容,而color命令用于使文本在其他tex环境和多行上运行。

要更改背景颜色,可以使用命令\pagecolor {mentioned-color},此命令为整个页面的背景着色。

要为文本的背景着色,可以使用\colorbox {mentioned-color} {text}命令。

如果要同时更改背景和文本颜色,可以按以下方式使用命令:

\colorbox{mentioned-color}{text}{\color{mentioned-color}text}

随处使用或作为所有颜色根源的原色是红色黄色 和 蓝色(RYB)。三种主要颜色是橙色,紫色和绿色,它们是通过混合两种主要颜色而形成的。有六种第三色,它们是通过混合原色和第二色形成的。

下面列出了所有系统上可用的预定义颜色:

Latex Colors

下面列出了其他预定义的颜色:

Latex Colors

让我们考虑一个简单的示例来为文本着色。代码如下:

\documentclass[12pt]{article}
\usepackage[dvipsnames]{xcolor} % 声明颜色包
\begin{document}
    \title{This is my WebSite LearnFK} 
    \maketitle
    
    \begin{center}
    
        \textcolor{red}{Learnfk} tutorials provide programmers with basic introductory tutorials. This site includes Javascript, MYSQL, PHP, Python, Java, \textcolor{green}{Latex}, Flutter, Redis, Nativescript, VueJs, Golang, big data, artificial intelligence and other basic programming tutorials
    
    \end{center}
\end{document}

输出:

Latex Colors

下面给出了为不同的行着色的代码:

\documentclass[12pt]{article}
\usepackage[dvipsnames]{xcolor} % 声明颜色包
\begin{document}
    \title{This is my WebSite LearnFK} 
    \maketitle
    
    \begin{center}
        \textcolor{red}{Learnfk tutorials provide programmers with basic introductory tutorials.}
        \textcolor{magenta}{This site includes}
        \textcolor{pink}{Javascript, MYSQL, PHP, Python, Java, \textcolor{green}{Latex}, Flutter, Redis, Nativescript, VueJs, Golang, big data,} artificial intelligence and other basic programming tutorials
    
    \end{center}
\end{document}

输出:

Latex Colors

新颜色

也有一些颜色。如果这些颜色不足,则可以创建颜色。

要在包中定义新颜色,您需要包括 xcolor 包。用于创建新颜色的命令是:

\definecolor{color name}{prototype}{specifications}

在这里,规格表示颜色的描述,原型就是模型。 gray,rgb,RGB,HTML,cmyk 有五种基本模型或原型。下面列出了不同型号的阴影参数以及原型和规格说明:

i。 gray   -  灰度参数在 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}
    \title{This is my WebSite LearnFK} 
    \maketitle
    
    \begin{center}
    
        \color{red!50!yellow}{Learnfk tutorials provide programmers with basic introductory tutorials.} \\  %red!50!yellow 表示50%的红色与50%的黄色混合色
        \color{blue!80!red}{This site includes} \\  80%的蓝色与20%的红色混合色
        \color{pink!20!red}{Javascript, MYSQL, PHP, Python, Java,} \\ \color{green!50!black}{Latex, Flutter, Redis, Nativescript, VueJs, Golang, big data,}\\ artificial intelligence and other basic programming tutorials
    
    \end{center}
\end{document}

输出:

您可以注意到新颜色和颜色百分比分布之间的差异。

Latex Colors

原型命令的代码如下:

\documentclass[12pt]{article}
\usepackage[dvipsnames]{xcolor} % 声明颜色包
\begin{document}
    \title{This is my WebSite LearnFK} 
    \maketitle
    
    \begin{center}
    
        \color[rgb]{0,0,1}{Learnfk tutorials provide programmers with basic introductory tutorials.} \\  %red!50!yellow 表示50%的红色与50%的黄色混合色
        \color[rgb]{0,1,0}{This site includes} \\  % 80的蓝色与20%的红色混合色
        \color[rgb]{1,0,0}{Javascript, MYSQL, PHP, Python, Java,} \\ \color[rgb]{1,0,1}{Latex, Flutter, Redis, Nativescript, VueJs, Golang, big data,}\\ artificial intelligence and other basic programming tutorials
    
    \end{center}
\end{document}

输出:

Latex Colors

您也可以在一行中插入两种或多种颜色。这种类型的代码如下:

\documentclass[12pt]{article}
\usepackage[dvipsnames]{xcolor} % 声明颜色包
\begin{document}
    \title{This is my WebSite LearnFK} 
    \maketitle
    
    \begin{center}
    
        \color[rgb]{0,0,1}{Learnfk tutorials provide programmers with basic introductory tutorials.} \\  %red!50!yellow 表示50%的红色与50%的黄色混合色
        \color[rgb]{0,1,0}{This site includes} \\  % 80的蓝色与20%的红色混合色
        \color[rgb]{1,0,0}{Javascript, MYSQL, PHP, Python, Java,} \\ \color[rgb]{1,0,1}{Latex, Flutter, Redis, Nativescript, VueJs, Golang, big data,}\\ artificial intelligence and other basic programming tutorials
    
    \end{center}
\end{document}

输出:

Latex Colors

文字高亮

有用于突出显示文本的命令。您可以根据需要选择任何颜色来突出显示文本。您需要一个带有 xcolor 包的 soul 包,以实现突出显示的文本。

soul 软件包写为\usepackage {soul}

突出显示文本的命令写为\hl {任何文本} 。这里的" hl "命令用作突出显示标题。

下面是突出显示文本的简单代码:

\documentclass[12pt]{article}
\usepackage[dvipsnames]{xcolor} % 声明颜色包
\usepackage{soul} %引入soul 包
\begin{document}
    \title{This is my WebSite LearnFK} 
    \maketitle
    
    \begin{center}
    
      \textbf{\color{red}{Learnfk tutorials}}  provide programmers with basic introductory tutorials. This site includes \hl{Javascript, MYSQL, PHP, Python, Java, HTML5, Flutter, Redis, Nativescript, VueJs, Golang, big data}, artificial intelligence and other basic programming tutorials
    
    \end{center}
\end{document}

您可以在上面的示例中看到,我们使用了粗体命令,颜色和高亮命令。

输出如下图所示:

Latex Colors

要指定颜色突出显示,您需要使用\sethlcolor {颜色名称}命令。您也可以在一个程序中使用许多颜色突出显示。

颜色高亮显示的代码如下:

\documentclass[12pt]{article}
\usepackage[dvipsnames]{xcolor} % 声明颜色包
\usepackage{soul} %引入soul 包
\begin{document}
    \title{This is my WebSite LearnFK} 
    \maketitle
    
    \begin{center}
    
      \textbf{\color{red}{Learnfk tutorials}}  provide programmers with basic introductory tutorials. This site includes 
      \sethlcolor{pink}   %设置颜色 
      Javascript, \hl{MYSQL, PHP, Python, Java, HTML5, Flutter}, Redis, Nativescript, VueJs, Golang, big data, artificial intelligence and other 
      \sethlcolor{orange} %设置颜色
      \hl{basic  programming tutorials }
    
    \end{center}
\end{document}

输出:

Latex Colors

文字背景

您可以使用\fcolorbox {任何颜色} {任何背景的颜色} {text}命令来更改文本背景颜色以及该背景的框架/边界颜色。可以使用\colorbox {anycolor} {text}命令更改文本背景。

要更改文本背景,代码如下:

\documentclass[12pt]{article}
\usepackage[dvipsnames]{xcolor} % 声明颜色包
\usepackage{soul} %引入soul 包
\begin{document}
    \title{This is my WebSite LearnFK} 
    \maketitle
    
    \begin{center}
    
      \textbf{\color{red}{Learnfk tutorials}} \\ provide programmers with basic introductory tutorials. This site includes 
      \colorbox{pink}{  
      Javascript, MYSQL, PHP,}   Python, Java, HTML5, Flutter, Redis, Nativescript, VueJs, Golang, big data
      \colorbox{orange}{basic  programming tutorials }
    
    \end{center}
\end{document}

输出:

Latex Colors

要更改文本背景和框架,代码如下:

\documentclass[12pt]{article}
\usepackage[dvipsnames]{xcolor} % 声明颜色包
\usepackage{soul} %引入soul 包
\begin{document}
    \title{This is my WebSite LearnFK} 
    \maketitle
    
    \begin{center}
    
      \textbf{\color{red}{Learnfk tutorials}} \\ provide programmers with basic introductory tutorials. This site includes 
      \fcolorbox{red}{white}{    %red 是边框颜色,white是背景颜色
      Javascript, MYSQL, PHP,}   Python, Java, HTML5, Flutter, Redis, Nativescript, VueJs, Golang, big data
      \fcolorbox{orange}{cyan}{basic  programming tutorials }
    
    \end{center}
\end{document}

输出:

Latex Colors

页面背景色

您可以使用\pagecolor {color name}命令更改页面的背景颜色。下面是更改背景颜色的代码:

\documentclass[12pt]{article}
\usepackage[dvipsnames]{xcolor} % 声明颜色包
\usepackage{soul} %引入soul 包
\begin{document}
    \title{This is my WebSite LearnFK} 
    \maketitle
    
    \pagecolor{lightgray}  %设置背景颜色
    
    \begin{center}
    
      \textbf{\color{red}{Learnfk tutorials}} \\ provide programmers with basic introductory tutorials. This site includes 
      \fcolorbox{red}{white}{    %red 是边框颜色,white是背景颜色
      Javascript, MYSQL, PHP,}   Python, Java, HTML5, Flutter, Redis, Nativescript, VueJs, Golang, big data
      \fcolorbox{orange}{cyan}{basic  programming tutorials }
    
    \end{center}
\end{document}

在这里,我们选择了浅灰色(light gray)颜色。您可以根据需要更改颜色。

输出:

Latex Colors

现在让颜色为橙色(orange)。输出将是:

Latex Colors

如果选择粉红色(pink)颜色,则输出为:

Latex Colors

彩色线条

您可以在文档中的任何位置绘制彩色线条。线宽可以根据要求设置。代码如下:

\documentclass[12pt]{article}
\usepackage[dvipsnames]{xcolor} % 声明颜色包
\usepackage{soul} %引入soul 包
\begin{document}
    \title{This is my WebSite LearnFK} 
    \maketitle
    
    \colorlet{OneColor}{red!70!}  %设置颜色
    \colorlet{TwoColor}{cyan!40!orange!60!}

    
    \begin{center}
    
      {\color{OneColor} \rule{\linewidth}{1mm} }\\ %使用彩色线条
    
      \textbf{\color{red}{Learnfk tutorials}} \\ provide programmers with basic introductory tutorials. This site includes 
      \fcolorbox{red}{white}{    %red 是边框颜色,white是背景颜色
      Javascript, MYSQL, PHP,}   Python, Java, HTML5, Flutter, Redis, Nativescript, VueJs, Golang, big data
      \fcolorbox{orange}{cyan}{basic  programming tutorials } 
      
      {\color{TwoColor} \rule{\linewidth}{1mm} }  %使用彩色线条
    
    \end{center}
\end{document}

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

输出:

Latex Colors

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

Serverless入门课 -〔蒲松洋(秦粤)〕

Spark核心原理与实战 -〔王磊〕

物联网开发实战 -〔郭朝斌〕

体验设计案例课 -〔炒炒〕

Spring编程常见错误50例 -〔傅健〕

深入C语言和程序运行原理 -〔于航〕

自动化测试高手课 -〔柳胜〕

深入浅出可观测性 -〔翁一磊〕

手把手带你写一个MiniSpring -〔郭屹〕

好记忆不如烂笔头。留下您的足迹吧 :)