![在表格上绘制括号而不记住覆盖](https://linux22.com/image/475443/%E5%9C%A8%E8%A1%A8%E6%A0%BC%E4%B8%8A%E7%BB%98%E5%88%B6%E6%8B%AC%E5%8F%B7%E8%80%8C%E4%B8%8D%E8%AE%B0%E4%BD%8F%E8%A6%86%E7%9B%96.png)
我发现这篇很棒的文章输入 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}