Ceci est une ancienne révision du document !
This time I thought we would have some fun with colors and images. I am going to explore more of what is available in the graphicx package. Eric discussed some of the possibilities in his articles a few years ago. I will start by reviewing the code necessary to get an image into a Latex-generated PDF (top right).
It turns out the graphicx package allows authors to do things on a page for not only involving images. The graphicx package can be used to modify text and other features of page design when the author wants something other than ordinary black text on a white background. For example you might want a particular bit of text not to be black but have some colour or you might want some text to be set at an angle to rest of the text. Perhaps you want part of a page to be highlighted with some color. We will look at the code for rotating text first.
The command is \rotatebox[key val list]{angle}{text}. The key-value list can contain different elements: origin=label x=dimen y=dimen units=number. The effect of rotatebox command is to put the text into a box and then rotate the box. The centre of rotation can be the default or defined by the user. Instead of defining a specific location in the box as the centre or rotation with x and y, the user can use the origin=label key-value. The label can be any of lrtcbB: left, right, top, centre, bottom, baseline. (Combinations of l and r with t, c, b are allowed to indicate specific points on the perimeter of the box. Here are a few examples.
\rotatebox[origin=c]{180}{180 degrees on centre}
\rotatebox[origin=tr]{90}{90 degrees on top-right}
There is another instruction that puts text into a box which can then be manipulated. It is \scalebox and it has two parameters {h-scale} and {v-scale}. As with rotatebox the text being scaled is the last parameter in the instruction.
\scalebox{h-scale}[v-scale]{Text goes here}. The v-scale parameter is optional, if not specified it is set to the same value as h-scale. If both are specified and are not equal the text will be distorted since the proportions will not be maintained. Note the v-scale has to be inside square brackets (or missing) in order for the scalebox instruction to be effective
\scalebox{2}[1]{Distorted text}
Here is an interesting use of scalebox.
\scalebox{-1}[1]{Reflected text}
Sometimes it is necessary to have text fit into a certain line length or line height. Another form of the text box instruction can be used to do that. It is \resizebox with (as you would predict I am sure) three parameters, one for horizontal measure, one for vertical measure and the last for the text.
\resizebox*{h-length}{v-length}{text}
The scalebox instruction controls the size of the text and therefore the size of the invisible box the text is in. The resizebox instruction controls the size of the invisible box and therefore the size of the text the box contains. Sometimes a page designer know the size of text required, other times the designer knows the size of the space to be filled. The original text appears first and then the resizebox instruction is applied to stretch the text.
\resizebox{5cm}{\height}{Some text}
Both length parameters are required. However one measure can be replaced with an exclamation mark which instructs Latex to use the same scaling factor for the missing parameter as for the included parameter. If \height is in the second set of braces, the original height is maintained.
Now let us add some color to the text. (I was unable to get the color command to work on my system until I added xcolor to the package list. I suggest you do the same to avoid the frustration I experienced.) It is necessary to tell Latex which color model is to be used: rgb, cmyk, gray, named. The support for named colors is variable. Each different printer driver defines color names in a specific way. Your printer driver may not use the same names as mine. It may use the same names but define them differently. Of course you are free to experiment and discover what color names are supported and what the result is. It is also possible to define a custom colour (or set of colors).
\definecolor{custome name}{colour model}{colour specification}
If using the rgb model then the specification must consist of three numbers, each one between 0 and 1. If using the cmyk model then use four numbers, again each one between 0 and 1. (If using the gray color model, then only one number is used to indicate the amount of gray desired, again between 0 and 1.) Here are examples of text in color using rgb and cmyk. Notice the important difference between the textcolor instruction and the color instruction. Either one can use either the rgb model or the cmyk model.
\textcolor[rgb]{0.9,0,0.1}{Red text using the textcolor syntax} Outside the curly braces the text returns to black.
\color[rgb]{0.9,0,0.1}This is red text using the color syntax. Text is not in curly braces and remains red until color is changed.
\color[cmyk]{0,0,0,1}Used the cmyk model set to (0,0,0,1) to return the text to black.
It is also possible, and easy, to make the background behind some text a specific color. The same effect is usually possible in a word processor with the highlight tool or a background fill style.
\colorbox[cmyk]{0,.5,.5,0}{Text with colour in the background}
We can take advantage of the features of the fbox set of commands and do the following:
\fcolorbox[rgb]{0.9,0,.1}{0,.9,0}{A box with one colour for the border and another for the background.}
In case it is not clear from the image, the first parameter sets the color of the outline and the second sets the color of the background.
At the beginning of this article I gave the basic instructions for including a graphic: tell Latex what size you want the graphic and what its name is and the graphic will appear in the generated PDF. The includegraphics command has other parameters. One basic form of the command looks like:
\includegraphics[keyvals]{imagefile}
To use the flexibility of the command means you need to know what the various key-value pairs are. I used height and width already. Angle is used to rotate an image. Possible variables for the origin key-value used with angle are the same as for the rotatebox command used for text above. Images can use the scale key value to control size without specifying a specific number and unit. I demonstrate these few key values in this article. There are a number of other possibilities. I suggest you read the documentation for the graphicx package and experiment.
Note: Latex reads and responds to the parameters from left to right . Rearranging the order of parameters may give a different result. Look at the results of the last two commands for an example.
\includegraphics[scale=0.25]{135}
\includegraphics[angle=35, scale=0.25]{135}
\includegraphics*[height=4cm, width=2.5cm, angle=45]{135}
\includegraphics*[height=4cm, angle=45, width=2.5cm]{135}
Again I encourage you to read through the documentation for the graphicx package, it only sixteen pages long. Some parts may seem overly complex if you are new to Latex. Generally you can skip sections that are not applicable to your needs. Put the documentation in a safe place, you may need it in the future.
Next time I will introduce another of the over two thousand default packages that are available with a standard installation of Latex. If you have any questions or need assistance with a specific task in Latex do not hesitate to send me a note.