使用 Tikz 在 Latex 中绘制 KV 图。如何绘制两个不同的表格?

使用 Tikz 在 Latex 中绘制 KV 图。如何绘制两个不同的表格?

我无法弄清楚如何绘制两个 KV-Diagramms,所有的包都没有我想要的外观,所以我创建了自己的 KV-Diagramm,但我无法绘制其中多个。

这是我的代码:

\begin{table}[!htb]
    \begin{minipage}{.5\linewidth}
      \centering
      \begin{tabular}[t]{|c|c|c|c|c|c|}
        \multicolumn{1}{c}{} & \multicolumn{1}{c}{A} & \multicolumn{1}{c}{A} & \multicolumn{1}{c}{$\mathrm{\overline{A}}$}& \multicolumn{1}{c}{$\mathrm{\overline{A}}$} \\
        \hhline{~|----}
        \multicolumn{1}{c|}{B}                          &\tikzmark{c3} 0 &\tikzmark{c7} 0 &\tikzmark{c6} 0 &\tikzmark{c2} 1 & \multicolumn{1}{c}{D} \\  
        \hhline{~|----}
        \multicolumn{1}{c|}{B}                          &\tikzmark{c11} 1 &\tikzmark{c15} 1 &\tikzmark{c14} 0 &\tikzmark{c10} 1 & \multicolumn{1}{c}{$\mathrm{\overline{D}}$} \\  
        \hhline{~|----}
        \multicolumn{1}{c|}{$\mathrm{\overline{B}}$}    &\tikzmark{c9} 1 &\tikzmark{c13} 0 &\tikzmark{c12} 0 &\tikzmark{c8} 1 &  \multicolumn{1}{c}{$\mathrm{\overline{D}}$} \\  
        \hhline{~|----}
        \multicolumn{1}{c|}{$\mathrm{\overline{B}}$}    &\tikzmark{c1} 1 &\tikzmark{c5} 1 &\tikzmark{c4} 0 &\tikzmark{c0} 1 & \multicolumn{1}{c}{D}  \\ 
        \hhline{~|----}
        \multicolumn{1}{c}{} & \multicolumn{1}{c}{C} & \multicolumn{1}{c}{$\mathrm{\overline{C}}$} & \multicolumn{1}{c}{$\mathrm{\overline{C}}$} & \multicolumn{1}{c}{C}
        \begin{tikzpicture}[overlay, remember picture]
            \draw[blue,rounded corners=5pt] ([xshift=-4pt,yshift=.7em]pic cs:c11) rectangle ([,xshift=13pt, yshift=-.1em]pic cs:c15);
        
            \draw[yellow,rounded corners=5pt] ([xshift=-4pt,yshift=.7em]pic cs:c1) rectangle ([,xshift=13pt, yshift=-.1em]pic cs:c5);
        
            \draw[red,rounded corners=5pt] ([xshift=-0.5em,yshift=9pt]pic cs:c11)   -| ++(1.75em,-1.25em); 
            \draw[red,rounded corners=5pt] ([xshift=-0.5em,yshift=-3pt]pic cs:c9)   -| ++(1.75em,1.25em);
            \draw[red,rounded corners=5pt] ([xshift=1.35em,yshift=9pt]pic cs:c10)    -| ++(-1.75em,-1.25em); 
            \draw[red,rounded corners=5pt] ([xshift=1.35em,yshift=-3pt]pic cs:c8)    -| ++(-1.75em,1.25em);
        
            \draw[green,rounded corners=5pt] ([xshift=-0.5em,yshift=9pt]pic cs:c9)   -| ++(1.75em,-1.25em); 
            \draw[green,rounded corners=5pt] ([xshift=-0.5em,yshift=-3pt]pic cs:c1)   -| ++(1.75em,1.25em);
            \draw[green,rounded corners=5pt] ([xshift=1.35em,yshift=9pt]pic cs:c8)    -| ++(-1.75em,-1.25em); 
            \draw[green,rounded corners=5pt] ([xshift=1.35em,yshift=-3pt]pic cs:c0)    -| ++(-1.75em,1.25em);
        \end{tikzpicture}
    \end{tabular}
    \caption{$S_a$}
    \end{minipage}%
    \begin{minipage}{.5\linewidth}
      \centering
        \begin{tabular}[t]{|c|c|c|c|c|c|}
            \multicolumn{1}{c}{} & \multicolumn{1}{c}{A} & \multicolumn{1}{c}{A} & \multicolumn{1}{c}{$\mathrm{\overline{A}}$}& \multicolumn{1}{c}{$\mathrm{\overline{A}}$} \\
            \hhline{~|----}
            \multicolumn{1}{c|}{B}                          &\tikzmark{c3} 0 &\tikzmark{c7} 0 &\tikzmark{c6} 0 &\tikzmark{c2} 1 & \multicolumn{1}{c}{D} \\  
            \hhline{~|----}
            \multicolumn{1}{c|}{B}                          &\tikzmark{c11} 1 &\tikzmark{c15} 1 &\tikzmark{c14} 0 &\tikzmark{c10} 1 & \multicolumn{1}{c}{$\mathrm{\overline{D}}$} \\  
            \hhline{~|----}
            \multicolumn{1}{c|}{$\mathrm{\overline{B}}$}    &\tikzmark{c9} 1 &\tikzmark{c13} 0 &\tikzmark{c12} 0 &\tikzmark{c8} 1 &  \multicolumn{1}{c}{$\mathrm{\overline{D}}$} \\  
            \hhline{~|----}
            \multicolumn{1}{c|}{$\mathrm{\overline{B}}$}    &\tikzmark{c1} 1 &\tikzmark{c5} 1 &\tikzmark{c4} 0 &\tikzmark{c0} 1 & \multicolumn{1}{c}{D}  \\ 
            \hhline{~|----}
            \multicolumn{1}{c}{} & \multicolumn{1}{c}{C} & \multicolumn{1}{c}{$\mathrm{\overline{C}}$} & \multicolumn{1}{c}{$\mathrm{\overline{C}}$} & \multicolumn{1}{c}{C}
            \begin{tikzpicture}[overlay, remember picture]
                \draw[blue,rounded corners=5pt] ([xshift=-4pt,yshift=.7em]pic cs:c11) rectangle ([,xshift=13pt, yshift=-.1em]pic cs:c15);
            
                \draw[yellow,rounded corners=5pt] ([xshift=-4pt,yshift=.7em]pic cs:c1) rectangle ([,xshift=13pt, yshift=-.1em]pic cs:c5);
            
                \draw[red,rounded corners=5pt] ([xshift=-0.5em,yshift=9pt]pic cs:c11)   -| ++(1.75em,-1.25em); 
                \draw[red,rounded corners=5pt] ([xshift=-0.5em,yshift=-3pt]pic cs:c9)   -| ++(1.75em,1.25em);
                \draw[red,rounded corners=5pt] ([xshift=1.35em,yshift=9pt]pic cs:c10)    -| ++(-1.75em,-1.25em); 
                \draw[red,rounded corners=5pt] ([xshift=1.35em,yshift=-3pt]pic cs:c8)    -| ++(-1.75em,1.25em);
            
                \draw[green,rounded corners=5pt] ([xshift=-0.5em,yshift=9pt]pic cs:c9)   -| ++(1.75em,-1.25em); 
                \draw[green,rounded corners=5pt] ([xshift=-0.5em,yshift=-3pt]pic cs:c1)   -| ++(1.75em,1.25em);
                \draw[green,rounded corners=5pt] ([xshift=1.35em,yshift=9pt]pic cs:c8)    -| ++(-1.75em,-1.25em); 
                \draw[green,rounded corners=5pt] ([xshift=1.35em,yshift=-3pt]pic cs:c0)    -| ++(-1.75em,1.25em);
            \end{tikzpicture}
        \end{tabular}
        \caption{$S_b$}
    \end{minipage} 
