1

I would like to make a double entry table in LaTeX.

Here is the result that I would like to get:

enter image description here

I found a clue here:

\documentclass{article}
\usepackage{multirow}
  \begin{document}
  \begin{center}
    \begin{tabular}{ c || l | r | c }
      & \multicolumn{3}{c}{Columns} \\ \hline \hline
      \multirow{3}{*}{Rows}
      & A1 & B1 & C1 \\ \cline{2-4}
      & A222 & B22 & C2 \\ \cline{2-4}
      & A3 & B333 & C33
    \end{tabular}
  \end{center}
\end{document}

enter image description here

I managed to get a partial solution:

\begin{document}
    \begin{center}
        \begin{tabular}{ l || r | c }
          A1 & B1 & C1 \\ \hline \hline
          A222 & B22 & C2 \\ \hline
          A3 & B333 & C33
        \end{tabular}
    \end{center}
\end{document}

However, it doesn't solve all my problems. Is it possible to get square cells with everything centered in the cell? I found other partial solutions here but I don't know tikz at all. The matrix environment might not suit my needs because I would like to avoid outer borders and I didn't find any solution with double lines separing row's titles from the inner cells.

Dunno
  • 329
  • Did you google for e.g. latex diagonal line in table which gives according to me already a potential result: https://tex.stackexchange.com/questions/17745/diagonal-lines-in-table-cell – albert May 27 '21 at 10:54
  • I'm pretty sure that's something you could manage with François Pantigny's nicematrix package. I'm not that an expert of it to provide a complete working solution, but it will pop one of these days. – SebGlav May 27 '21 at 17:35

2 Answers2

2

I use plain TikZ. You can fine turn everything as desired. In particular, double distance to adjust distance inside the double lines.

About scaling, I propose 2 manner. The first one is scaling the whole picture with [scale=.8]; the text will not be affected.

enter image description here

\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}[scale=.8]
\draw (0,0)--(1,-1) (0,-2)--(3,-2) (2,0)--(2,-3);
\draw[double,double distance=.5pt] (0,-1)--(3,-1) (1,0)--(1,-3) ;
\path[magenta]
(1.5,-.5) node{2} ++(0:1) node{3}
(.5,-1.5) node{4} ++(0:1) node{8}  +(0:1) node{12}
(.5,-2.5) node{5} ++(0:1) node{10} +(0:1) node{15}
;
\end{tikzpicture}
\end{document}

The 2nd way is scaling only nodes with nodes={scale=.6}; the lines will not be affected.

enter image description here

\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw (0,0)--(1,-1) (0,-2)--(3,-2) (2,0)--(2,-3);
\draw[double,double distance=.5pt] (0,-1)--(3,-1) (1,0)--(1,-3);
\path[teal,nodes={scale=.6}]
(1.5,-.5) node{2} ++(0:1) node{3}
(.5,-1.5) node{4} ++(0:1) node{8}  +(0:1) node{12}
(.5,-2.5) node{5} ++(0:1) node{10} +(0:1) node{15}
;
\end{tikzpicture}
\end{document}
Black Mild
  • 17,569
1

Like I said in the comments, I'm not that a specialist of the nicematrix package, so I didn't come with a complete corresponding answer. Anyway, it's a start and sure someone (maybe François himself) would come and improve that solution.

nicematrix1

\documentclass[12pt]{article}
\usepackage{nicematrix}

\begin{document}

\renewcommand{\arraystretch}{2}
$\begin{NiceTabular}{W{c}{1cm}|W{c}{1cm}|W{c}{1cm}}
\diagbox{}{}& 2 & 3 \\
\hline \hline
4 & 8 & 12 \\
\hline
5 & 10 & 15
\end{NiceTabular}$

\end{document}

The main problem is that you may think that by adding a vertical line in the table declaration, it would be good, but that doesn't work fine:

$\begin{NiceTabular}{W{c}{1cm}||W{c}{1cm}|W{c}{1cm}}

nicematrix 2

SebGlav
  • 19,186