在接下来的代码中,我希望tikzmark
将其放置在表格黑线上,但是出现了漂移。
主要目标是在表格的每个单元格的每个角落放置一个幻影 tikz 标记。
\documentclass{article}
\usepackage{tikz,array,xparse,luacode}
\usetikzlibrary{tikzmark}
\newcounter{TabTikzCount}
\makeatletter
\NewDocumentCommand{\TabTikzMark}{sm}{%
\IfBooleanTF{#1}{%
\\[-\ht\@arstrutbox]\noalign{\setcounter{TabTikzCount}{1}}%
\Row{3}
\\[-\dp\@arstrutbox]%
}{%
\\[-\ht\@arstrutbox]
\Row{3}
\\[-\dp\@arstrutbox]}}
\makeatother
\begin{luacode}
function row (s)
a = "\\multicolumn{1}{@{}c@{}}{\\tikzmark{\\Alph{TabTikzCount}0}"
for i = 1,s-1
do
a=a.."\\strut\\hfill\\tikzmark{\\Alph{TabTikzCount}"..i.."}}&\\multicolumn{1}{@{}c@{}}{"
end
a=a.."\\strut\\hfill\\tikzmark{\\Alph{TabTikzCount}"..s.."}}"
tex.print (a)
print (a)
end
\end{luacode}
\newcommand{\Row}[1]{%
\directlua{row(#1)}
\stepcounter{TabTikzCount}}
\begin{document}
\begin{tabular}{|c|c|c|c|}
\TabTikzMark*{4}\hline
a&z&a&d\TabTikzMark{4}\hline
a&z&a&d\TabTikzMark{4}\hline
\end{tabular}
\foreach \j in {A,B,C} {%
\foreach \i in {0,...,5} {%
\tikz[overlay,remember picture]
\node at (pic cs:\j\i) {\tiny \j\i} ;
}}
\end{document}
答案1
您正在添加空白:
\documentclass{article}
\usepackage{tikz,array,xparse,luacode}
\usetikzlibrary{tikzmark}
\newcounter{TabTikzCount}
\makeatletter
\NewDocumentCommand{\TabTikzMark}{sm}{%
\IfBooleanTF{#1}{%
\\[-\ht\@arstrutbox]\noalign{\setcounter{TabTikzCount}{1}}%
\Row{3}%
\\[-\dp\@arstrutbox]%
}{%
\\[-\ht\@arstrutbox]%
\Row{3}%
\\[-\dp\@arstrutbox]}}
\makeatother
\begin{luacode}
function row (s)
a = "\\multicolumn{1}{@{}c@{}}{\\tikzmark{\\Alph{TabTikzCount}0}"
for i = 1,s-1
do
a=a.."\\strut\\hfill\\tikzmark{\\Alph{TabTikzCount}"..i.."}}&\\multicolumn{1}{@{}c@{}}{"
end
a=a.."\\strut\\hfill\\tikzmark{\\Alph{TabTikzCount}"..s.."}}"
tex.print (a)
print (a)
end
\end{luacode}
\newcommand{\Row}[1]{%
\directlua{row(#1)}%
\stepcounter{TabTikzCount}}
\begin{document}
\begin{tabular}{|c|c|c|c|}
\TabTikzMark*{4}\hline
a&z&a&d\TabTikzMark{4}\hline
a&z&a&d\TabTikzMark{4}\hline
\end{tabular}
\foreach \j in {A,B,C} {%
\foreach \i in {0,...,5} {%
\tikz[overlay,remember picture]
\node at (pic cs:\j\i) {\tiny \j\i} ;
}}
\end{document}