21

Recently I found the standalone package. I am using it to create figures and such in external files. But everytime content is created the width of the page seems to be fixed, it does not shrink to the minimal width.

Here my example *.tex file:

\documentclass{standalone}
\usepackage{tikz}

\begin{document}

Test

\end{document}

And the produced content (the actual document is the white stuff with the Text 'Test' on it): enter image description here

I am using pdflatex (MiKTeX 2.9).

  • 2
    This works: \documentclass{standalone} \usepackage{tikz} \begin{document} Test \end{document} I just deleted the blank line between "Test" and \end{document}. – Gonzalo Medina Nov 12 '11 at 17:26
15

Deleting (or commenting out) any blank lines between the material and \end{document} solves the problem:

\documentclass{standalone}

\begin{document}
%
Test
%
\end{document}

enter image description here

15

Update 2011/12/21

The new standalone v1.0 provides a fix for this issue. Now the new crop option (based on TeX boxes and page resizing) will be used by default and ignore paragraph break. Also have a look at the new varwidth option which allows for paragraphs with variable widths. An example can be seen in standalone figure and tabular.


Previous versions of standalone class used the preview package to generate a tight page. That package sets the size of the page to the size of the content box plus some border.

In your code you have a trailing empty line which causes an implicit \par, i.e. a paragraph, turning the whole thing into paragraph box with the given \linewidth. I, as the standalone author, tried to find a way to fix this, e.g. using my question Avoid paragraph due to trailing empty line in standalone file, but so far I didn't put anything into the class.

As a workaround simply do not have trailing empty lines. Leading lines might be OK, but it is better to avoid them too. Future versions of standalone will handle this better. Maybe I will provide multiple ways to clip the whitespace off or an option to use varwidth internally.

  • Thanks for the crop option -- I was searching for it for a century. – Dennis Jun 25 '12 at 19:42
3

Sometimes you need to do more than just remove the blank lines, and a way to do that is to use the varwidth package. Here is the output with out and with varwidth:

enter image description here enter image description here

\documentclass{standalone}
\usepackage{varwidth}
\begin{document}
\begin{varwidth}{\linewidth}
\section{Section Title}
\end{varwidth}
\end{document}
  • Actually I recently had the idea to add the varwidth environment to standalone by default to avoid the very thing. – Martin Scharrer Nov 13 '11 at 8:56
  • @MartinScharrer: Excellent. Automatically invoking varwidth when the tightpage option is used might be one way. – Peter Grill Nov 13 '11 at 18:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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