[Tex/LaTex] Crop entire document around figure

pdfcroptables

Have you ever submitted a LaTeX paper to a journal that wants separate figures? When you want to include a figure composed of a table of images, you must build it separately.

When I run latexpdf, I get an entire 8.5 x 11 page, even when I remove the page number.

Is there a way to "autocrop" my built pdf as I compile it from LaTeX? I suppose I could open it in inkscape and crop and save it, but I'd really like to learn how to do this the right way.

Best Answer

I have been using the standalone package exactly for this purpose. You create a standalone tex file for each figure and use:

\documentclass[preview=true]{standalone}

and the main files which include this standalone file will need to have the complete preamble including \usepackage{standalone}. Martin Scharrer, the package author provides a good example here.


Alternatively you could use the preview package. Add \usepackage[active, graphics]{preview}, and use the \PreviewEnvironment to specify which environments you want to be extracted.

Here is an example that extracts the two tikzpicture environments on separate pages:

\documentclass{article}
\usepackage{tikz}
\usepackage{lipsum}

\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{1pt}%

\begin{document}
\lipsum[1]
\begin{tikzpicture}
    \draw [red, ultra thick] (0,0) rectangle (1,1);
\end{tikzpicture}
\lipsum[2]
\begin{tikzpicture}
    \draw [blue,fill=yellow] (0,0) circle (5pt);
\end{tikzpicture}
\end{document}
Related Question