在表格上绘制括号而不记住覆盖

在表格上绘制括号而不记住覆盖

我发现这篇很棒的文章输入 l 在表格中添加弯曲箭头和括号,但是我想要的是将表格放入同一个tizkpicture环境中并删除记忆过度,这需要两次编译才能生效。

除了表格之外的任何其他解决方案也受到欢迎。

我从这里的帖子中复制了完整的代码:

\documentclass[border=20pt,png]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,calc}

\newcommand{\tikzmark}[2][-3pt]{\tikz[remember picture, overlay, baseline=-0.5ex]\node[#1](#2){};}

\tikzset{brace/.style={decorate, decoration={brace}},
 brace mirrored/.style={decorate, decoration={brace,mirror}},
}

\newcounter{brace}
\setcounter{brace}{0}
\newcommand{\drawbrace}[3][brace]{%
 \refstepcounter{brace}
 \tikz[remember picture, overlay]\draw[#1] (#2.center)--(#3.center)node[pos=0.5, name=brace-\thebrace]{};
}

\newcounter{arrow}
\setcounter{arrow}{0}
\newcommand{\drawcurvedarrow}[3][]{%
 \refstepcounter{arrow}
 \tikz[remember picture, overlay]\draw (#2.center)edge[#1]node[coordinate,pos=0.5, name=arrow-\thearrow]{}(#3.center);
}

% #1 options, #2 position, #3 text 
\newcommand{\annote}[3][]{%
 \tikz[remember picture, overlay]\node[#1] at (#2) {#3};
}

\begin{document}

 \begin{tabular}{ | l | l |}
  \hline
   letter & number \\ \hline
   \tikzmark[xshift=-8pt,yshift=1ex]{x}A &  1\tikzmark[xshift=3.5em]{a} \\ \hline
   A &  2 \\ \hline
   \tikzmark[xshift=-8pt,yshift=-1ex]{y}A &  1\tikzmark[xshift=3.5em]{b} \\ \hline
   \tikzmark[xshift=-8pt,yshift=1ex]{w}B &  1 \\ \hline
   \tikzmark[xshift=-8pt,yshift=-1ex]{z}B &  2 \\ \hline
 \end{tabular}
\drawcurvedarrow[bend left=60,-stealth]{a}{b}
\drawbrace[brace mirrored, thick]{x}{y}
\drawbrace[brace mirrored, thick]{w}{z}
\annote[right]{arrow-1}{Duplicate}
\annote[left]{brace-1}{A}
\annote[left]{brace-2}{B}
\end{document}

输出: 在此处输入图片描述

答案1

如果您使用matrix of nodes而不是tabular,单元格将成为您可以正常引用的命名节点。例如,

在此处输入图片描述

\documentclass[border=20pt,png]{standalone}
% ateb: https://tex.stackexchange.com/a/715067/
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,matrix,arrows.meta}
\tikzset{%
  brace/.style={decorate, decoration={brace}},
  brace mirrored/.style={decorate, decoration={brace,mirror}},
}

\begin{document}
\begin{tikzpicture}
  \matrix (m) [matrix of nodes,nodes={text width=12.5mm,text height=1.5ex,anchor=base west}]
  {
    letter & number \\
    A   &   1  \\
    A   &   2  \\
    A   &   1  \\
    B   &   1  \\
    B   &   2  \\
  };
  \foreach \i/\j/\k in {2/4/A,5/6/B}
  \draw [brace mirrored,thick] (m.west |- m-\i-1.north) -- node [midway,left] {\k} (m.west |- m-\j-1.south);
  \draw (m-1-1.north west) -| (m-6-2.south east) -| cycle
  (m-1-1.north east) -- (m-6-1.south east)
  foreach \i in {2,3,...,6} { (m-\i-1.north west) -- (m-\i-2.north east) }
  ;
  \draw [-Latex] (m-2-2.east -| m.east) [bend left] to node [midway,right] {Duplicate} (m-4-2.east -| m.east) ;
\end{tikzpicture}
\end{document}

相关内容