4

During my studies, I was mostly fine with the standard tables I computed with certain table creation software. Now I was urged by my professor to prepare my thesis in "publication like" format.

The hardest thing for me is creating good looking tables.

See e.g. this:

\begin{table}[h]
\scalebox{0.9}{
\begin{tabular}{@{}lccccc@{}}
\toprule
           & \multicolumn{1}{l}{}                                                                          & \multicolumn{4}{c}{Total economic damage (mUS\$)}                                                                                            \\ \midrule
           & \multicolumn{1}{l}{Risk factor}                                                               & \multicolumn{1}{l}{Upstream  Losses} & \multicolumn{1}{l}{Downstream Losses} & \multicolumn{1}{l}{Total  Losses} & \multicolumn{1}{l}{Ratio} \\ \midrule
Scenario 1 & \begin{tabular}[c]{@{}c@{}}Supervisory control \\ and data acquisition\\ network\end{tabular} & 23.221                               & 14.876                                & 38.097                            & 1.56                      \\
Scenario 2 & Cloud service failure                                                                         & 722                                  & 1.196                                 & 1.918                             & 0.60                      \\
Scenario 3 & \begin{tabular}[c]{@{}c@{}}Health sector and \\ hospitals\end{tabular}                        & 28.487                               & 10.771                                & 39.257                            & 2.64                      \\
Scenario 4 & Municipal services                                                                            & 23.257                               & 9.105                                 & 32.361                            & 2.55                      \\
Scenario 5 & Telecommunications                                                                            & 1.521                                & 1.593                                 & 3.113                             & 0.95                      \\
Scenario 6 & Cross-sector attack                                                                           & 34.879                               & 37.669                                & 72.458                            & 0.93                      \\ \bottomrule
\end{tabular}}
\caption{xxx}
\end{table}

enter image description here

Which does not look bad for a student essay. However, I do want to make an effort to make it more professional looking. When looking at it, the aesthetics are just kind of off (e.g. the space inbetween rows/colum which is sometimes larger/smaller depending on page breaks).

What are some fixes I could try to accomplish this?

I would appreciate any help

  • 2
    do not use scalebox. And the line spacing in the second column looks odd, but from your code one can't see why it is so large. And align the numbers with siunitx. – Ulrike Fischer Mar 31 '23 at 16:23
  • thank you! what would you suggest to make the table fitting on one page? manipulate width? – rememberthename_ Mar 31 '23 at 17:15
  • @HansD. Choose one column and decrease its width. Insert line breaks in the column headers ... there are many ways to decrease the width of a table without decreasing the font. – Jasper Habicht Mar 31 '23 at 17:27
  • @rememberthename_ Not directly related to the table, but avoid using the same symbol as decimal separator and for digit grouping. In your last column you seem to be using . as a decimal separator, while everywhere else in the table it seems to be used to group digits. This is confusing and can lead to your number being misread by a factor of 1000. – Marcel Krüger Apr 01 '23 at 12:39

2 Answers2

9

My suggestions would be:

  • Only use \multicolumn where it relly belongs. It hardly makes sence in your example to use it to span over just one single column (and I really wonder why so many people suddenly do this ... should we blame ChatGPT?).
  • The same holds for the nested tabulars. Better choose the p column type here, which also solves the problem of overly wide line spacing inside the cells.
  • Talking of column types: Since you are dealing with numbers, why don't you try the siunitx package that allows you to nicely arrange numbers aligned at the decimal separator (I know, it is not strictly necessary here, but maybe for other use cases, it is a nice idea).
  • Draw the horizontal line that spans over the four last columns only over those columns which are meant to be grouped.

\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage{array, booktabs, siunitx}

\begin{document} \renewcommand{\arraystretch}{1.25} \begin{tabular}{ @{} l >{\raggedright\arraybackslash}p{7em} *{4}{S[table-format=3.3]} @{} } \toprule & & \multicolumn{4}{c}{Total economic damage (mUS$)} \ \cmidrule{3-6} & {Risk Factor} & {Upstream Losses} & {Downstream Losses} & {Total Losses} & {Ratio} \ \midrule Scenario 1 & Supervisory control and data acquisition network & 23.221 & 14.876 & 38.097 & 1.56 \ Scenario 2 & Cloud service failure & 722.000 & 1.196 & 1.918 & 0.60 \ Scenario 3 & Health sector and hospitals
& 28.487 & 10.771 & 39.257 & 2.64 \ Scenario 4 & Municipal services & 23.257 & 9.105 & 32.361 & 2.55 \ Scenario 5 & Telecommunications & 1.521 & 1.593 & 3.113 & 0.95 \ Scenario 6 & Cross-sector attack & 34.879 & 37.669 & 72.458 & 0.93 \ \bottomrule \end{tabular} \end{document}

