Pictures and Floats

Including pictures in every common format, and placing figures and tables.

Including a picture

\begin{figure}[htbp]
  \centering
  \includegraphics[width=0.8\linewidth]{plot}
  \caption{Error against mesh width.}
  \label{fig:plot}
\end{figure}

\includegraphics

\includegraphics[options]{name} sets a picture where it stands. It is part of mLaTeX, so graphicx and graphics are accepted and need nothing loaded.

OptionWhat it does
widthScales the picture to a width, such as 0.8\linewidth.
heightScales the picture to a height.
scaleScales the picture by a factor, such as 0.5.
angleTurns the picture by that many degrees.
keepaspectratioWith both width and height, fits inside them without stretching.

Where pictures are found

A picture named without an extension is looked for as .png, .jpg, .jpeg, .webp, .pdf, .eps, .ps and .svg, in this order:

  1. Pictures a program handed in from memory, when mLaTeX is embedded.
  2. The document's folder, and the folders given with -I.
  3. The folders \graphicspath lists, as in \graphicspath{{figures/}{plots/}}.
  4. The network, for a name that is an http:// or https:// address.

Pictures from the web

\includegraphics{https://example.com/chart.png} fetches the picture when the document is set. Run with --offline to refuse every network request instead; see Security.

Placeholders

mwe's example-image, example-image-a and their kin are drawn as framed boxes of the right size with their names in them, so a layout can be checked before its pictures exist.


Formats

FormatHow it is used
PNGDecoded and compressed into the PDF
JPEGEmbedded exactly as it came, never decoded or recompressed
WebPDecoded and compressed into the PDF
PDFThe page itself, fonts and vectors intact; page=, trim=, viewport= and clip are read
EPSIts PostScript is run and drawn as vectors
SVGIts shapes, paths, transforms, styles and text are drawn as vectors; \includesvg{name} works too
.tikz, .pgfRead as the TikZ picture they contain

Size

A picture's natural size follows the resolution in its file, or 72 dpi when it gives none, as in pdfTeX.

Pictures that cannot be drawn

A picture in a form mLaTeX cannot draw keeps its place as an empty frame of the right size, with a warning.

Text inside an EPS or SVG picture is set in the nearest of PDF's standard fonts rather than the font the file embeds, and an SVG gradient is drawn in its first colour.


Floats

Figures and tables float to where LaTeX's own algorithm puts them, within the placement you allow.

Placement

The letters in brackets after \begin{figure} say where the float may go:

OptionMeaning
hHere, where it is written, if it fits
tAt the top of a page
bAt the bottom of a page
pOn a page of floats
!Ignore the limits on how much of a page floats may take
HExactly here; needs the float package

Limits and order

\topfraction, \bottomfraction, \textfraction, \floatpagefraction, topnumber and the rest are respected, and figures and tables each keep their order.

Two columns

figure* and table* span both columns of a two-column page.

Setting floats that wait

\clearpage, or placeins' \FloatBarrier, sets every float still waiting before going on.

Floats from other packages

wrapfig's wrapfigure, rotating's sidewaysfigure and sidecap's SCfigure are accepted and set as floats of mLaTeX's own.


Captions

\caption and \label

\caption{text} numbers a float and sets its caption; \label after it names it for \ref. \caption[short]{long} gives the list of figures a shorter entry.

The caption package

The caption package's font, labelfont and labelsep options are read:

\usepackage[font=small, labelfont=bf, labelsep=period]{caption}

Captions outside a float

\captionof{figure}{...} captions something outside a float, as if it were a figure.


Figures made of parts

subcaption

A subfigure block inside a figure is one part of it, with its own caption:

\usepackage{subcaption}

\begin{figure}[htbp]
  \begin{subfigure}{0.48\linewidth}
    \includegraphics[width=\linewidth]{coarse}
    \caption{Coarse mesh}
  \end{subfigure}
  \hfill
  \begin{subfigure}{0.48\linewidth}
    \includegraphics[width=\linewidth]{fine}
    \caption{Fine mesh}
  \end{subfigure}
  \caption{Two meshes.}
\end{figure}

Each part is lettered, and a reference to one prints as 1a.

subfig

subfig's \subfloat[caption]{picture} works the same way.


Floats of your own

newfloat and float

newfloat's \DeclareFloatingEnvironment and float's \newfloat make a new kind of float with its own counter and caption name:

\usepackage{newfloat}
\DeclareFloatingEnvironment[name=Scheme]{scheme}

algorithm

algorithm is one already, for pseudocode.