你能帮我在 LaTeX 中获取这张表格吗?
完成下面的代码就能获得吗?
\begin{table}[htbp] \centering
\begin{tabular}{cccc}
\hline
a & b & c & d \\
e & f & g & h \\
i & & & j \\
k & & & l \\
\hline
\end{tabular}
\end{table}
答案1
使用宏的可能解决方案\tikzmark
(需要两次编译运行):
\documentclass{article}
\usepackage{tikz}
\newcommand{\tikzmark}[1]{\tikz[remember picture,overlay, baseline=-0.5ex]\node (#1){};}
\newcommand{\connect}[3][3mm]{\tikz[remember picture,overlay]\draw[shorten <=-#1, shorten >=-#1](#2)--(#3);}
\begin{document}
Cancelling two rows and two columns:
\begin{table}[htbp] \centering
\begin{tabular}{cccc}
\hline
a & b & c & d \\
e & f & g & h \\
i & \tikzmark{p1} & \tikzmark{p2} & j \\
k & \tikzmark{p3} & \tikzmark{p4} & l \\
\hline
\connect{p1}{p4}
\connect{p2}{p3}
\end{tabular}
\end{table}
Cancelling one row and two columns:
\begin{table}[htbp] \centering
\begin{tabular}{cccc}
\hline
a & b & c & d \\
e & f & g & h \\
i & \tikzmark{a1} & \tikzmark{a2} & j \\
\hline
\connect[1mm]{a1.north}{a2.south}
\connect[1mm]{a1.south}{a2.north}
\end{tabular}
\end{table}
Cancelling two rows and one column:
\begin{table}[htbp] \centering
\begin{tabular}{cccc}
\hline
a & b & c & d \\
e & f & g & h \\
i & \tikzmark{b1} & j & k\\
l & \tikzmark{b2} & m & n\\
\hline
\connect[0mm]{b1.north west}{b2.south east}
\connect[0mm]{b1.north east}{b2.south west}
\end{tabular}
\end{table}
\end{document}
结果:
答案2
使用{NiceTabular}
和nicematrix
TikZ 绘制十字架。
\documentclass{article}
\usepackage{nicematrix,tikz}
\begin{document}
\begin{table}[htbp]
\centering
\begin{NiceTabular}{cccc}
\hline
a & b & c & d \\
e & f & g & h \\
i & & & j \\
k & & & l \\
\hline
\CodeAfter
\begin{tikzpicture} [shorten < = 1mm, shorten > = 1mm]
\draw (3-|2) -- (5-|4) ;
\draw (5-|2) -- (3-|4) ;
\end{tikzpicture}
\end{NiceTabular}
\end{table}
\end{document}