enter image description here


If you allow for line breaks in the column headers, the alignment could be probably improved a bit (thanks to barbara beeton for the hint):

\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage{array, booktabs, siunitx}

\NewDocumentCommand{\headercell}{ O{4.5em} m }{ \begin{tabular}{ @{} >{\centering\arraybackslash}p{#1} @{} } #2 \end{tabular} }

\begin{document} \renewcommand{\arraystretch}{1.25} \begin{tabular}{ @{} l >{\raggedright\arraybackslash}p{9em} *{4}{S[table-format=3.3]} @{} } \toprule & & \multicolumn{4}{c}{Total economic damage (mUS$)} \ \cmidrule{3-6} & Risk Factor & {\headercell{Upstream Losses}} & {\headercell[5.5em]{Downstream Losses}} & {\headercell[3em]{Total Losses}} & {Ratio} \ \midrule Scenario 1 & Supervisory control and data acquisition network & 23.221 & 14.876 & 38.097 & 1.56 \ Scenario 2 & Cloud service failure & 722.000 & 1.196 & 1.918 & 0.60 \ Scenario 3 & Health sector and hospitals
& 28.487 & 10.771 & 39.257 & 2.64 \ Scenario 4 & Municipal services & 23.257 & 9.105 & 32.361 & 2.55 \ Scenario 5 & Telecommunications & 1.521 & 1.593 & 3.113 & 0.95 \ Scenario 6 & Cross-sector attack & 34.879 & 37.669 & 72.458 & 0.93 \ \bottomrule \end{tabular} \end{document}

enter image description here

Here, you could actually indeed also make use of single-cell \multicolumn macros (creating a custom macro in this context requires \NewExpandableDocumentCommand):

\documentclass{article}
\usepackage{array, booktabs, siunitx}

\NewExpandableDocumentCommand{\headercell}{ O{4.5em} m }{ \multicolumn{1}{ >{\centering\arraybackslash}b{#1} }{#2} }

\begin{document} \renewcommand{\arraystretch}{1.25} \begin{tabular}{ @{} l >{\raggedright\arraybackslash}p{9em} *{4}{S[table-format=3.3]} @{} } \toprule & & \multicolumn{4}{c}{Total economic damage (mUS$)} \ \cmidrule{3-6} & Risk Factor & \headercell{Upstream Losses} & \headercell[5.5em]{Downstream Losses} & \headercell[3em]{Total Losses} & {Ratio} \ \midrule Scenario 1 & Supervisory control and data acquisition network & 23.221 & 14.876 & 38.097 & 1.56 \ Scenario 2 & Cloud service failure & 722.000 & 1.196 & 1.918 & 0.60 \ Scenario 3 & Health sector and hospitals
& 28.487 & 10.771 & 39.257 & 2.64 \ Scenario 4 & Municipal services & 23.257 & 9.105 & 32.361 & 2.55 \ Scenario 5 & Telecommunications & 1.521 & 1.593 & 3.113 & 0.95 \ Scenario 6 & Cross-sector attack & 34.879 & 37.669 & 72.458 & 0.93 \ \bottomrule \end{tabular} \end{document}

enter image description here


Finally, an approach using the amazing tabularray package:

\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}

\begin{document} \begin{tblr}{ % define columns Q[em] is like >{\raggedright\arraybackslash}p{9em} colspec = { l Q[9em] *{4}{S[table-format=3.3]} }, % disable siunitx from header rows row{1-2} = {guard}, % colsep to zero in outer columns, @{} in traditional column definition column{1} = {leftsep = 0pt}, column{Z} = {rightsep = 0pt}, % set \arraystretch stretch = 1.25, % set cell 1-3 to multicol cell{1}{3} = {c = 4}{c}, % set vertical alignment of second row to bottom cell{2}{1-Z} = {f}, % set horizontal alignment of header cells of last four columns to center cell{2}{3-Z} = {c} } \toprule & & Total economic damage (mUS$) \ \cmidrule{3-6} & Risk Factor & {Upstream \ Losses} & {Downstream \ Losses} & {Total \ Losses} & Ratio \ \midrule Scenario 1 & Supervisory control and data acquisition network & 23.221 & 14.876 & 38.097 & 1.56 \ Scenario 2 & Cloud service failure & 722.000 & 1.196 & 1.918 & 0.60 \ Scenario 3 & Health sector and hospitals
& 28.487 & 10.771 & 39.257 & 2.64 \ Scenario 4 & Municipal services & 23.257 & 9.105 & 32.361 & 2.55 \ Scenario 5 & Telecommunications & 1.521 & 1.593 & 3.113 & 0.95 \ Scenario 6 & Cross-sector attack & 34.879 & 37.669 & 72.458 & 0.93 \ \bottomrule \end{tblr} \end{document}

enter image description here

  • 1
    If the two-word subheadings ("Upstream Losses", etc.) were allowed two lines, as centered, bottom-aligned paragraphs, those columns could be narrower, allowing column 2 to be wider, and thus both take fewer lines and be more readable. (The hyphenation of "Telecommuni-cations" is particularly unfortunate.) – barbara beeton Mar 31 '23 at 19:19
  • Wow, thank you very much for your detailed answer, Jasper. What do you think would be the best way to spend some hours to get better with tables myself? I mostly relied, as I said, on these "cookie-cutter" table-generator website. Since using latex, the table code/syntax always frightened me :D – rememberthename_ Apr 01 '23 at 07:09
  • @rememberthename_ I have to admit, typesetting tables is not always straightforward. You often need to logically split up the problem into several smaller ones (multi-line, spanning cells, borders, number aligning. ...) which you then can address one after each other. Sadly, if you want to typeset tables in a traditional way, there is not a one-fits-all solution. But you could take a look at the tabularray package. The syntax is a partially bit different, but as far as I can see, this package really covers a huge range of possible aspects concerning tables and offers a lot of flexibility. – Jasper Habicht Apr 01 '23 at 07:32
  • How do you reconcile with the siunitix package that all numbers have the same amout of integers and decimals? In my second row first colum, e.g., the number should be 722 MN but now is 722.000 which would imply 722 BN as my units are MN $ – rememberthename_ Apr 01 '23 at 08:14
  • @rememberthename_ I just added the zeros because I thought that it looked better. Just remove them. The number will then be aligned so that the decimals are aligned to the decimals of the other numbers (ones below ones, tens below tens ...). – Jasper Habicht Apr 01 '23 at 08:20
0

The same tabular as proposed by Jasper Habicht (+1) but constructed with {NiceTabular} of nicematrix.

\documentclass{article}
\usepackage{nicematrix, booktabs, siunitx}

\begin{document} \renewcommand{\arraystretch}{1.25} \begin{NiceTabular}{ @{} l p[l]{9em} *{4}{S[table-format=3.3]} @{} } \toprule & & \Block{1-4}{Total economic damage (mUS$)} \ \cmidrule{3-6} & Risk Factor & \Block[b]{}{Upstream\ Losses} & \Block[b]{}{Downstream\ Losses} & \Block[b]{}{Total\ Losses} & {Ratio} \ \midrule Scenario 1 & Supervisory control and data acquisition network & 23.221 & 14.876 & 38.097 & 1.56 \ Scenario 2 & Cloud service failure & 722.000 & 1.196 & 1.918 & 0.60 \ Scenario 3 & Health sector and hospitals
& 28.487 & 10.771 & 39.257 & 2.64 \ Scenario 4 & Municipal services & 23.257 & 9.105 & 32.361 & 2.55 \ Scenario 5 & Telecommunications & 1.521 & 1.593 & 3.113 & 0.95 \ Scenario 6 & Cross-sector attack & 34.879 & 37.669 & 72.458 & 0.93 \ \bottomrule \end{NiceTabular} \end{document}

Output of the above code

F. Pantigny
  • 40,250