Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 11 down vote accepted

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}
share|improve this answer
    
+1 This sounds exactly like what I want. But I don't seem to have the package, despite having installed texlive-full. Do you know how to get the package (I'm using Ubuntu)? –  Oliver Oct 24 '11 at 18:12
    
Which package? Both preview and standalone are part of the normal distribution. I have added links to the answer as to where the packages are. –  Peter Grill Oct 24 '11 at 18:16
1  
@Werner: The TeXLive version of Ubuntu is from 2009 and doesn't include tlmgr. –  Martin Scharrer Oct 24 '11 at 18:21
2  
@Oliver: If you still have the (utterly outdated) TeXLive version which ships with Ubuntu then consider installing it manually: How to install “vanilla” TeXLive on Debian or Ubuntu?. Otherwise try a sudo tlmgr install preview standalone on the command line. –  Martin Scharrer Oct 24 '11 at 18:25
1  
@Oliver: Make sure you don't have empty lines at the begin or end of the document environment. They cause paragraphs. See Avoid paragraph due to trailing empty line in standalone file. –  Martin Scharrer Oct 24 '11 at 23:04

I agree with Peter Grill. You should use standalone for your pictures and other more complicated figures in the future. However, for an existing document using preview directly is easier. However, for complicated figures which are not simply contain a single *picture environment or \includegraphics I would redefine the figure environment instead to use preview directly while removing the \caption:

\documentclass{article}

\usepackage[demo]{graphicx}% remove 'demo' for real documents
\usepackage[active,tightpage]{preview}
\setlength{\PreviewBorder}{0pt}

\renewenvironment{figure}[1][]{%
    \begin{preview}%
        \renewcommand{\caption}[2][]{}%
}{%
    \end{preview}%
}

\begin{document}

text text text text text text 

\begin{figure}[t]
    \centering
    \includegraphics[width=\textwidth]{image}%
    \caption{Some caption}
\end{figure}

text text text text text text 

\begin{figure}[b]
    \centering
    \includegraphics[width=\textwidth]{image}%
    \caption[short]{Some caption}
\end{figure}

text text text text text text 

\end{document}

This will give you one PDF which has every figure as one tight page. You then might separate it using a PDF tool like pdftk with the burst argument.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.