Outils pour utilisateurs

Outils du site


issue203:latex

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.

Cette fois-ci, j'ai pensé que nous allions nous amuser avec les couleurs et les images. Je vais explorer davantage les possibilités offertes par le logiciel graphicx. Eric a évoqué certaines des possibilités dans ses articles d'il y a quelques années. Je commencerai par passer en revue le code nécessaire pour intégrer une image dans un PDF généré par LaTeX (en haut à droite).

Il s'avère que le package graphicx permet aux auteurs de faire des choses sur une page qui n'impliquent pas seulement des images. Le paquet graphicx peut être utilisé pour modifier le texte et d'autres caractéristiques de conception de la page lorsque l'auteur souhaite autre chose qu'un texte noir ordinaire sur un fond blanc. Par exemple, vous pouvez souhaiter qu'une partie du texte ne soit pas noire, mais qu'elle soit colorée, ou qu'une partie du texte soit inclinée par rapport au reste du texte. Vous souhaitez peut-être qu'une partie de la page soit mise en évidence par une couleur. Nous examinerons d'abord le code permettant de faire pivoter le texte.

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}

La commande est la suivante : \rotatebox[key val list]{angle}{texte}. La liste clé-valeur peut contenir différents éléments : origin=label x=dimen y=dimen units=number. La commande rotatebox a pour effet de placer le texte dans une boîte, puis de faire pivoter cette dernière. Le centre de rotation peut être défini par défaut ou par l'utilisateur. Au lieu de définir un emplacement spécifique dans la boîte comme centre de rotation avec x et y, l'utilisateur peut utiliser la valeur-clé origin=label. L'étiquette peut être lrtcbB : left, right, top, centre, bottom, baseline (gauche, droite, haut, centre, bas, ligne de base). (Les combinaisons de l et r avec t, c, b sont autorisées pour indiquer des points spécifiques sur le périmètre de la boîte. Voici quelques exemples :

\rotatebox[origin=c]{180}{180 degrés autour du centre}

\rotatebox[origin=tr]{90}{90 degrés depuis le haut à droite}

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}

Il existe une autre instruction qui place le texte dans une boîte qui peut ensuite être manipulée. Il s'agit de \scalebox et elle a deux paramètres {h-scale} et {v-scale}. Comme pour rotatebox, le texte mis à l'échelle est le dernier paramètre de l'instruction.

\scalebox{h-scale}[v-scale]{Le texte va ici}. Le paramètre v-scale est facultatif ; s'il n'est pas spécifié, il prend la même valeur que h-scale. Si les deux sont spécifiés et ne sont pas égaux, le texte sera déformé car les proportions ne seront pas respectées. Notez que le paramètre v-scale doit être entre crochets (ou absent) pour que l'instruction scalebox soit efficace :

\scalebox{2}[1]{texte déformé}

Voici une utilisation intéressante de l'instruction scalebox :

\scalebox{-1}[1]{texte reflété}

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}

Il est parfois nécessaire de faire tenir le texte dans une certaine longueur ou hauteur de ligne. Une autre forme d'instruction de zone de texte peut être utilisée à cet effet. Il s'agit de \resizebox avec (comme vous le prévoyez, j'en suis sûr) trois paramètres, un pour la mesure horizontale, un pour la mesure verticale et le dernier pour le texte.

\resizebox*{h-length}{v-length}{texte}

L'instruction scalebox contrôle la taille du texte et donc la taille de la boîte invisible dans laquelle il se trouve. L'instruction resizebox contrôle la taille de la boîte invisible et donc la taille du texte qu'elle contient. Parfois, le concepteur de la page connaît la taille du texte nécessaire, parfois il connaît la taille de l'espace à remplir. Le texte original apparaît en premier, puis l'instruction resizebox est appliquée pour étirer le texte.

\resizebox{5cm}{\height}{un certain texte}

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}

Les deux paramètres de longueur sont nécessaires. Cependant, une mesure peut être remplacée par un point d'exclamation qui indique à LaTeX d'utiliser le même facteur d'échelle pour le paramètre manquant que pour le paramètre inclus. Si \height se trouve dans la deuxième série d'accolades, la hauteur d'origine est conservée.

