9

Can you help me to obtain this table in LaTeX?

Is it possible to obtain it by completing the following code?

\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}

enter image description here

2 Answers 2

10

A possible solution with the \tikzmark macro (requires two compilation runs):

\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}

The result: enter image description here

3
  • One more question please... What would you change if I want the cross in two rows but one column (instead of two rows and two columns?) I guess the "connect" command has to change...
    – Marco
    Commented Dec 13, 2012 at 14:34
  • No, why? You can use the TikZ anchors: I'll provide you a couple of examples. Commented Dec 13, 2012 at 14:42
  • Ok, I get it :-) Many Thanks! (+1)
    – Marco
    Commented Dec 13, 2012 at 14:47
0

With {NiceTabular} of nicematrix and TikZ to draw the cross.

\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}

Output of the above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .