有什么方法可以在表格的某些单元格之间画箭头吗?

有什么方法可以在表格的某些单元格之间画箭头吗?

我想知道是否有任何方法可以像下图一样在表格中放置箭头?在此处输入图片描述

我使用的 LaTeX 代码如下:

\setlength{\arrayrulewidth}{0.3mm}
\setlength{\tabcolsep}{18pt}
\renewcommand{\arraystretch}{1.3}
\begin{longtable}{|c|c|c|c|c|}
    \hline
    \textbf{$p$}    &    $=$    &   \textbf{$a$}    & \textbf{$+$}  & \textbf{$b$}  \\
    \hline
    \endfirsthead
    \multicolumn{5}{c}%
    {\tablename\ \thetable\ -- \textit{Continued from previous page}} \\
    \hline
    \textbf{$p$}    &       &   \textbf{$a$}    & $+$   & \textbf{$b$}  \\
    \hline
    \endhead
    \hline \multicolumn{5}{r}{\textit{Continued on next page}} \\
    \endfoot
    \hline
    \endlastfoot
                    & $=$           & $0$       &           & $p$   \\
                    & $=$           & $1$       &           & $p-1$ \\
                    & $=$           & $2$       &           & $p-2$ \\
    \textbf{$p$}    & $\vdots$      & \vdots    & \vdots    & \vdots\\
                    & $=$           & $p-2$     &           & $2$   \\
                    & $=$           & $p-1$     &           & $1$   \\
                    & $=$           & $p$       &           & $0$   \\
\end{longtable}

结果如下:

在此处输入图片描述

我希望有人能帮助我解决这个问题。

答案1

一个简单的代码pstricks:我添加一列(空)节点并将这些节点连接到\ncbar

\documentclass{article}
\usepackage{array} 
\usepackage{longtable} 
\usepackage{pst-node, auto-pst-pdf}

\begin{document}

