请参阅示例代码。如果我删除奇数行的背景颜色规范,箭头将不间断地显示。有没有办法让箭头“位于”背景颜色之上?它在开始的单元格中显示正确(该单元格也具有背景颜色),因此我认为这与跨入新表格单元格有关。
\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage{tabularray}
\begin{document}
\begin{tblr}{
colspec = {Q[2in,l,m]X[1,c,m]X[0.7,c,m]X[1,c,m]X[1,c,m]X[0.7,c,m]X[1,c,m]},
hlines,
vlines,
row{odd} = {bg=gray!50}, %if this is commented out, then the arrow displays uninterrupted
row{1} = {bg=gray},
row{even} = {bg=white}
}
& Trial 1 & Units & {Sig Fig\\Check} & Trial 2 & Units & {Sig Fig\\Check} \\
Mass of graduated cylinder BEFORE addition of sugar water & & & &\SetCell{r,h}\begin{tikzpicture}[overlay,remember picture]\node (end) at (0,0){*};\end{tikzpicture} & & \\
Mass of graduated cylinder AFTER addition of sugar water & \SetCell{c,h}\begin{tikzpicture}[overlay, remember picture]\node(start) at (0,0){*};\draw[->] (start.east) -- (end.west);\end{tikzpicture}& & & & & \\
\end{tblr}
\end{document}
答案1
在我之后不久,有人发布了这个问题,并得到了一些回复 表格中颜色上的 Tikz 符号
在这个问题中,发布的解决方案提到问题在于 tikz 绘图发生后发生的着色(这是众所周知的,但我似乎找不到任何类似的 stackexchange 问题)
因此,我几乎采用了所有原始代码,并在表格着色完成后移动了箭头绘制,因为我可以参考节点,现在它运行完美。
\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage{tabularray}
\begin{document}
\begin{tblr}{
colspec = {Q[2in,l,m]X[1,c,m]X[0.7,c,m]X[1,c,m]X[1,c,m]X[0.7,c,m]X[1,c,m]},
hlines,
vlines,
row{odd} = {bg=gray!50}, %if this is commented out, then the arrow displays uninterrupted
row{1} = {bg=gray},
row{even} = {bg=white}
}
& Trial 1 & Units & {Sig Fig\\Check} & Trial 2 & Units & {Sig Fig\\Check} \\
Mass of graduated cylinder BEFORE addition of sugar water & & & &\SetCell{r,h}\begin{tikzpicture}[overlay,remember picture]\node (end) at (0,0){*};\end{tikzpicture} & & \\
Mass of graduated cylinder AFTER addition of sugar water & \SetCell{c,h}\begin{tikzpicture}[overlay, remember picture]\node(start) at (0,0){*};\end{tikzpicture}& & & & & \\
\end{tblr}
\begin{tikzpicture}[overlay,remember picture]
\draw[->] (start.east) -- (end.west);
\end{tikzpicture}
\end{document}
答案2
通过使用包tikzmark
库tikz
可以使您的代码更加清晰和简短:
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, % <---
tikzmark} % <---
\tikzset{is/.style = {inner xsep=3pt, inner ysep=0pt}} % <---
\usepackage{ragged2e}
\usepackage{tabularray}
\begin{document}
\noindent%
\begin{tblr}{cells = {font=\small}, % \small font size enable better formatting od cells contents
colspec = {Q[1.5in,l, cmd=\RaggedRight] % <---
*{6}{X[c]}},
colsep = {3pt}, % <---
row{1} = {m, font=\footnotesize\bfseries, bg=gray}, % <---
row{odd} = {bg=gray!30},
hlines, vlines,
}
& Trial 1 & Units & Sig Fig Check & Trial 2 & Units & Sig Fig Check \\
Mass of graduated cylinder BEFORE addition of sugar water
& & & & \tikzmarknode[is]{a}{$\ast$} % <---
& & \\
Mass of graduated cylinder AFTER addition of sugar water
& \tikzmarknode[is]{b}{$\ast$} % <---
& & & & & \\
\end{tblr}
\begin{tikzpicture}[overlay,remember picture]
\draw[->] (b.north east) -- (a.south west);
\end{tikzpicture}
\end{document}
至少经过两次编译后,您将获得以下结果: