1

Description of issue

I would like to make a table like the following in a LaTeX document that uses revtex4-2 as its document class: desired table

However, the table that I generate with LaTeX has a bunch of white columns that are undesired: revtex4-2 table

Strangely, these white columns are not present when I use article as my document class: regular-article table

LaTeX code:

\documentclass[aps, twocolumn]{revtex4-2}
% \documentclass[twocolumn]{article}

\usepackage{multirow} \usepackage[table,xcdraw]{xcolor}

\begin{document}

\begin{table}[] \caption{} \label{tab:my-table} \begin{tabular}{ll|c|cc|c|c|ccc|c} \rowcolor[HTML]{EFEFEF} \cellcolor[HTML]{EFEFEF} & \cellcolor[HTML]{EFEFEF} & \multicolumn{8}{c|}{\cellcolor[HTML]{EFEFEF}Col3} & \cellcolor[HTML]{EFEFEF} \ \rowcolor[HTML]{EFEFEF} \cellcolor[HTML]{EFEFEF} & \cellcolor[HTML]{EFEFEF} & AA & \multicolumn{2}{c}{\cellcolor[HTML]{EFEFEF}BB} & CC & DD & \multicolumn{3}{c|}{\cellcolor[HTML]{EFEFEF}EE} & \cellcolor[HTML]{EFEFEF} \ \rowcolor[HTML]{EFEFEF} \multirow{-3}{}{\cellcolor[HTML]{EFEFEF}Col1} & \multirow{-3}{}{\cellcolor[HTML]{EFEFEF}Col2} & & b.1 & b.2 & & & e.1 & e.2 & e.3 & \multirow{-3}{}{\cellcolor[HTML]{EFEFEF}Col4} \ \hline dat1 & 111 & 0.00 & 1.00 & 1.00 & & 1.00 & & 1.00 & & 111111.00 \ \rowcolor[HTML]{EFEFEF} dat2 & 222 & 0.00 & & 1.00 & 1.00 & 0.50 & & 1.00 & 1.00 & 222222.00 \ dat3 & 333 & 0.00 & & & & & & & & 333333.00 \ \rowcolor[HTML]{EFEFEF} dat4 & 444 & 0.00 & & & & & & & & 4444444.00 \end{tabular} \end{table*}

\end{document}

2 Answers2

1

As suggested in this StackExchange discussion, nicematrix does the job!

nicematrix-table

\documentclass[aps, twocolumn]{revtex4-2}

\usepackage{booktabs} \usepackage[table,xcdraw]{xcolor} \usepackage{nicematrix}

\begin{document}

\begin{table}[] \centering \begin{NiceTabular}{@{}ll|c|cc|c|c|ccc|c@{}} \CodeBefore \rowcolor{gray!10}{1-3} \rowcolors{2}{gray!10}{white} \Body % \toprule & & \Block{1-8}{Col3} & & & & & & & & \
& & & \Block{1-2}{BB} & & & & \Block{1-3}{EE} & & & \
Col1 & Col1 & AA & b.1 & b.2 & CC & DD & e.1 & e.2 & e.3 & Col4 \
\midrule
dat1 & 111 & 0.00 & 1.00 & 1.00 & & 1.00 & & 1.00 & & 111111.00 \
dat2 & 222 & 0.00 & & 1.00 & 1.00 & 0.50 & & 1.00 & 1.00 & 222222.00 \
dat3 & 333 & 0.00 & & & & & & & & 333333.00 \
dat4 & 444 & 0.00 & & & & & & & & 444444.00 \
% \bottomrule \end{NiceTabular} \caption{Caption} \label{tab:my_label} \end{table
}

\end{document}

1

Use of the new LaTeX 3 tabularray package also gives desired result already after one compilation. In MWE below is considered the package Version 2021K (2021-06-05):

\documentclass[aps, twocolumn]{revtex4-2}
\usepackage{multirow, tabularray}
\usepackage[table,xcdraw]{xcolor}

\begin{document}

\begin{table} \caption{} \label{tab:my-table} \begin{tblr}{colspec = {ll|c|cc|c|c|ccc|c}, colsep=4pt, row{odd} = {bg=gray!30}, row{2} = {bg=gray!30},
rowsep=1pt, }
\multirow{3}{
}{Col1} & \multirow{3}{}{Col2} & \multicolumn{8}{c}{Col3} & \multirow{3}{}{Col4} \ & & AA & \multicolumn{2}{c}{BB} & CC & DD & \multicolumn{3}{c}{EE} & \ & & & b.1 & b.2 & & & e.1 & e.2 & e.3 & \ \hline dat1 & 111 & 0.00 & 1.00 & 1.00 & & 1.00 & & 1.00 & & 111111.00 \ dat2 & 222 & 0.00 & & 1.00 & 1.00 & 0.50 & & 1.00 & 1.00 & 222222.00 \ dat3 & 333 & 0.00 & & & & & & & & 333333.00 \ % dat4 & 444 & 0.00 & & & & & & & & 4444444.00 \end{tblr} \end{table*}

\end{document}

enter image description here

Zarko
  • 296,517