3

I'm trying to add an in-between row for my table. This image shows what I can do with tabular (above), and what I'd like to get (below):

enter image description here

This was produced with a trick that makes the source hard to read and transposes the table.

Is there a better way? E.g. any way to adjust the offset of a cell or column, as I'd do with yshift in TikZ?

\documentclass{article}
\begin{document}
\begin{table}
\begin{tabular}{llll}

\multicolumn{4}{l}{\textbf{What I have}} \\
\quad a & b & c & d \\
\quad e & f & g & h \\
\quad i & j & k &  \\

\multicolumn{4}{l}{\textbf{What I want}} \\
\quad 
\begin{tabular}{@{}c@{}} a \\ e \\ i \end{tabular}
& \begin{tabular}{@{}c@{}} b \\ f \\ j \end{tabular}
& \begin{tabular}{@{}c@{}} c \\ g \\ k \end{tabular}
& \begin{tabular}{@{}c@{}} d \\ h \\ \end{tabular}

\end{tabular}
\end{table}
\end{document}

3 Answers 3

2

As a quick hack, you could use a \multirow. The disadvantage is that you will have to manually choose a suitable width.

\documentclass{article}

\usepackage{multirow}
\begin{document}
\begin{table}
\begin{tabular}{llll}
\multicolumn{4}{l}{\textbf{What I have}} \\
\quad a & b & c & \multirow{3}{0.5cm}{d\linebreak h} \\
\quad e & f & g &  \\
\quad i & j & k &  \\
\end{tabular}
\end{table}
\end{document}
2

Here is a solution with {NiceTabular} of nicematrix. That environment is similar to the classical environment {tabular} (of array) but also creates PGF/Tikz nodes under the cells, rows and columns. It's possible to use those nodes with Tikz to put whatever you want at any position.

\documentclass{article}
\usepackage{nicematrix}
\usepackage{tikz}

\begin{document}

\begin{NiceTabular}{ccc}
  a & b & c \\
  e & f & g \\
  i & j & k 
\CodeAfter
  \begin{tikzpicture}
    \node [right] at (2-|last) { d } ; 
    \node [right] at (3-|last) { h } ; 
  \end{tikzpicture}
\end{NiceTabular}

\end{document}

Output of the first code

\documentclass{article}
\usepackage{nicematrix}
\usepackage{tikz}

\begin{document}

\begin{NiceTabular}{ccc}
  a & b & c \\
  e & f & $\displaystyle \int_a^b f(x)\, dx$ \\
  i & j & k 
\CodeAfter
  \begin{tikzpicture}
    \node [right] at (2-|last) { d } ; 
    \node [right] at (3-|last) { h } ; 
  \end{tikzpicture}
\end{NiceTabular}

\end{document}

Output of the second code

1

Similar to nice @sam answer (+1) but with tblr of tabularray package and prescribed width of the last table column:

\documentclass{article}
\usepackage{tabularray}

\begin{document}
    \begin{table}
\begin{tblr}{colspec = {*{3}{l} Q[l, wd=1em]},
             cell{1}{Z} = {r=3}{}
             }
\quad a & b & c &   d h     \\
\quad e & f & g &           \\
\quad i & j & k &           \\
\end{tblr}
    \end{table}
\end{document}

enter image description here

You must log in to answer this question.

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