# standalone figure and tabular

I'd like to generate a standalone pdf containing a pgf/tikz image and a tabular.

I'm almost getting the desired result but there is a paragraph between the image and the tabular that breaks my layout (I guess it is due to the fact that the empty paragraph takes the full textwidth).

What I do to get such result is the following:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgf}

\begin{document}
\begin{tikzpicture}
...
\end{tikzpicture}
%This empty line creates the undesired paragraph
\begin{tabular}
...
\end{tabular}
\end{document}

-
You could just crop the resulting standalone pdf... –  Seamus Sep 29 '11 at 9:08
Yes, the paragraph causes the full text width. I tried to build something into standalone to avoid this and asked the following question for that: Avoid paragraph due to trailing empty line in standalone file. Unfortunately, this can't be fixed by standalone itself. –  Martin Scharrer Sep 29 '11 at 19:44
@Seamus I'd like to avoid that. It was the reason I decided to use the standalone package –  mariosangiorgio Sep 30 '11 at 8:48
@MartinScharrer I'll have a look at the linked discussion. Thanks –  mariosangiorgio Sep 30 '11 at 8:48
@mariosangiorgio: Please note my updated answer. The new version of standalone makes things much easier. –  Martin Scharrer Dec 21 '11 at 15:46

### Update 2011/12/21

I now release standalone v1.0 which comes with a varwidth option to allow for vertical content with variable width. It uses the varwidth environment (and package) internally which is based on minipage. Using this option you can use a paragraph break (i.e. an empty line) to stack both things. If you want more vertical space try a \vspace{..} between them.

\documentclass[varwidth]{standalone}[2011/12/21]
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\draw (0,0) rectangle (2,3);
\end{tikzpicture}%

\begin{tabular}{cc}
a & b \\\hline
b & c \\
d & e \\
\end{tabular}%
\end{document}


You need to stack the two elements manually without using a line break or new paragraph. You can use a TikZ picture like Ignasi suggested, wrap both into a tabular or use \shortstack{...\\...}. It is also possible to stack it using plainTeX commands: \vbox{\hbox{..}\hbox{..}}.

Examples:

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
\vbox{\hbox{%
\begin{tikzpicture}
\draw (0,0) rectangle (2,3);
\end{tikzpicture}%
}\hbox{%
\begin{tabular}{cc}
a & b \\\hline
b & c \\
d & e \\
\end{tabular}%
}}%
\end{document}


and

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
\shortstack{%
\begin{tikzpicture}
\draw (0,0) rectangle (2,3);
\end{tikzpicture}%
\\%
\begin{tabular}{cc}
a & b \\\hline
b & c \\
d & e \\
\end{tabular}%
}%
\end{document}


With the optional argument of \shortstack you can select the horizontal alignment of the blocks.

I reused the example code from Ignasi to allow for easy comparison.

-
@MartinScharrer: I didn't know how to automatically adjust output width. Now, I know three ways of doing it. Thanks. –  Ignasi Sep 30 '11 at 7:07

If it's possible you can include your tabular inside the tikzpicture.

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}

\begin{tikzpicture}
\node (figure) at (0,0) {\tikz \draw (0,0) rectangle (2,3);};
\node (tabular) [below = of figure] {\begin{tabular}{cc}
a & b \\\hline
b & c \\
d & e \\
\end{tabular}};
\end{tikzpicture}
\end{document}


I've tested standalone and preview but although cropped height is correct, cropped width is textwidth. If you know final width, you can use a minipage to fix it.

-