我想在表格上画箭头,得到下面的图片
所以我写下了这段代码:
\begin{tabular}{*{6}{|c}|}
\hline
\tikzmark{A}{A} & \tikzmark{B}{B} & \tikzmark{C}{C} & \tikzmark{D}{D} & \tikzmark{E}{E} &
\tikzmark{F}{F}\\
\hline
\end{tabular}
\begin{tikzpicture}[remember picture,overlay]
\draw [->] (pic cs:A) -- (pic cs:F);
\end{tikzpicture}
但它给了我这个
而不是像这样(如我所料)
就像 tikzpicture 不能覆盖表格一样,即使我已经声明
\begin{tikzpicture}[remember picture,overlay]
我该如何解决这个问题?
答案1
使用\tikzmarknode
。 或者matrix
。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,tikzmark}
\begin{document}
\begin{tabular}{*{6}{|c}|}
\hline
\tikzmarknode{A}{A} & \tikzmarknode{B}{B} & \tikzmarknode{C}{C} & \tikzmarknode{D}{D} & \tikzmarknode{E}{E} &
\tikzmarknode{F}{F}\\
\hline
\end{tabular}%
\begin{tikzpicture}[remember picture,overlay]
\draw [-stealth] (A.west) -- (F);
\end{tikzpicture}%
\bigskip
\begin{tikzpicture}[>=stealth]
\matrix[matrix of nodes,cells={nodes={draw}},column sep=-\pgflinewidth]
(m){A & B & C & D & E & F\\};
\draw[->] (m-1-2.north) -- ++ (0,2ex) -| (m-1-4);
\draw[->] (m-1-2.south) -- ++ (0,-2ex) -| (m-1-1);
\draw[->] (m-1-2.south) -- ++ (0,-1ex) -| (m-1-3);
\end{tikzpicture}
\end{document}