# TikZ Picture in Table

Can somebody help me with the table? I want to have distance between the outline of a TikZ picture and the table-line. Furthermore, the non-TikZ pictures aren't centered.

Here is my LaTeX code:

\documentclass[a4paper,10pt]{article}
\usepackage{tikz,amsmath, amssymb,bm,color}
\usetikzlibrary{circuits.logic.US,circuits.logic.IEC}
\begin{document}

\begin{table}
\caption{Test}
\label{de:Wahrheitstabelle_Bsp01}
\setlength{\tabcolsep}{5mm} % separator between columns
\def\arraystretch{1.25} % vertical stretch factor
\centering

\begin{tabular}{|c|c|c|}
\hline

Gatter    &   Funktion    &   CNF-Formel        \\ \hline

\begin{tikzpicture}
\draw (-1.5,-0.75) rectangle (1.5,0.75) ;
\end{tikzpicture}   &    0   & 1    \\ \hline

\begin{tikzpicture}[circuit logic US,  logic gate input sep=4mm]
\node [or gate, inputs =nn] (a1) {};
\draw (a1.input 1) -- ++(left:5mm) node[left] {$x_{1}$};
\draw (a1.input 2) -- ++(left:5mm) node[left] {$x_{2}$};
\draw (a1.output)--++(right:5mm) node[right] {$x_{3}$};

\end{tikzpicture}   &    0   & 1        \\ \hline

\begin{tikzpicture}[circuit logic US]
\node (a1) [not gate, inputs =n] at (0,0)  {};
\draw (a1.input) -- ++(left:5mm) node[left] {$x_{1}$};
\draw (a1.output)--++(right:5mm) node[right] {$x_{2}$};

\end{tikzpicture}   & $x_{2} \equiv \neg x_{1}$  & $(x_{2} \vee x_{1}) \wedge (\neg x_{2} \vee \neg x_{1})$    \\ \hline
\end{tabular}
\end{table}

\end{document}


Here is my table:

## migrated from stackoverflow.comJan 1 '14 at 22:18

This question came from our site for professional and enthusiast programmers.

• Please make your code compilable so that it is easier for people to help you. I tried to patch your code up by adding a document class and some necessary packages, but I don't know which package provides \Cref and tikz does not know what to do with the pgfkey 'circuit logic US' so I'm unable to reproduce the problem. – cfr Jan 2 '14 at 0:32
• oh, im sorry. I've edited my post... thank you for your help – bunebu Jan 2 '14 at 1:38

To fix the vertical margin around a tikzpicture, you can use the fit library and the special node current boundind box. In the following example, the \addvmargin macro uses this method.

To fix the vertical alignment of a tikzpicture, you can use the baseline option. Here, I choose 0 as base line for the first tikzpicture, but you can choose any vertical coordinate. In the two last tikzpictures, I choose an arbitrary node as reference.

\documentclass[a4paper,10pt]{article}
\usepackage{tikz,amsmath, amssymb,bm,color}
\usetikzlibrary{circuits.logic.US,circuits.logic.IEC,fit}
\node[fit=(current bounding box),inner ysep=#1,inner xsep=0]{};
}
\begin{document}
\begin{table}
\caption{Test}
\label{de:Wahrheitstabelle_Bsp01}
\setlength{\tabcolsep}{5mm} % separator between columns
\def\arraystretch{1.25} % vertical stretch factor
\centering
\begin{tabular}{|c|c|c|}
\hline
Gatter    &   Funktion    &   CNF-Formel
\\ \hline
\begin{tikzpicture}[baseline=0]
\draw (-1.5,-0.75) rectangle (1.5,0.75) ;
\end{tikzpicture}   &    0   & 1
\\ \hline
\begin{tikzpicture}[baseline={(x3.base)},circuit logic US,logic gate input sep=4mm]
\node [or gate, inputs =nn] (a1) {};
\draw (a1.input 1) -- ++(left:5mm) node[left] {$x_{1}$};
\draw (a1.input 2) -- ++(left:5mm) node[left] {$x_{2}$};
\draw (a1.output)--++(right:5mm) node[right] (x3) {$x_{3}$};
\draw (a1.input) -- ++(left:5mm) node[left] (x1) {$x_{1}$};
\draw (a1.output)--++(right:5mm) node[right] {$x_{2}$};
\end{tikzpicture}   & $x_{2} \equiv \neg x_{1}$  & $(x_{2} \vee x_{1}) \wedge (\neg x_{2} \vee \neg x_{1})$