2

I am trying two build a table, with the following code:

\begin{table}[]
\begin{tabular}{@{}lllll@{}}
\toprule
\multicolumn{3}{c}{gamma function} & \multicolumn{2}{c}{\begin{tabular}[c]{@{}c@{}}zeta and gamma \\ function\end{tabular}} \\ \midrule
1          & 1         & 1         & 1                                          & 1                                         \\
2          & 3         & 4         & 5                                          & 6                                         \\
4          & 7         & 8         & 43                                         & 21                                        \\ \bottomrule
\end{tabular}
\end{table}

But the third and fourth columns have different widths. I tried to set equal width for all columns, but doesn't work. How can I fix this problem?

  • Do you want all five data columns to have the same width, or just columns 3 & 4? – Mico Dec 15 '19 at 20:12
  • 1
    I am trying to fix the same width for all columns. – sane Dec 15 '19 at 20:14
4

Here's a solution which sets all five columns to have equal width. It employs the w column type that's provided by the array package. The column contents are center-set via the c option in the first argument of the w columns.

enter image description here

\documentclass{article}
\usepackage{booktabs}
\usepackage{array}  % for "w" column type
\begin{document}
\begin{table}
\begin{tabular}{@{} *{5}{w{c}{11mm} }@{}}
\toprule
\multicolumn{3}{@{}c}{gamma function} & 
\multicolumn{2}{c}{\begin{tabular}[c]{@{}c@{}}
   zeta and gamma \\ function\end{tabular}} \\ 
\midrule
1 & 1 & 1 & 1  & 1  \\
2 & 3 & 4 & 5  & 6  \\
4 & 7 & 8 & 43 & 21 \\ 
\bottomrule
\end{tabular}
\end{table}
\end{document}
  • Thanks, very useful! How I can add 6th column with different width? – sane Dec 15 '19 at 20:30
  • @sane - change *{5}{w{c}{11mm}} to *{5}{w{c}{11mm}}w{<some other width>}. – Mico Dec 15 '19 at 20:44
  • Should I keep *{5}? – sane Dec 15 '19 at 20:48
  • Ok, I tried the following *{5}{w{c}{11mm}}*{1}{w{c}{25mm}}. Itworks! – sane Dec 15 '19 at 20:55
  • @sane - *{1}{w{c}{25mm}} and w{c}{25mm} have the exact same effect. The second expression avoids code clutter, though. – Mico Jan 21 at 11:00
5

I propose this, with an empty column to separate the groups, siunitx and makecell for the column heads:

\documentclass{article}
\usepackage{makecell} 
\usepackage{booktabs}
\usepackage{siunitx} 

\begin{document}

\begin{table}
\sisetup{table-format=2.0, table-number-alignment=center}
\begin{tabular}{@{}SSSc@{\enspace}SS}
\toprule
\multicolumn{3}{@{}c}{\thead{gamma \\ function}} & & \multicolumn{2}{@{\enspace}c}{\makebox[0pt]{\thead{zeta and\\ gamma \\ functions}}} \\
\midrule
1 & 1 & 1 & & 1 & 1 \\
2 & 3 & 4 & & 5 & 6 \\
4 & 7 & 8 & & 43 & 21 \\
\bottomrule
\end{tabular}
\end{table}

\end{document} 

enter image description here

  • 1
    Many many wishes for your reputation of 200k: auguriiiiiiiiiiiiiii ! – Sebastiano Dec 15 '19 at 21:57
  • 2
    Mille grazie!!! – Bernard Dec 15 '19 at 22:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.