3

enter image description here

I want to create this type of table in the latex. What I did is the following

\begin{tabular}{c|ccccc|ccccc|ccccc}
 \toprule
  &&& Edge count &&&&& Wedge count &&&&& Triangle count &&\\
 \hline
 $p$ &&  \Romannum{1} &  \Romannum{2} &  \Romannum{3} &&& \Romannum{1}  & \Romannum{2} & \Romannum{3} &&& \Romannum{1} & \Romannum{2} & \Romannum{3} &\\
 \hline
 $0.025$ &&     0 & 0 & 0 &&& 0 & 3 & 1 &&& 0 & 1 & 2 &\\
 $0.100$ && 2 & 0 & 1 &&& 0 &     0 & 0 &&& 1 & 0 & 1 &\\
 $0.250$ && 2 & 1 & 0 &&& 1 & 2 & 0 &&& 0 & 0 &     0 &\\
 \bottomrule
 \end{tabular}

Unable to get bracket quantity under every number in the latex code.

1
  • 1
    Since you need vertical lines in the table, it's inappropriate to use \toprule and \bottomrule.
    – Stephen
    Dec 17, 2023 at 6:31

2 Answers 2

6

Your table has defined much more columns as they are needed. For example:

\documentclass[margin=3mm]{standalone}
\usepackage{array, booktabs}
\usepackage[Most]{romannum}

\begin{document}
\begin{tabular}{c| *3{wc{2em}} | *3{wc{2em}} | *3{wc{2em}} }   
    \toprule
                &   \multicolumn{3}{c|}{Edge count}
                    &   \multicolumn{3}{c|}{Wedge count} 
                        &   \multicolumn{3}{c}{Triangle count}   \\
    \cline{2-10}
 $p$            &   \Romannum{1} 
                    &  \Romannum{2} 
                        &  \Romannum{3} 
                &   \Romannum{1}
                    &  \Romannum{2}
                        &  \Romannum{3} 
                 &   \Romannum{1}
                    &  \Romannum{2}
                        &  \Romannum{3} \\
     \hline
  0.025     & 0 & 0 & 0 & 0 & 3 & 1 & 0 & 1 & 2 \\
  0.100    & 2 & 0 & 1 & 0 & 0 & 0 & 1 & 0 & 1 \\
  0.250    & 2 & 1 & 0 & 1 & 2 & 0 & 0 & 0 & 0 \\
    \bottomrule
 \end{tabular}
 \end{document}

which reproduce your problem:

enter image description here

  • You should be aware, that rules defined in booktabs package are not intended for tables with vertical rules (around them are small vertical spaces).
  • This spaces can be removed by redefinition of \toprule,\midrule and cmidrule, and bottomrule.
  • Another possibilities is use tablr of tabularray package, which remove these vertical spaces:
\documentclass[margin=3mm]{standalone}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\usepackage[Most]{romannum}

\begin{document}
\begin{tblr}{colspec={c| *3{Q[c,wd={2em}]} |  *3{Q[c,wd={2em}]} |  *3{Q[c,wd={2em}]} },
             cell{1}{2,5,8} = {c=3}{}
            }  
    \toprule
                &   Edge count 
                    &   &   &   Wedge count  
                                &   &   Triangle count  \\
    \cmidrule{2-10}
 $p$            &   \Romannum{1} 
                    &  \Romannum{2} 
                        &  \Romannum{3} 
                &   \Romannum{1}
                    &  \Romannum{2}
                        &  \Romannum{3} 
                 &   \Romannum{1}
                    &  \Romannum{2}
                        &  \Romannum{3} \\
     \midrule
  0.025     & 0 & 0 & 0 & 0 & 3 & 1 & 0 & 1 & 2 \\
  0.100    & 2 & 0 & 1 & 0 & 0 & 0 & 1 & 0 & 1 \\
  0.250    & 2 & 1 & 0 & 1 & 2 & 0 & 0 & 0 & 0 \\
    \bottomrule
\end{tblr}
\end{document}

enter image description here

3
  • The gap above I, II, III is smaller than the gap below. This doesn't look right.
    – Simd
    Dec 17, 2023 at 15:09
  • @Simd - That's a direct consequence of using \hline.
    – Mico
    Dec 17, 2023 at 15:40
  • Given the little information we have about the OP's document setup, I don't think it's necessary (or advisable) to load the romannum package with the option Most (or most).
    – Mico
    Dec 17, 2023 at 15:41
3

I can see nothing wrong with getting rid of the vertical lines entirely. Conversely, I would advocate making more use of the macros of the booktabs package. And, since it looks like the 9 data columns will contain decimal numbers, it would be useful to align them on their decimal markers; this may be done with the help of the dcolumn package and its D column type.

enter image description here

\documentclass{article}
\usepackage{booktabs,array,romannum}
\usepackage{dcolumn} % align numbers in 'D'-type columns on their decimal markers
\newcolumntype{d}[1]{D{.}{.}{#1}}
\newcommand\mc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro

\begin{document}
\begin{center}
\setlength\tabcolsep{0pt}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} 
           >{$}l<{$} 
           *{3}{*{2}{d{1.3}}d{1.4}} }
\toprule
 p & \multicolumn{3}{c}{Edge count} 
   & \multicolumn{3}{c}{Wedge count} 
   & \multicolumn{3}{c}{Triangle count} \\
\cmidrule{2-4} \cmidrule{5-7} \cmidrule{8-10}
   & \mc{\Romannum{1}} & \mc{\Romannum{2}} & \mc{\Romannum{3}}
   & \mc{\Romannum{1}} & \mc{\Romannum{2}} & \mc{\Romannum{3}} 
   & \mc{\Romannum{1}} & \mc{\Romannum{2}} & \mc{\Romannum{3}} \\
\midrule
0.025 & 0.95   & 0.98   & 0.93   & 0.00 & 0.00 & 0.00 & 0.00 & 0.00 & 0.98  \\
      &(0.137) &(0.273) &(0.278) & & & & & &                         (0.273)\\
0.100 & 0.00   & 0.00   & 0.00   & 0.00 & 0.00 & 0.00 & 0.00 & 0.00 & 0.00  \\
0.25  & 0.00   & 0.00   & 0.00   & 0.00 & 0.00 & 0.00 & 0.00 & 0.00 & 0.00  \\
\bottomrule
\end{tabular*}

\end{center}
\end{document}

You must log in to answer this question.

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