Ajoutons maintenant de la couleur au texte. (Je n'ai pas réussi à faire fonctionner la commande color sur mon système avant d'ajouter xcolor à la liste des paquets. Je vous suggère de faire de même pour éviter la frustration que j'ai connue). Il est nécessaire d'indiquer à LaTeX le modèle de couleur à utiliser : rgb, cmyk, gray, named. La prise en charge des couleurs nommées est variable. Chaque pilote d'imprimante définit les noms de couleurs d'une manière spécifique. Il se peut que votre pilote d'imprimante n'utilise pas les mêmes noms que le mien. Il peut utiliser les mêmes noms, mais les définir différemment. Bien entendu, vous êtes libre d'expérimenter et de découvrir quels noms de couleurs sont pris en charge et quel est le résultat. Il est également possible de définir une couleur (ou un ensemble de couleurs) personnalisée.

\definecolor{custome name}{colour model}{spécification de la couleur}

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.

Si l'on utilise le modèle rgb, la spécification doit comporter trois nombres, chacun compris entre 0 et 1. Si l'on utilise le modèle cmyk, il faut utiliser quatre nombres, chacun compris entre 0 et 1. (Si l'on utilise le modèle des couleurs grises, un seul nombre, également compris entre 0 et 1, est utilisé pour indiquer la quantité de gris souhaitée.) Voici des exemples de texte en couleur utilisant les modèles rgb et cmyk. Remarquez la différence importante entre l'instruction textcolor et l'instruction color. L'une et l'autre peuvent utiliser le modèle rgb ou le modèle cmyk.

\textcolor[rgb]{0.9,0,0.1}{Texte en rouge utilisant la syntaxe textcolor} En dehors des accolades, le texte redevient noir.

\color[rgb]{0.9,0,0.1} Il s'agit d'un texte rouge utilisant la syntaxe de color. Le texte n'est pas entre accolades et reste rouge jusqu'à ce que la couleur soit modifiée.

\color[cmyk]{0,0,0,1} Utilise le modèle cmyk défini sur (0,0,0,1) pour ramener le texte au noir.

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}

Il est également possible, et facile, de donner une couleur spécifique à l'arrière-plan d'un texte. Le même effet est généralement possible dans un traitement de texte avec l'outil de mise en évidence ou un style de remplissage de l'arrière-plan.

\colorbox[cmyk]{0,.5,.5,0}{Texte avec la couleur de l'arrière-plan}

Nous pouvons tirer parti des fonctionnalités du jeu de commandes fbox et procéder comme suit :

\fcolorbox[rgb]{0,9,0,.1}{0,.9,0}{Une boîte avec une couleur pour la bordure et une autre pour l'arrière-plan}.

Si l'image ne le montre pas clairement, le premier paramètre définit la couleur du contour et le second, la couleur de l'arrière-plan.

Au début de cet article, j'ai donné les instructions de base pour inclure une image : indiquez à LaTeX la taille de l'image et son nom, et l'image apparaîtra dans le PDF généré. La commande includegraphics possède d'autres paramètres. Une forme de base de la commande se présente comme suit :

\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}

Pour utiliser la flexibilité de la commande, vous devez savoir ce que sont les différentes paires clé-valeur. J'ai déjà utilisé la hauteur et la largeur. Angle est utilisé pour faire pivoter une image. Les variables possibles pour la clé-valeur origin utilisée avec angle sont les mêmes que pour la commande rotatebox utilisée pour le texte ci-dessus. Les images peuvent utiliser la clé-valeur d'échelle pour contrôler la taille sans spécifier un nombre et une unité spécifiques. Je présente ces quelques clés-valeurs dans cet article. Il existe un certain nombre d'autres possibilités. Je vous suggère de lire la documentation du paquet graphicx et de l'essayer.

Remarque : LaTeX lit les paramètres et y répond de gauche à droite. Un réarrangement de l'ordre des paramètres peut donner un résultat différent. Regardez les résultats des deux dernières commandes pour un exemple.

\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.

Encore une fois, je vous encourage à lire la documentation du paquet graphicx, qui ne fait que seize pages. Certaines parties peuvent sembler trop complexes si vous ne connaissez pas LaTeX. En général, vous pouvez sauter les sections qui ne s'appliquent pas à vos besoins. Conservez la documentation dans un endroit sûr, vous pourriez en avoir besoin à l'avenir.

La prochaine fois, je présenterai un autre des plus de deux mille paquets par défaut qui sont disponibles avec une installation standard de LaTeX. Si vous avez des questions ou si vous avez besoin d'aide pour une tâche spécifique dans LaTeX, n'hésitez pas à m'envoyer un message.

issue203/latex.txt · Dernière modification : 2024/04/10 18:07 de andre_domenech