我有一个tabular
环境,旨在作为教科书的练习。我希望它看起来像这样:
学生需要连接剩余的线来完成练习。
问题:如何在表格环境中画一条线将一个条目连接到另一个条目?
我愿意接受能够实现相同目标的替代方案:指示学生应该将左侧的单元格与右侧的相应答案连接起来。
这是我用于该表的代码:
\documentclass{memoir}
\begin{document}
\begin{center}
\begin{tabular}{lcl}
letter & & number \\
\hline
a & \qquad\qquad\qquad & 3 \\
b & \qquad\qquad\qquad & 4 \\
c & \qquad\qquad\qquad & 2 \\
d & \qquad\qquad\qquad & 1 \\
e & \qquad\qquad\qquad & 5 \\
\hline
\end{tabular}
\end{center}
\end{document}
我正在使用 XeLaTeX 进行编译(因为我有中文字体)。
过去我曾使用 Tikz baseline/overlay 来完成类似的工作,但已经有一段时间了,我无法让它工作:
\documentclass{memoir}
\usepackage{tikz}
\tikzset{mynode/.style={draw=none,fill=none,rectangle,anchor=base}}
\begin{document}
\begin{center}
\begin{tabular}{lcl}
letter & & number \\
\hline
a & \tikz[baseline]{\node[mynode] (A) {};} \qquad\qquad\qquad \tikz[baseline]{\node[mynode] (3) {};} & 3 \\
b & \tikz[baseline]{\node[mynode] (B) {};} \qquad\qquad\qquad \tikz[baseline]{\node[mynode] (4) {};} & 4 \\
c & \tikz[baseline]{\node[mynode] (C) {};} \qquad\qquad\qquad \tikz[baseline]{\node[mynode] (2) {};} & 2 \\
d & \tikz[baseline]{\node[mynode] (D) {};} \qquad\qquad\qquad \tikz[baseline]{\node[mynode] (1) {};} & 1 \\
e & \tikz[baseline]{\node[mynode] (E) {};} \qquad\qquad\qquad \tikz[baseline]{\node[mynode] (5) {};} & 5 \\
\hline
\tikz[overlay] \path[line width=1pt,-stealth,out=0,in=-90] (A) edge (1);
\end{tabular}
\end{center}
\end{document}
这给了我一个箭头,但它没有连接节点:
答案1
您忘记了remember picture
选项。
\documentclass{memoir}
\usepackage{tikz}
\tikzset{mynode/.style={draw=none,fill=none,rectangle,anchor=base}}
\begin{document}
\begin{center}
\begin{tabular}{lcl}
letter & & number \\
\hline
\tikz[remember picture,baseline]{\node[mynode] (A) {a};} & \qquad\qquad\qquad & \tikz[remember picture,baseline]{\node[mynode] (3) {3};}\\
\tikz[remember picture,baseline]{\node[mynode] (B) {b};} & \qquad\qquad\qquad & \tikz[remember picture,baseline]{\node[mynode] (4) {4};}\\
\tikz[remember picture,baseline]{\node[mynode] (C) {c};} & \qquad\qquad\qquad & \tikz[remember picture,baseline]{\node[mynode] (2) {2};}\\
\tikz[remember picture,baseline]{\node[mynode] (D) {d};} & \qquad\qquad\qquad & \tikz[remember picture,baseline]{\node[mynode] (1) {1};}\\
\tikz[remember picture,baseline]{\node[mynode] (E) {e};} & \qquad\qquad\qquad & \tikz[remember picture,baseline]{\node[mynode] (5) {5};}\\
\hline
\tikz[remember picture,overlay] \draw[line width=1pt,-stealth,out=0,in=-180] (A) to (1);
\end{tabular}
\end{center}
\end{document}