The most useful commands for applying colours made available by xcolor are:
- \color{color} (applies color to the text in the currrent group)
- \textcolor{color}{text} (applies color to the specified text only)
- \pagecolor{color} (colors the entire page to be color)
- \colorbox{color}{text} (creates a box containing the specified text, with color as the background)
- \fcolorbox{frame color}{bg color}{text} (same as above, but with a coloured border around the box)
The xcolor package has quite a collection of pre-defined colours; they are listed in Section 4 Colors by Name in the manual. Apart from the 19 "base" colours that are always available, you can also access more pre-defined colours via the dvipsnames, svgnames and x11names options. Here's a quick example:
\documentclass[a6paper,12pt]{article}
\usepackage[x11names]{xcolor}
\begin{document}
% 'LemonChiffon1' from x11names
\pagecolor{LemonChiffon1}
% 'magenta' is a base colour
\textcolor{magenta}{Hello World!}
% 'CadeBlue1', 'Firebrick2' and 'Goldenrod1'
% are available via x11names
What a \colorbox{CadetBlue1}{wonderful}
\fcolorbox{Firebrick2}{Goldenrod1}{world}.
\end{document}
\usepackage[x11names]{xcolor}
\begin{document}
% 'LemonChiffon1' from x11names
\pagecolor{LemonChiffon1}
% 'magenta' is a base colour
\textcolor{magenta}{Hello World!}
% 'CadeBlue1', 'Firebrick2' and 'Goldenrod1'
% are available via x11names
What a \colorbox{CadetBlue1}{wonderful}
\fcolorbox{Firebrick2}{Goldenrod1}{world}.
\end{document}
You can mix up your own colours, too. \color{LemonChiffon1!80} means 80% LemonChiffon1 and 20% white, while \color{lime!30!yellow!60!Mahogany} would be 30% lime, 60% yellow, and 10% Mahogany. You can also give names to the colours you concoct, so that you can reuse them at various points in your document. For example:
- \definecolor[named]{CoolBlack}{cmyk}{.3,0,0,1} defines the CMYK 'Cool Black' (useful if your printer asks for CMYK black instead of 'rich black')
- \definecolor[named]{AquaBlue2}{rgb}{.553,.769,.98} defines 'AquaBlue2' with decimal RGB values (range [0,1])
- \definecolor[named]{Hazelnut}{HTML}{BDA59B} defines 'Hazelnut' with HTML RGB values. Useful if you're re-using colour definitions from CSS styesheets.
Have fun and happy LaTeXing!
No comments:
Post a Comment