[Tex/LaTex] make the page as big as the picture

diagramspaper-size

This is the reciprocal to How can I create a pdf document exactly as big as my tikz picture?. My understanding of all the answers there is that they extract a picture from a TeX document and strip away all the unnecessary space around the edges. My situation is that the picture I'm drawing is bigger than the usual page and I want to resize the page to be big enough to fit it.

More specifically, I'm drawing a picture using TikZ (though that's not important, I guess) and the document consists only of that picture. As I draw more and more, it gets bigger and bigger (current size is about 80cm square). I use the geometry package to keep enlarging the paper size, but it would be nice if TeX could handle that automatically.

(It is possible that one of the answers to How can I create a pdf document exactly as big as my tikz picture? can do this, but it wasn't obvious from reading them.)

Best Answer

Your approach seems the right one for me. Just set the paper size to \maxdimen and let preview or standalone scale it down:

\documentclass{standalone}
\usepackage[paperwidth=\maxdimen,paperheight=\maxdimen]{geometry}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
 \draw (0,0) rectangle (100cm,100cm);
 \draw (0,0) -- (100cm,100cm);
\end{tikzpicture}
\end{document}

Make sure it is really just the tikzpicture no empty lines around it. This isn't required when using preview directly:

\documentclass{article}
\usepackage[paperwidth=\maxdimen,paperheight=\maxdimen]{geometry}
\usepackage{tikz}
\usepackage[tightpage,active]{preview}
\PreviewEnvironment{tikzpicture}
\begin{document}
\begin{tikzpicture}
 \draw (0,0) rectangle (100cm,100cm);
 \draw (0,0) -- (100cm,100cm);
\end{tikzpicture}
\end{document}
Related Question