\setlength{\arrayrulewidth}{0.3mm}
\setlength{\tabcolsep}{18pt}
\renewcommand{\arraystretch}{1.3}
\begin{postscript}
\psset{arrows=->, arrowinset=0.12, linearc=0.05}
\newcommand{\mynode}[1]{\pnode[0pt,0.5ex]{#1}}
\begin{longtable}{|c|c|c|c|@{\qquad}c@{\qquad}c|}
    \hline
    \textbf{$p$} & $=$ & \textbf{$a$} & \textbf{$+$} & \textbf{$b$} & \qquad\\
    \hline
    \endfirsthead
    \multicolumn{5}{c}%
    {\tablename\ \thetable\ -- \textit{Continued from previous page}} \\
    \hline
    \textbf{$p$} & & \textbf{$a$} & $+$ & \textbf{$b$} \\
    \hline
    \endhead
    \hline \multicolumn{5}{r}{\textit{Continued on next page}} \\
    \endfoot
    \hline
    \endlastfoot
                    & $=$ & $0$ & & $p$ & \mynode{p} \\
                    & $=$ & $1$ & & $p-1$ & \mynode{p1} \\
                    & $=$ & $2$ & & $p-2$ & \mynode{p2} \\
    \textbf{$p$} & $\vdots$ & \vdots & \vdots & \vdots & \\
                    & $=$ & $p-2$ & & $2$ & \mynode{2} \\
                    & $=$ & $p-1$ & & $1$ & \mynode{1} \\
                    & $=$ & $p$ & & $0$ & \mynode{0} \\
\end{longtable}
\ncbar[arm=1.2cm]{p}{0}
\ncbar[arm=1.6cm]{p1}{1}
\ncbar[arm=2.2cm]{p2}{2}
\end{postscript}

\end{document} 

在此处输入图片描述

答案2

与@marmot 的类似,但我清理了这些嘈杂的交叉,并使用虚拟列来水平对齐箭头的起点和终点。

\documentclass{article}%
\usepackage{array}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand{\tikznode}[2]{\relax
\ifmmode%
  \tikz[remember picture,baseline=(#1.base),inner sep=0pt]\node(#1){$#2$};
\else
  \tikz[remember picture,baseline=(#1.base),inner sep=0pt]\node(#1){#2};%
\fi}

\begin{document}
\setlength{\arrayrulewidth}{0.3mm}
\setlength{\tabcolsep}{12pt}
\renewcommand{\arraystretch}{1.3}
\begin{tabular}{|>{\centering}p{1.8cm}|c|>{\centering}p{1.8cm}|c|>{\centering}p{1.8cm}|@{}p{0pt}@{}} % 
    \hline
    \textbf{$p$}    &    $=$    &\textbf{$a$} & \textbf{$+$} & \textbf{$b$} & \tabularnewline
    \hline
    \textbf{$p$}    &           &\textbf{$a$} & $+$     & \textbf{$b$}  & \tabularnewline
    \hline
                    & $=$       & $0$       &           & $p$      &\tikznode{p2}{} \tabularnewline
                    & $=$       & $1$       &           & $p-1$    &\tikznode{p1}{} \tabularnewline
                    & $=$       & $2$       &           & $p-2$    &\tikznode{p0}{} \tabularnewline
    \textbf{$p$}    & $\vdots$  & $\vdots$  & $\vdots$  & $\vdots$ &\tabularnewline
                    & $=$       & $p-2$     &           & $2$      &\tikznode{0}{}  \tabularnewline
                    & $=$       & $p-1$     &           & $1$      &\tikznode{1}{}  \tabularnewline
                    & $=$       & $p$       &           & $0$      &\tikznode{2}{}  \tabularnewline
  \hline                    
\end{tabular}
\begin{tikzpicture}[overlay,remember picture,line width=.7pt,rounded corners]
 \foreach \X in {0,1,2}
  \draw[-latex] ($(p\X)+(-.7,3pt)$) -- ++({1.2+0.5*\X},0) |- ($(\X)+(-.7,3pt)$);
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案3

Ti 相当直接只要表格仅在一页上,就可以为 Z。

\documentclass{article}%
\usepackage{longtable}
\usepackage{tikz}
\newcommand{\tikznode}[2]{\relax
\ifmmode%
  \tikz[remember picture,baseline=(#1.base),inner sep=0pt] \node (#1) {$#2$};
\else
  \tikz[remember picture,baseline=(#1.base),inner sep=0pt] \node (#1) {#2};%
\fi}

\begin{document}
\setlength{\arrayrulewidth}{0.3mm}
\setlength{\tabcolsep}{18pt}
\renewcommand{\arraystretch}{1.3}
\begin{longtable}{|c|c|c|c|c|}
    \hline
    \textbf{$p$}    &    $=$    &   \textbf{$a$}    & \textbf{$+$}  & \textbf{$b$}  \\
    \hline
    \endfirsthead
    \multicolumn{5}{c}%
    {\tablename\ \thetable\ -- \textit{Continued from previous page}} \\
    \hline
    \textbf{$p$}    &       &   \textbf{$a$}    & $+$   & \textbf{$b$}  \\
    \hline
    \endhead
    \hline \multicolumn{5}{r}{\textit{Continued on next page}} \\
    \endfoot
    \hline
    \endlastfoot
                    & $=$           & $0$       &           & \tikznode{p0}{$p$}   \\
                    & $=$           & $1$       &           & \tikznode{p1}{$p-1$} \\
                    & $=$           & $2$       &           & \tikznode{p2}{$p-2$} \\
    \textbf{$p$}    & $\vdots$      & \vdots    & \vdots    & \vdots\\
                    & $=$           & $p-2$     &           & \tikznode{2}{$2$}   \\
                    & $=$           & $p-1$     &           & \tikznode{1}{$1$}   \\
                    & $=$           & $p$       &           & \tikznode{0}{$0$}   \\
\end{longtable}
\begin{tikzpicture}[overlay,remember picture]
 \foreach \X in {0,1,2}
 { \draw[-latex] (p\X) -- ++({1.5+0.5*\X},0) |- (\X);}
\end{tikzpicture}
\end{document}

在此处输入图片描述

这是一个更接近上图的版本,并且也没有使用 longtable,因为这里不需要。

\documentclass{article}%
\usepackage{array}
\usepackage{tikz}
\newcommand{\tikznode}[2]{\relax
\ifmmode%
  \tikz[remember picture,baseline=(#1.base),inner sep=0pt] \node (#1) {$#2$};
\else
  \tikz[remember picture,baseline=(#1.base),inner sep=0pt] \node (#1) {#2};%
\fi}

\begin{document}
\setlength{\arrayrulewidth}{0.3mm}
\setlength{\tabcolsep}{12pt}
\renewcommand{\arraystretch}{1.3}
\begin{tabular}{|>{\centering}p{1.8cm}|c|>{\centering}p{1.8cm}|c|>{\centering}p{1.8cm}|} % 
    \hline
    \textbf{$p$}    &    $=$    &   \textbf{$a$}    & \textbf{$+$}  & \textbf{$b$}  \tabularnewline
    \hline
    \textbf{$p$}    &       &   \textbf{$a$}    & $+$   & \textbf{$b$}  \tabularnewline
    \hline
                    & $=$           & $0$       &           & \tikznode{p0}{$p$}   \tabularnewline
                    & $=$           & $1$       &           & \tikznode{p1}{$p-1$} \tabularnewline
                    & $=$           & $2$       &           & \tikznode{p2}{$p-2$} \tabularnewline
    \textbf{$p$}    & $\vdots$      & $\vdots$    & $\vdots$    & $\vdots$ \tabularnewline
                    & $=$           & $p-2$     &           & \tikznode{2}{$2$}   \tabularnewline
                    & $=$           & $p-1$     &           & \tikznode{1}{$1$}   \tabularnewline
                    & $=$           & $p$       &           & \tikznode{0}{$0$}   \tabularnewline
  \hline                    
\end{tabular}
\begin{tikzpicture}[overlay,remember picture]
 \foreach \X in {0,1,2}
 { \draw[-latex] (p\X) -- ++({1.8+0.5*\X},0) |- (\X);}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容