表格中的 TikZ 图片

表格中的 TikZ 图片

有人能帮我做表格吗?我希望 TikZ 图片的轮廓和表格线之间有距离。此外,非 TikZ 图片不居中。

这是我的 LaTeX 代码:

\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}

这是我的表格:

在此处输入图片描述

答案1

要修复 tikzpicture 周围的垂直边距,可以使用fit库和特殊节点current boundind box。在下面的示例中,\addvmargin宏使用此方法。

要修复 tikzpicture 的垂直对齐,您可以使用baseline选项。在这里,我选择0作为第一个 tikzpicture 的基线,但您可以选择任何垂直坐标。在最后两个 tikzpicture 中,我选择任意节点作为参考。

在此处输入图片描述

\documentclass[a4paper,10pt]{article}
\usepackage{tikz,amsmath, amssymb,bm,color}
\usetikzlibrary{circuits.logic.US,circuits.logic.IEC,fit}
\newcommand\addvmargin[1]{
  \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) ;
    \addvmargin{1mm}
  \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}$};
    \addvmargin{1mm}
  \end{tikzpicture}   &    0   & 1
  \\ \hline
  \begin{tikzpicture}[baseline={(x1.base)},circuit logic US]
    \node (a1) [not gate, inputs =n] at (0,0)  {};
    \draw (a1.input) -- ++(left:5mm) node[left] (x1) {$x_{1}$};
    \draw (a1.output)--++(right:5mm) node[right] {$x_{2}$};
    \addvmargin{1mm}
  \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}

相关内容