Just another option is preview
. With it you can also generate cropped figures but with a great advantage: you can have several figures on the same .tex
file. The result will be a pdf file with a cropped figure per page. Then you can select which figure include in your document with 'page=' option of graphicx
package.
One example:
\documentclass{article}
\usepackage[active,pdftex,tightpage]{preview}
\usepackage{tikz}
\PreviewEnvironment{tikzpicture}
\begin{document}
\begin{tikzpicture}
\draw (0,0) rectangle (2,3);
\end{tikzpicture}
\begin{tikzpicture}
\draw (0,0) rectangle (3,2);
\end{tikzpicture}
\end{document}
Process this file and will obtain a pdf with two pages, then select which figure to include in your main document:
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}\centering
\includegraphics[page=1]{Preview}%<-- Replace 'Preview' with your figures file's name
\caption{First rectangle}
\end{figure}
\begin{figure}\centering
\includegraphics[page=2]{Preview}%<-- Replace 'Preview' with your figures file's name
\caption{Second rectangle}
\end{figure}
\end{document}
Update:
With verson 1.x of standalone
class you don't need to use preview
package because my previous description is standalone
class default behaviour with option tikz
. So, with this simpler code:
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw (0,0) rectangle (2,3);
\end{tikzpicture}
\begin{tikzpicture}
\draw (0,0) rectangle (3,2);
\end{tikzpicture}
\end{document}
you will also get a pdf file with two pages with one cropped figure in each page.