Outils pour utilisateurs

Outils du site


issue184:latex

Ceci est une ancienne révision du document !


Above is the code Erik used in Part 3 of this series, using Latex to produce documents: The following are required to make a complete document with an image: \documentclass[letterpaper]{book} \usepackage{graphicx} These two packages are also useful: \usepackage{subcaption} % Builds customized captions for images, tables, etc. \usepackage{lipsum} %To add lipsum dummy text All three of these packages should be available in any standard installation of Latex. The begin{document} code has to be closed in order to compile without error. Putting all the pieces together yields the code shown top right. Some of this code should be self-explanatory. Other parts need some words to make their effects clear. The obvious ones are explained first.

Image files are imported size-as or to fit the text-width or line-width of the selected location. Height and width arguments in the includegraphics instruction should be obvious. Latex is not limited to metric measures. Text-width and line-width are usually the same value, the width between left and right margins. If there is more than one column of text, then line-width will equal the column width. Images used inside a column will not by default exceed the column margins. The centering instruction should also be obvious. Any element inside the figure environment will be centred between the left and right margins. The caption instruction gives text to the caption. Notice the caption is automatically given the name “Fig.”, and the next number in the sequence of figures. Fig is short for figure, the number (visible in the pdf output) will change if other figures come before this one. There is a label instruction in the code which is not required. Labels are very useful for providing cross references. They can be used to generate hot links in the pdf file, very useful for both author and reader. The instruction includegraphics[height=3cm,width=3cm]{atom} contains the name of the required graphic: atom.png. No file extension (file type) is required, Latex will import and show image files of types EPS, JPEG, PDF or PNG. If there are two or more files with the same name but different file types, the first file alphabetically is loaded in the document. The writer can indicate the correct file type in the includegraphics instruction: \includegraphics{sample-image.pdf}

Latex also assumes image files are stored in the same folder / directory as the tex document. It is possible to store graphics files in another directory. The location of the graphics file must be indicated in the includegraphics instruction. Either absolute or relative paths may be used. For example: \includegraphics{./sample-image.png} Image files may also be scaled, reduced or enlarged by a specific metric: \includegraphics[scale=.5]{sample-image.png} % scales both width and height by 0.5 Images can be rotated: \includegraphics[angle=10]{sample-image.png} % rotates the image by 10 degrees counterclockwise Location on the page is obviously important to the page design. The image environment floats images to the best location. If there is not room for the image on the selected page then it is moved to the next page, generating a new page if necessary. This action can be controlled through options in the beginfigure instruction. In it, you will see [h] which indicates the graphic image should be inserted “here”, at the location where the instruction is typed. Options are h=here, t=top of this page, b=bottom of this page, p=a separate page dedicated to floated elements, a different page in other words. If “t” or “b” are used, and the image is larger than the available space on the current page, the image will be moved to either the top or bottom of the next page. Repositioning the begin{figure} code using “h” as its first argument will move the image of the model of an atom within the document. (See images below left and below right.)

I leave it to you to experiment with the position of text in relation to the position of the code for the image. Note: using lipsum to generate imitation text does not allow for inserting the image between paragraphs. One way to control the position of an image is to resize it so it fits where you want it. Setting both height and width options to fixed values can distort images because it can change the aspect-ratio. Images can look squashed or stretched if both height and width are fixed values. (See image bottom left in which both height and width are fixed.) If only one of height and width is fixed, Latex will alter the other dimension automatically to maintain the aspect-ratio of the image. A similar way to resize an image is to use the [scale] instruction which alters both height and width by the same multiplier. This keeps the aspect ratio the same as the original. If [scale=1] the image is displayed in its original size, if [scale>1} then image is enlarged, and if [scale<1] then image is reduced. (See image bottom right in which [scale=1.3]. I hope this article has given you a few ideas about working with images in Tex / Latex. Next time, I will discuss setting up columns, a necessary skill for many online and printed publications.

issue184/latex.1661703515.txt.gz · Dernière modification : 2022/08/28 18:18 de d52fr