3

How can one make the following table with columns within columns?

enter image description here

3
  • 1
    What have you tried so far? Please show us your code ... Commented Sep 26, 2021 at 10:55
  • I have not created a table before! Just checked Table overleaf here overleaf.com/learn/latex/Tables, but it does show anything like what I need. I am using the following document class: \documentclass[pra,onecolumn]{revtex4}. Commented Sep 26, 2021 at 10:59
  • 1
    You need to define so may columns as you needed on table body and than put Action 1 and Action 2 into \multicolumn{2}{c}{ <content> }. BTW, columns cannpot be split to "sub" columns, but cells in adjacent columns can be merged. Commented Sep 26, 2021 at 11:06

3 Answers 3

2

There's nothing particularly special about your table. Just use a couple of \multicolumn directives for the cells that span two columns.

To have the decimal markers show up as \cdot (raised dot) symbols and to align the numbers in the four data columns on the decimal markers, I suggest you load the siunitx package, employ its S column type instead of basic-LaTeX c column type, and run \sisetup{output-decimal-marker=\cdot}.

enter image description here

Observe that non-numeric cell contents such as \alpha and \beta are encased in curly braces; this informs the siunitx package that the cell contents shouldn't be processed further and just be centered horizontally.

\documentclass[pra]{revtex4} \usepackage{siunitx} % for 'S' column type \begin{document} \begin{table} \sisetup{output-decimal-marker=\cdot} % optional \caption{A 5-column table} \begin{tabular}{ | l | *{4}{S[table-format=1.2]|} } \hline Class & \multicolumn{2}{c|}{Action 1} & \multicolumn{2}{c|}{Action 2} \\ \cline{2-5} & {$\alpha$} & {$\beta$} & {$\alpha$} & {$\beta$} \\ \hline C1 & 1.01 & 0.1 & 1.3 & 1.5 \\ \hline C2 & 0.1 & 1.3 & 1.5 & 1.01 \\ \hline C3 & 3.0 & 3.1 & 0.4 & 1.2 \\ \hline \end{tabular} \end{table} \the\tabcolsep \end{document} 
2

Let me spell out my comment, but now with considering tabularray package and its syntax for multirow and multicolumn cells:

\documentclass{revtex4-2} \usepackage{tabularray} \UseTblrLibrary{siunitx} % for 'S' column type \begin{document} \begin{tblr}{hlines, vlines, colspec={c Q[c, si={table-format=1.2}, wd=2em] % S column type *{2}{Q[c, si={table-format=1.1}, wd=2em]} Q[c, si={table-format=1.2}, wd=2em] }, } \SetCell[r=2]{c} Class % <--- multi row cell & \SetCell[c=2]{c} {{{Action 1}}} % <--- multi column cell in S column type & & \SetCell[c=2]{c} {{{Action 2}}} & \\ & $\alpha$ & $\beta$ & $\alpha$ & $\beta$ \\ C1 & 1.01 & 0.1 & 1.3 & 1.5 \\ C2 & 0.1 & 1.3 & 1.5 & 1.01 \\ C3 & 3.0 & 3.1 & 0.4 & 1.2 \\ \end{tblr} \end{document} 

enter image description here

1

With {NiceTabular} of nicematrix. However, nicematrix is not compatible with the class revtex4. I have used the class revtex4-1 (which is also obsolete...).

\documentclass[pra]{revtex4-1} \usepackage{siunitx} % for 'S' column type \usepackage{nicematrix} \usepackage{caption} \begin{document} \begin{table} \sisetup{output-decimal-marker=\cdot} % optional \caption{A 5-column table} \centering \begin{NiceTabular}{l*{4}{S[table-format=1.2]}}[hvlines] \Block{2-1}{} Class & \Block{1-2}{Action 1} && \Block{1-2}{Action 2} \\ & {$\alpha$} & {$\beta$} & {$\alpha$} & {$\beta$} \\ C1 & 1.01 & 0.1 & 1.3 & 1.5 \\ C2 & 0.1 & 1.3 & 1.5 & 1.01 \\ C3 & 3.0 & 3.1 & 0.4 & 1.2 \\ \end{NiceTabular} \end{table} \end{document} 

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code

However, I would recommend a tabular in the style of booktabs.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.