使用表格将表格中的箭头从一个单元格移到另一个单元格

使用表格将表格中的箭头从一个单元格移到另一个单元格

我想从表格中的一个单元格到另一个单元格绘制一个红色箭头。将本例中的描述与单位联系起来我使用了表格和表格,不想使用矩阵。我正在使用考试类。我有很多这样的表格要写在答案键上。

平均能量损失

\documentclass[12pt,addpoints]{exam}
\usepackage{array}% this is need to centre data
\renewcommand{\arraystretch}{2}
\begin{document}
\begin{table}[h!]
\begin{center}
\setlength{\tabcolsep}{80pt}
\renewcommand{\arraystretch}{5}
\setlength\extrarowheight{-4pt}
\begin{tabular}{|c|c|} % <-- Alignments: 1st column left, 2nd middle and 3rd right, with vertical lines in between
% this is symbols representing meaning in relation to measurement contexts
\hline
Length of a classroom    &  cm \\ %\rule{0pt}{10pt}
%\\ % this needs to put in otherwise next line will be indented
\hline
Length of a finger nail  &  m  \\ %\rule{0pt}{10pt}
\hline
Length of your shoe  &  mm   \\ %\rule{0pt}{10pt}
\hline
\end{tabular}
\renewcommand{\arraystretch}{1}
\end{center}
\end{table}
\end{document}

答案1

正如我在上面的评论中提到的,您可以尝试使用tikzmark库,类似于在这里

\documentclass[12pt,addpoints]{exam}
\usepackage{array}% this is need to centre data
\renewcommand{\arraystretch}{2}

\usepackage{tikz}           % <---
\usetikzlibrary{tikzmark}   % <---


\begin{document}
    \begin{table}[h!]
\centering
\setlength{\tabcolsep}{80pt}
\renewcommand{\arraystretch}{5}
\setlength\extrarowheight{-4pt}
\begin{tabular}{|c|c|} % <-- Alignments: 1st column left, 2nd middle and 3rd right, with vertical lines in between
% this is symbols representing meaning in relation to measurement contexts
\hline
Length of a \tikzmarknode{a}{classroom}                 % <---
        &  \tikzmarknode{b}{cm} \\                      % <---
%\\ % this needs to put in otherwise next line will be indented
\hline
Length of a finger nail  &  m  \\ %\rule{0pt}{10pt}
\hline
Length of your shoe  &  mm   \\ %\rule{0pt}{10pt}
\hline
\end{tabular}
\begin{tikzpicture}[overlay, remember picture,
                    shorten >=2pt, shorten <=2pt]
                    ]
\draw [red, very thick, ->] (a) -- (b);
\end{tikzpicture}
    \end{table}
\end{document}

上述MWE经过两次或两次以上编译后的结果是:

在此处输入图片描述

答案2

使用{NiceTabular}nicematrixTikZ 来绘制箭头。

\documentclass[12pt,addpoints]{exam}
\usepackage{nicematrix,tikz}
\usetikzlibrary{arrows.meta}

\renewcommand{\arraystretch}{2}
\begin{document}

\begin{table}
\centering
\setlength{\tabcolsep}{80pt}
\renewcommand{\arraystretch}{5}
\setlength{\extrarowheight}{-4pt}

\begin{NiceTabular}{cc}[hvlines] 
   Length of a classroom    &  cm \\ 
   Length of a finger nail  &  m  \\ 
   Length of your shoe      &  mm   \\ 
\CodeAfter
   \tikz \draw [red,->,shorten < = 1mm, shorten > = 1mm] (1-1) -- (1-2) ; 
\end{NiceTabular}

\end{table}

\end{document}

您需要多次编译(因为 PGF/TikZ 节点)。

上述代码的输出

相关内容