楼主: oliyiyi
1114 0

Using colors in a LaTeX document [推广有奖]

版主

已卖:2994份资源

泰斗

1%

还不是VIP/贵宾

-

TA的文库  其他...

计量文库

威望
7
论坛币
84105 个
通用积分
31671.0967
学术水平
1454 点
热心指数
1573 点
信用等级
1364 点
经验
384134 点
帖子
9629
精华
66
在线时间
5508 小时
注册时间
2007-5-21
最后登录
2025-7-8

初级学术勋章 初级热心勋章 初级信用勋章 中级信用勋章 中级学术勋章 中级热心勋章 高级热心勋章 高级学术勋章 高级信用勋章 特级热心勋章 特级学术勋章 特级信用勋章

楼主
oliyiyi 发表于 2015-5-21 08:48:14 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

Guest post by Qutub Sajib

While preparing a document in LaTeX, you may want to use colors for different purposes. Those purposes might be to color text or highlight text by changing its background color. You may even want to do both, highlight colored text. In this tutorial, we’re going to discuss how to color and highlight text, and how to define our own colors.


Coloring text

To color text in a document, you first need to add the color or xcolor package to the preamble of your LaTeX file. Since the xcolor package has more powerful features than the color package, in this tutorial we will be using xcolor. To do that, we add the following line to the preamble:

  1. \usepackage{xcolor}
复制代码

Now we are ready to use colors in our text either through \textcolor or through\color. These two commands work as follows:



The colorname in the command stands for any “base color” as described in thedocumentation of xcolor package. Here is an example that shows how the color redcan be used in a document:



Among the nineteen base colors listed, some frequently used colors include green,blue, violet, or purple.

It’s possible to mix multiple colors to a new color. For example, the custom colored text here is a result of 55% green mixed with 45% blue as illustrated in the example:


With xcolor’s different package options, a large number of predefined colors can be used. The option dvipsnames loads 68 cmyk colors, the option svgnames loads 151 rgb colors, and the option x11names loads 317 rgb colors. For example, the color RedViolet is available with the dvipsnames option:




Highlighting text

To highlight text, in addition to loading color or xcolor, we also need to load the soulpackage:

[size=1em]

[size=1em]1



[size=1em][size=1em]\usepackage{soul}



Now, text can be highlighted by simply using the command \hl{text}.


By default, text is highlighted by changing the background color to yellow. It is possible to change the highlighting color to your desired color. The soul package provides the \sethlcolor{colorname} command to change the highlighting color. For example, we can change the color to green using:




Highlighting and coloring text

Text can be colored and highlighted by combining the previously discussed commands.


Note that the \hl command goes inside the \color or \textcolor command to work as expected.


Custom colors

Although the range of colors available in xcolor is huge, we might want to define our own custom color. Provided that xcolor package is loaded, new colors can be defined using the \definecolor command. Before defining a new color, let’s see how the color red is defined:


Obviously, red is the name of the color to be defined, rgb is the color model, and1,0,0 are three corresponding values for red, green, and blue. In other words, for redwe use 100% red, 0% green and 0% blue. With this, we can now define a new colorOliveGreen through the rgb color model:



There are numerous online color mixing tools which are useful to get the numbers right. Here is such a tool: color mixer.


Similarly, we can define colors through the cmyk color model. We can define OliveGreen by setting corresponding values for cyan, magenta, yellow, and black.





二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Document DOCUME LaTeX Using Late document

缺少币币的网友请访问有奖回帖集合
https://bbs.pinggu.org/thread-3990750-1-1.html

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-29 07:38