TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to compile a pseudocode for an algorithm into a separate pdf and then include it into my main document as a figure. However, the compiled pseudocode gets compiled into a pdf with margins and I have not been able to crop it (other than manually) to fit into a tighter box. I used pdfcrop to try to get rid of the white space, but it only removes white space at the top, left, and right, but not the bottom. I would like to be able to compile it so that it has no margins and not to have to do it manually every time I change a comma in the pseudocode.
Here is an example:

    \caption{Precomputing densities}
      \FOR{$i = 1 \to n$}
        \STATE $\mathrm{sums}[i][i] \gets 0$

Any advice?

share|improve this question
Does this post help? – cmhughes Nov 3 '11 at 15:45
Tried using preview: produces an "Undefined control sequence." on the line with \begin{algorithm}. – lynxoid Nov 3 '11 at 15:49
Your trimming via pdfcrop probably includes the page number. Use \pagestyle{empty} for such stand-alone instances. – Werner Nov 3 '11 at 15:53
That's it - removing the page number allows pdfcrop to crop it properly! Thanks a lot! – lynxoid Nov 3 '11 at 15:57
My hunch was to instead use the document class standalone but when I try it I get "LaTeX Error: Not in outer par mode." – N.N. Nov 3 '11 at 16:00
up vote 13 down vote accepted

Have you tried this with


just below \begin{document}? This may get rid of something in the footer that pdfcrop is having trouble with.

share|improve this answer
It worked - removed the page number and pdfcrop cropped it alright. Thanks! – lynxoid Nov 3 '11 at 15:57
That was my first ever post! You're very welcome. Glad I could help. – qubyte Nov 3 '11 at 16:03

Your Answer


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.