24

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).

lockstep
  • 250,273
  • 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

3 Answers3

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

Gonzalo Medina
  • 505,128
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.

Martin Scharrer
  • 262,582
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}
Peter Grill
  • 223,288