Anda di halaman 1dari 11

Not logged in Discussion for this IP address Contributions Create account Log in

Book Discussion Read Edit View history Search Wikibooks

LaTeX/Colors
< LaTeX

Adding colors to your text is supported by the xcolor package (supersedes package color). Using this
Main Page
LaTeX
Help package, you can set the font color, text background, or page background. You can choose from
Browse predefined colors or define your own colors using RGB, Hex, or CMYK. Mathematical formulas can also Getting Started
Cookbook be colored. 1. Introduction
Wikijunior 2. Installation
Featured books Contents 3. Installing Extra
Recent changes 1 Adding the xcolor package Packages
Donations
2 Entering colored text 4. Basics
Random book
3 Entering colored background for the text 5. How to get help
Using Wikibooks
4 Predefined colors
Common Elements
Community 4.1 The 68 standard colors known to dvips
1. Document
Reading room 5 Defining new colors
Structure
Community portal 5.1 Place
2. Text Formatting
Bulletin Board 5.2 Method
3. Paragraph
Help out! 5.3 Color Models
Policies and guidelines Formatting
5.4 Examples
Contact us 4. Colors
5.5 Using color specifications directly
5. Fonts
5.6 Creating / Capturing colors
Tools 6. List Structures
5.7 Spot colors
What links here 7. Special Characters
6 Sources
Related changes 8. Internationalization
Upload file 9. Rotations
Special pages
Permanent link Adding the xcolor package [edit] 10. Tables
11. Title creation
Page information To make use of these features, the xcolor package must be imported. 12. Page Layout
Cite this page
13. Customizing Page
In other languages Headers and
Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf
Српски / srpski Footers​
Add links 14. Importing Graphics
\usepackage{xcolor}
Sister projects 15. Floats, Figures and
Captions
Wikipedia
Wikiversity
16. Footnotes and
Wiktionary Margin Notes
Wikiquote 17. Hyperlinks
The package has some options to get more predefined colors, which should be added globally. usenames
Wikisource 18. Labels and Cross-
allows you to use names of the default colors, the same 16 base colors as used in HTML. The dvipsnames
Wikinews referencing
Wikivoyage
allows you access to more colors, another 64, and svgnames allows access to about 150 colors. The
Mechanics
Commons initialization of "table" allows colors to be added to tables by placing the color command just before the
Wikidata table. 1. Errors and
Warnings
Print/export If you need more colors, then you may also want to look at the x11names option. This offers more than 300
2. Lengths
Create a collection
colors. 3. Counters
Download as PDF 4. Boxes
Printable version Entering colored text [edit] 5. Rules and Struts

The simplest way to type colored text is by: Technical Texts

1. Mathematics
2. Advanced
Mathematics
\textcolor{declared-color}{text}
3. Theorems
4. Chemical Graphics
5. Algorithms
where declared-color is a color that was defined before by \definecolor . 6. Source Code
Listings
Another possible way by
7. Linguistics
Special Pages

1. Indexing
{\color{declared-color}some text}
2. Glossary
3. Bibliography
Management
that will switch the standard text color to the color you want. It will work until the end of the current TeX 4. More
group. For example: Bibliographies

Special Documents
Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf
1. Scientific Reports
(Bachelor Report,
Master Thesis,
Dissertation)
2. Letters
3. Presentations
4. Teacher's Corner
5. Curriculum Vitae
Creating Graphics

1. Introducing
Procedural
Graphics
2. MetaPost
3. Picture
4. PGF/TikZ
5. PSTricks
6. Xy-pic
7. Creating 3D
graphics

Programming
1. Macros
2. Plain TeX
3. Creating Packages
4. Creating Package
Documentation
5. Themes
Miscellaneous

1. Modular
Documents
2. Collaborative
Writing of LaTeX
Documents
3. Export To Other
Formats
Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf
Help and
Recommendations
1. FAQ
2. Tips and Tricks
Appendices
1. Authors
2. Links
3. Package
Reference
4. Sample LaTeX
documents
5. Index
6. Command
Glossary

edit this box • edit the


TOC

\emph{some black text,


\color{red}followed by a red fragment},
going black again.

The difference between \textcolor and \color is the same as that between \texttt and \ttfamily , you can use the
one you prefer. The \color environment allows the text to run over multiple lines and other text environments whereas the text in
\textcolor must all be one paragraph and not contain other environments.

You can change the background color of the whole page by:

\pagecolor{declared-color}

Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf


Entering colored background for the text [edit]

\colorbox{declared-color}{text}

If the background color and the text color is changed, then:

\colorbox{declared-color1}{\color{declared-color2}text}

There is also \fcolorbox to make framed background color in yet another color:

\fcolorbox{declared-color-frame}{declared-color-background}{text}

Predefined colors [edit]

The predefined color names are

black, blue, brown, cyan, darkgray, gray, green, lightgray, lime, magenta, olive, orange, pink,
purple, red, teal, violet, white, yellow.

There may be other pre-defined colors on your system, but these should be available on all systems.

If you would like a color not pre-defined, you can use one of the 68 dvips colors, or define your own. These options are discussed in
the following sections

The 68 standard colors known to dvips [edit]

Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf


Invoke the package with the usenames and dvipsnames option. If you are using tikz or pstricks package you must declare the xcolor
package before that, otherwise it will not work.

\usepackage[dvipsnames]{xcolor}

This above syntax may result in an error if you are using beamer with tikz. To go around it, include usenames and dvipsnames options
when defining the document class.

\documentclass[usenames,dvipsnames]{beamer}

