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.

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

share|improve this question
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
    
Wow, so simple! Thank you! Make this an answer and I will accept it. –  PetPaulsen Nov 12 '11 at 17:28

3 Answers 3

up vote 10 down vote accepted

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

share|improve this answer

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.

share|improve this answer
    
Thanks for the crop option -- I was searching for it for a century. –  Dennis Jun 25 '12 at 19:42

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}
share|improve this answer
    
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

 
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.