10

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}
mariosangiorgio
  • 677
  • 2
  • 6
  • 9

2 Answers2

14

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.

David Carlisle
  • 757,742
Martin Scharrer
  • 262,582
  • @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 07:07
5

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} 

enter image description here

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.

David Carlisle
  • 757,742
Ignasi
  • 136,588