Name Color Color Name


Apricot Aquamarine
Bittersweet Black
Blue BlueGreen
BlueViolet BrickRed
Brown BurntOrange
CadetBlue CarnationPink
Cerulean CornflowerBlue
Cyan Dandelion
DarkOrchid Emerald
ForestGreen Fuchsia
Goldenrod Gray
Green GreenYellow
JungleGreen Lavender

Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf


LimeGreen Magenta

Mahogany Maroon
Melon MidnightBlue
Mulberry NavyBlue
OliveGreen Orange
OrangeRed Orchid
Peach Periwinkle
PineGreen Plum
ProcessBlue Purple
RawSienna Red
RedOrange RedViolet
Rhodamine RoyalBlue
RoyalPurple RubineRed
Salmon SeaGreen
Sepia SkyBlue
SpringGreen Tan
TealBlue Thistle
Turquoise Violet
VioletRed White
WildStrawberry Yellow
YellowGreen YellowOrange

Defining new colors [edit]

If the predefined colors are not adequate, you may wish to define your own.

Place [edit]

Define the colors in the preamble of your document. (Reason: do so in the preamble, so that you can already refer to them in the
Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf
preamble, which is useful, for instance, in an argument of another package that supports colors as arguments, such as the listings
package.)

Method [edit]

You need to include the xcolor package in your preamble to define new colors. In the abstract, the colors are defined following this
scheme:

\definecolor{name}{model}{color-spec}

where:

name is the name of the color; you can call it as you like
model is the way you describe the color, and is one of gray, rgb, RGB, HTML, and cmyk.
color-spec is the description of the color

Color Models [edit]

Among the models you can use to describe the color are the following (several more are described in the xcolor manual ):

Color Models
Model Description Color Specification Example
Just one number between 0 (black)
Shades of gray
gray and 1 (white), so 0.95 will be very light \definecolor{light-gray}{gray}{0.95}
(0-1)
gray, 0.30 will be dark gray.
Three numbers given in the form
Red, Green,
red,green,blue; the quantity of each
rgb Blue \definecolor{orange}{rgb}{1,0.5,0}
color is represented with a number
(0-1)
between 0 and 1.

Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf


Three numbers given in the form
Red, Green, red,green,blue; the quantity of each
RGB Blue color is represented with a number \definecolor{orange}{RGB}{255,127,0}
(0-255) between 0 and 255.

Red, Green, Six hexadecimal numbers given in the


HTML Blue form RRGGBB; similar to what is used \definecolor{orange}{HTML}{FF7F00}
(00-FF) in HTML.
Four numbers given in the form
Cyan, Magenta,
cyan,magenta,yellow,black; the
cmyk Yellow, Black \definecolor{orange}{cmyk}{0,0.5,1,0}
quantity of each color is represented
(0-1)
with a number between 0 and 1.

Examples [edit]

To define a new color, follow the following example, which defines orange for you, by setting the red to the maximum, the green to one
half (0.5), and the blue to the minimum:

\definecolor{orange}{rgb}{1,0.5,0}

The following code should give a similar results to the last code chunk.

\definecolor{orange}{RGB}{255,127,0}

If you loaded the xcolor package, you can define colors upon previously defined ones.

The first specifies 20 percent blue and 80 percent white; the second is a mixture of 20 percent blue and 80 percent black; and the last
one is a mixture of (20*0.3) percent blue, ((100-20)*0.3) percent black and (100-30) percent green.

Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf


\color{blue!20}
\color{blue!20!black}
\color{blue!20!black!30!green}

xcolor also feature a handy command to define colors from color mixes:

\colorlet{notgreen}{blue!50!yellow}

Using color specifications directly [edit]

Normally one would predeclare all the colors as above, but sometimes it is convenient to directly use a color without naming it first. To
achieve this, \color and \textcolor have an alternative syntax specifying the model in square brackets, and the color
specification in curly braces. For example:

{\color[rgb]{1,0,0} This text will appear red-colored}


\textcolor[rgb]{0,1,0}{This text will appear green-
colored}

Creating / Capturing colors [edit]

You may want to use colors that appear on another document, web pages, pictures, etc. Alternatively, you may want to play around
with rgb values to create your own custom colors.

Image processing suites like the free GIMP suite for Linux/Windows/Mac offer color picker facilities to capture any color on your
screen or synthesize colors directly from their respective rgb / hsv / hexadecimal values.

Smaller, free utilities also exist:


Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf
Linux/BSD: The gcolor2 tool (usually also available in repositories)
Microsoft Windows: The open-source Color Selector tool.
Apple Macs: Hex Color Picker for creating custom colors and the built-in DigitalColor Meter for capturing colors on screen.
Online utilities: See here for a Wikipedia article with several external links

Spot colors [edit]

Spot colors are customary in printing. They usually refer to pre-mixed inks based on a swatchbook (like Pantone, TruMatch or Toyo).
The package colorspace extends xcolor to provide real spot colors (CMYK and CIELAB). They are defined with, say:

\definespotcolor{mygreen}{PANTONE 7716 C}{.83, 0, .40,


.11}

Sources [edit]

The xcolor manual


The color package documentation

Previous: Paragraph Formatting Index Next: Fonts

Category: Book:LaTeX

This page was last edited on 7 February 2018, at 17:19.

Text is available under the Creative Commons Attribution-ShareAlike License.; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy
Policy.

Privacy policy About Wikibooks Disclaimers Developers Cookie statement Mobile view

Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

Anda mungkin juga menyukai