Vladar's Blog

LaTeX images

One of the most essential functionalities for TTRPG layout, besides tables, is the rendering of graphic files. In this post, I will cover the most common operations related to this topic.

Just like the tables, images can be included into floats through figure environment. Since it was already covered previously, this topic won't be covered here.

Contents


Include graphics

The graphicx package's1 \includegraphics command will be the main tool for you to load a graphic file into your document.

\includegraphics[options]{filename}

The options of the \includegraphics command can be classified into several categories:

📝 NOTE: a b c d values represent the following coordinates:

📝 NOTE: If units of length are not specified, bp (big point, 1/72 inch) unit is used.

There are a couple of other useful commands in this package:

Most of these options can be set globally, using \setkeys{Gin}{options} command. (Gin is a group of keyval keys for "Graphic inclusion".)

Examples

% Load image as-is
\includegraphics{image-test1.pdf}

latex-ig1

% Scale to 65%
\includegraphics[scale=0.65]{image-test1.pdf}

latex-ig2

% Scale to 65% and rotate 30 degrees counterclockwise
\includegraphics[scale=0.65,angle=30]{image-test1.pdf}

latex-ig3

% Cropped region from 2in:1in to 4in:3in
\includegraphics[viewport= 2in 1in 4in 3in, clip]{image-test1.pdf}

latex-ig4

% Trim 1in from the bottom and 3in from the right
\includegraphics[trim= 0in 1in 3in 0in, clip]{image-test1.pdf}

latex-ig5

Text over image

The graphicxbox package2 allows to add a background image \graphicxbox[includegraphics options]{graphic}{content} and add a colored frame around it \fgraphicxbox[model]{color}[includegraphics options]{graphic}{content}.

\graphicxbox[width=\linewidth]{image-test2.pdf}{%
    \parbox{\linewidth}{\lipsum[2]}
}

latex-gb1

You can keep the image's aspect ratio by using the minipage environment and specifying the image's height and width manually (both with the -2\fboxsep adjustment)

\graphicxbox[width=\linewidth]{image-test2.pdf}{%
    \begin{minipage}
    		[c]% vertical alignment
    		[\linewidth-2\fboxsep]% height
    		{\linewidth-2\fboxsep}% width
    	\lipsum[2]
    \end{minipage}

latex-gb2

Page color

The pagecolor package3 allows you to set a custom page background color with the \pagecolor[model]{color} command, or reset it with the \nopagecolor command.

Page background

Background package4

The background is configured through the \usepackage[options]{background} or \backgroundsetup{options} command, which options are:

\usepackage[pages=some,placement=top]{background}a

...

\backgroundsetup{%
    contents={\includegraphics{image-test1.pdf}},
    angle=30,
    opacity=0.5,
    scale=1,
    position=current page.north west,
    hshift=1in,
    vshift=-2in,
}

\BgThispage

latex-background

Eso-pic package6

This package allows you to add images to background and foreground of the pages of PDF documents, using \AddToShipoutPictureBG and \AddToShipoutPictureFG commands. Starred versions will do this for the current page only. \ClearShipoutPictureBG and \ClearShipoutPictureFG commands clear the corresponding stack.

There is a collection of helper macros to specify the exact position of the image:

For example, to display the image at the upper-left corner, you can do:

\AddToShipoutPictureBG*{%
    \AtPageUpperLeft{%
    	\raisebox{-\height}{%
    		\includegraphics{image-test1.pdf}
    	}
    }
}

latex-eso-pic

To stretch the image over the whole page, the following code could be used:

\AddToShipoutPictureBG*{%
    \AtPageLowerLeft{%
    	\includegraphics[width=\paperwidth, height=\paperheight]{image-test1.pdf}
    }
}

Wallpaper package7

This is an extension above the eso-pic package, providing useful macros for aligning, scaling, and tiling:

\This* versions of these commands will do the same but only for the current page

Two lengths \wpXoffset and \wpYoffset may be set to tweak the position of the wallpaper on the page.

So, to make the image to stretch over the whole page, like in the eso-pic example, you will do the following:

\ThisTileWallPaper{\paperwidth}{\paperheight}{image-test1.pdf}

Or, to tile the square image three times horizontally:

\ThisTileSquareWallPaper{3}{image-test2.pdf}

Reusing graphics

If you plan to include the same image multiple times, the graphicxsp package8 should be used instead of the graphicx package to keep the PDF document size minimal.

📝 NOTE: This package requires that the PDF be created by Adobe Distiller, version 5.0 or greater for graphics without transparency, version 5.0 with transparency.

First, load the image using the \embedEPS[options]{name}{path} command:

Alternatively, you can use the createImage environment to embed the Postscript code to draw the image.

Once the image is embedded, you can display it using the \includegraphics[name=myimagename, options]{path} command. If the name is specified, the path isn't used; otherwise, the command works as it does in the graphicx package. The second command to display the image, is \insertEPS[options]{name}.

📝 NOTE: Check the package's documentation for details on additional options, such as transparency parameters and Postscript commands insertion.


Discuss this post on Reddit


  1. https://ctan.org/pkg/graphicx

  2. https://www.ctan.org/pkg/graphicxbox

  3. https://ctan.org/pkg/pagecolor

  4. https://www.ctan.org/pkg/background

  5. https://ctan.org/pkg/pgf

  6. https://www.ctan.org/pkg/eso-pic

  7. https://www.ctan.org/pkg/wallpaper

  8. https://ctan.org/pkg/graphicxsp

#gamedev #guide #latex #software #ttrpg