我需要在表格中的一些单元格边框中绘制一些箭头标记。该箭头应从单元格的右下角开始,到单元格的右上角结束。我已经绘制了这样的箭头tikzmark
和calc
库。以下是我的解决方案
\newcommand\cellarrow[1]{%
\begin{tikzpicture}[remember picture, overlay, >=stealth, shift={(0,0)}]
\draw[->, line width=2pt,color =brown] ( $ (pic cs:#1) +(2.7\tabcolsep,-1ex) $ ) to ( $ (pic cs:#1) +(16pt,2.5ex) $ ) ;
\end{tikzpicture}%
}
显然这不是一个好的解决方案,因为它只适用于所示的特定表格Section 1
。所以我们需要以某种方式定位右下角并绘制与相应单元格高度相同的箭头。
这个怎么做?
任何想法都将受到高度赞赏。
梅威瑟:
\documentclass{article}
\usepackage{tikz}
\usepackage{xcolor}
\usetikzlibrary{calc,tikzmark}
\newcommand\cellarrow[1]{%
\begin{tikzpicture}[remember picture, overlay, >=stealth, shift={(0,0)}]
\draw[->, line width=2pt,color =brown] ( $ (pic cs:#1) +(2.7\tabcolsep,-1ex) $ ) to ( $ (pic cs:#1) +(16pt,2.5ex) $ ) ;
\end{tikzpicture}%
}
\def\done{done}
\begin{document}
\section{Table with Same width}
\begin{tabular}{|l|c|c|c|c|c|c|}
\hline
Some column & \done & \done & \done& \done& \done&\done \\
\hline
This has arrows&\tikzmark{a} & \tikzmark{b} & \tikzmark{c} & & & \\
\hline
Communication of Papers
& & & & & & \\ \hline
\end{tabular}
\cellarrow{a}
\cellarrow{b}
\cellarrow{c}
\section{Some other table}
\renewcommand{\arraystretch}{2}
\begin{tabular}{|l|c|c|c|c|c|c|c|c|}
\hline
Some column & \done & \done & \done& \done& \done& \done &\done &\\
\hline
This has arrows& & & & & & \tikzmark{f} & \tikzmark{g} & \tikzmark{h} \\
\hline
Communication of Papers
& & & & & & & & \\ \hline
\end{tabular}
\cellarrow{f}
\cellarrow{g}
\cellarrow{h}
\end{document}
答案1
也许在您的情况下使用 TikZ 矩阵更方便。
我创建了一个\cellarrow
有两个选项的宏:要绘制箭头的单元格的行和列。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\tikzset{
mymatr/.style={
matrix of nodes,
nodes in empty cells,
nodes={draw, text centered, text width=width("\done")},
row sep=-\pgflinewidth,
column sep=-\pgflinewidth,
}
}
\usepackage{xcolor}
\def\done{done}
\newcommand\cellarrow[2]{
\draw[-stealth, line width=2pt, color=brown] (matr-#1-#2.south east) -- (matr-#1-#2.north east);
}
\begin{document}
\section{Table with Same width}
\begin{tikzpicture}
\matrix[mymatr,
column 1/.style={nodes={text width=width("Communication of Papers")}},
nodes={text height=height("C"), text depth=depth("p")}
] (matr) {
Some column & \done & \done & \done& \done& \done&\done \\
This has arrows& & & & & & \\
Communication of Papers & & & & & & \\};
\foreach \cell in {2,3,4}
{\cellarrow{2}{\cell}}
\end{tikzpicture}
\section{Some other table}
\begin{tikzpicture}
\matrix[mymatr,
column 1/.style={nodes={text width=width("Communication of Papers")}},
column 9/.style={nodes={text width=width("~~")}},
nodes={text height=3.5ex, text depth=2ex}
] (matr) {
Some column & \done & \done & \done& \done& \done& \done &\done &\\
This has arrows& & & & & & & & \\
Communication of Papers & & & & & & & & \\};
\foreach \cell in {7,8,9}
{\cellarrow{2}{\cell}}
\end{tikzpicture}
\end{document}
答案2
这是一个{NiceTabular}
使用 的解决方案nicematrix
。
\documentclass{article}
\usepackage{nicematrix}
\usepackage{tikz}
\usepackage{xcolor}
\def\done{done}
\makeatletter
\ExplSyntaxOn
\cs_new_protected:Nn \__David_Arrow:nn
{
\tikz \draw [->,red,very~thick]
( \int_eval:n { #1 + 1 } -| \int_eval:n { #2 + 1 } )
-- ( #1 -| \int_eval:n { #2 + 1 } ) ;
}
\NewDocumentCommand \Arrow { }
{
\tl_gput_right:Nx \g_nicematrix_code_after_tl
{ \__David_Arrow:nn { \arabic{iRow} } { \arabic{jCol} } }
}
\ExplSyntaxOff
\makeatother
\begin{document}
\section{Table with Same width}
\begin{NiceTabular}{|l|c|c|c|c|c|c|}
\hline
Some column & \done & \done & \done& \done& \done&\done \\
\hline
This has arrows& \Arrow & \Arrow & \Arrow & & & \\
\hline
Communication of Papers & & & & & & \\ \hline
\end{NiceTabular}
\section{Some other table}
\renewcommand{\arraystretch}{2}
\begin{NiceTabular}{|l|c|c|c|c|c|c|c|c|}
\hline
Some column & \done & \done & \done& \done& \done& \done &\done &\\
\hline
This has arrows& & & & & & \Arrow & \Arrow & \Arrow \\
\hline
Communication of Papers
& & & & & & & & \\ \hline
\end{NiceTabular}
\end{document}
由于 PGF/Tikz 节点,您需要进行多次编译。