[Tex/LaTex] standalone figure and tabular

standalone

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}

Best Answer

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}

Original answer:

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.

Related Question