\end{table}

结果

我只想让两个表都带有标记。我认为这与记住图片以及 \tikzmark 的工作方式有关,但我无法解决它。

感谢您的帮助。

答案1

如果您更喜欢Tikz这些表格的解决方案,则可以使用 轻松构建它们matrix

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{matrix}

\begin{document}
\begin{tikzpicture}
\matrix(A)[matrix of math nodes, 
    nodes={draw, anchor=center, minimum width=8mm, minimum height=6mm},
    column sep=-\pgflinewidth, row sep=-\pgflinewidth,   
    row 1/.style={nodes={draw=none, anchor=base}},
    row 6/.style={nodes={draw=none, anchor=base}},
    column 1/.style={nodes={draw=none}},
    column 6/.style={nodes={draw=none}},]
    { & A       & A        & \overline{A} & \overline{A} \\
    B &|(c3)| 0 &|(c7)| 0 & |(c6)| 0     & |(c2)| 1     & D\\
    B &|(c11)| 1 &|(c15)| 1 &|(c14)| 0 &|(c10)| 1 & \overline{D}\\
    \overline{B} &|(c9)| 1 &|(c13)| 0 &|(c12)| 0 &|(c8)| 1 & \overline{D}\\
    \overline{B} &|(c1)| 1 &|(c5)| 1 &|(c4)| 0 &|(c0)| 1 & D\\
    & C & \overline{C}& \overline{C} & C\\};
    \draw[red, rounded corners] ([yshift=-1mm]c11.north west)-|([xshift=-1mm]c11.south east)|-([yshift=1mm]c9.south west);
    \draw[red, rounded corners] ([yshift=-1mm]c10.north east)-|([xshift=1mm]c10.south west)|-([yshift=1mm]c8.south east);
    
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容