1

I would like to design a table like the one bellow, but I am not proficient enough in Latex and it would take me too long. Can someone help with writing a "mockup" table like this?

enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{multirow}
\usepackage{tabularx,ragged2e,booktabs}


\begin{document}

\begin{table}[h]
    \begin{tabularx}{\textwidth}{X *6{r}}
        \toprule \addlinespace[6pt]
        Statistics &
        \multicolumn{2}{c}{April} &
        \multicolumn{2}{c}{June} \\
        \cmidrule(lr){2-3}
        \cmidrule(lr){4-5}
         & Cumulative Operating Time/h & Average Operating Time/h  & Cumulative Operating Time/h & Average Operating Time/h \\
        \midrule
        Trawler            & 142.87 & 137.72 & 142.87 & 142.87   \\
        Purse-seine             & 102.94 & 190.15 & 142.87 & 142.87 \\
        \addlinespace[3pt]
        \toprule \addlinespace[6pt]
        Statistics &
        \multicolumn{2}{c}{September} &
        \multicolumn{2}{c}{October}\\
        \cmidrule(lr){2-3}
        \cmidrule(lr){4-5}
             & Cumulative Operating Time/h & Average Operating Time/h  & Cumulative Operating Time/h & Average Operating Time/h \\
        \midrule
        Trawler   & -65.76 & -60.18 & 142.87 & 142.87  \\
        Purse seine             &  42.37 &  36.11 & 142.87 & 142.87 \\
        \bottomrule
    \end{tabularx}
    \caption{Statistics of speed, heading and depth for OTB \& PS fishing vessel types}
    \label{table_statistics}
\end{table}

\end{document}

This gives: enter image description here

4
  • Welcome to SE. "Do my work for me" questions aren't allowed. Please show some code, even if imperfect, and people will suggest corrections and enhancements.
    – Miyase
    Commented Jun 20, 2022 at 15:40
  • There's a question about a similar table with the tabularray-based answer.
    – Celdor
    Commented Jun 20, 2022 at 15:57
  • @Celdor Using your proposed solution from the question you are refering to i get overflowing texts (I edited this post so you can see what i mean). Is it possible to have everything in one line like the image i posted above? Commented Jun 20, 2022 at 16:09
  • 1
    I added my answer. While I was working on it, Mico and Bernard already gave you their suggestions so you can choose the best one.
    – Celdor
    Commented Jun 20, 2022 at 17:57

4 Answers 4

3

I can see no need for a tabularray, or even a tabularx, environment. Once you apply some reasonable abbreviations of the bloated header cell material, all 9 columns of the table fit within the width of the textblock. This suggests employing a 9-column tabular* environment.

enter image description here

\documentclass{article}
\usepackage[flushleft]{threeparttable}
\usepackage{booktabs,siunitx}
\newcommand\mc[1]{\multicolumn{2}{c}{#1}} % handy shortcut macro

\begin{document}

\begin{table}[ht!]
\setlength\tabcolsep{0pt}

\begin{threeparttable}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} l *{8}{S[table-format=3.2]} }
    \toprule 
    Statistics 
    & \mc{April} & \mc{June} & \mc{September} & \mc{October}\\
    \cmidrule{2-3} \cmidrule{4-5} \cmidrule{6-7} \cmidrule{8-9}
    & {COT\tnote{a}} & {AOT\tnote{b}} & {COT} & {AOT} & {COT} & {AOT} & {COT} & {AOT} \\
    \midrule
    Trawler      & 142.87 & 137.72 & 142.87 & 142.87 & -65.76 & -60.18 & 142.87 & 142.87 \\
    Purse-seine  & 102.94 & 190.15 & 142.87 & 142.87 &  42.37 &  36.11 & 142.87 & 142.87 \\
    \bottomrule
\end{tabular*}
    
\smallskip\footnotesize
\begin{tablenotes}
  \item[a]COT: Cumulative Operating Time, in hours
  \item[b]AOT: Average Operating Time, in hours
\end{tablenotes}
    
\caption{Statistics of speed, heading and depth for OTB \& PS fishing vessel types}
\label{table_statistics}

\end{threeparttable}
\end{table}

\end{document}
3

In contrary to @Mico, I see some advantages to use tabularray package :-). It define talltblr table, which is an equivalent to threeparttable with difference that tables' notes are written in table preamble. Using them, similar as @Mico done in his answer (+1) ,you can use in column headers abbreviations COT and AOT and tis way make columns narrower.

\documentclass{article}
%\usepackage[xcdraw]{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{booktabs,siunitx}
\NewTableCommand\SCC{\SetCell[c=2]{c}}

\begin{document}
    \begin{table}[ht!]
\begin{talltblr}[
caption = {Statistics of speed, heading and depth for OTB \& PS fishing vessel types},
  label = {table_statistics},
note{a} = {COT: Cumulative Operating Time, in hours},
note{b} = {AOT: Average Operating Time, in hours},
                  ]{colsep = 3pt,
                   colspec = {@{} l *{8}{X[c, si={table-format=3.2}]} @{}},
                  row{1,2} = {guard, c}
                    }
    \toprule
\SetCell[r=2]{l}    Statistic 
1   &\SCC   April 
        &   &\SCC   June
                &   &\SCC   September
                        &   &\SCC   October
                                & 8 \\
    \cmidrule[lr]{2-3} \cmidrule[lr]{4-5}
    \cmidrule[lr]{6-7} \cmidrule[lr]{8-9}
    & COT\TblrNote{a}   & AOT\TblrNote{b} & COT     & AOT   & COT   & AOT   & COT   & AOT   \\
    \midrule
Trawler      & 142.87   & 137.72 & 142.87 & 142.87  & -65.76 & -60.18 & 142.87 & 142.87 \\
Purse-seine  & 102.94   & 190.15 & 142.87 & 142.87  &  42.37 &  36.11 & 142.87 & 142.87 \\
    \bottomrule
\end{talltblr}
    \end{table}
\end{document}

enter image description here

2
  • +1. :-) When I wrote "I can see no need for...", I was referring to the fact that automatic line breaking is not needed in any of the table's columns. That's why I went with a tabular* envrionment instead, as it requires far fewer computation cycles to finish than a tabularx environment does.
    – Mico
    Commented Jun 20, 2022 at 19:28
  • 1
    @Mico, Unfortunately, computation time is quite serious drawback of tabutarray. It is even longer as it is at tabularx. "Classic" tables will be attractive for a long time to come.
    – Zarko
    Commented Jun 20, 2022 at 19:37
1

enter image description hereThis is quite easy with the \thead command from makecell, which enables you to have line breaks in standard columns:

\documentclass{article}
\usepackage{multirow}
\usepackage{tabularx,ragged2e,booktabs}
\usepackage{makecell}
\renewcommand{\theadfont}{\normalsize\bfseries}

\begin{document}

\begin{table}[h]
    \begin{tabularx}{\textwidth}{X *6{r}}
        \toprule \addlinespace[6pt]
        \bfseries Statistics &
        \multicolumn{2}{c}{\bfseries April} &
        \multicolumn{2}{c}{\bfseries June} \\
        \cmidrule(lr){2-3}
        \cmidrule(lr){4-5}
         & \thead{Cumulative\\ Operating\\ Time/h} & \thead{Average\\ Operating\\ Time/h} & \thead{Cumulative\\ Operating\\ Time/h} & \thead{Average\\ Operating\\ Time/h} \\
        \midrule
        Trawler & 142.87 & 137.72 & 142.87 & 142.87 \\
        Purse-seine & 102.94 & 190.15 & 142.87 & 142.87 \\
        \addlinespace[3pt]
        \toprule \addlinespace[6pt]
        \bfseries Statistics &
        \multicolumn{2}{c}{\bfseries September} &
        \multicolumn{2}{c}{\bfseries October}\\
        \cmidrule(lr){2-3}
        \cmidrule(lr){4-5}
             & \thead{Cumulative\\ Operating\\ Time/h} & \thead{Average\\ Operating\\ Time/h} & \thead{Cumulative\\ Operating\\ Time /h} & \thead{Average\\ Operating\\ Time/h} \\
        \midrule
        Trawler & -65.76 & -60.18 & 142.87 & 142.87 \\
        Purse seine & 42.37 & 36.11 & 142.87 & 142.87 \\
        \bottomrule
    \end{tabularx}
    \caption{Statistics of speed, heading and depth for OTB \& PS fishing vessel types}
    \label{table_statistics}
\end{table}

\end{document} 
1

The problem with your table is the content; there is not enough space for that long headers. You can clearly see that! Also, a number of columns in definition must match a number of columns in the data.

There are two solutions. First, you could vertically split the long expressions usually by "inner tabulars" (see the code). Another option is to use a \makecell{} from a package makecell. Even though now the table fits the page, it is IMO not well balanced unless you have more data to add.

The other solution, which I think is slightly better, and the one you used in other question, is to use shorter texts or even use acronyms and add annotations at the bottom of the table

enter image description here

The code

\documentclass{article}
\usepackage{tabularx,booktabs}

\newcommand\tabcell[1]{\begin{tabular}{c}#1\end{tabular}}


\begin{document}
\begin{table}[htb]
    \centering

    \begingroup
        \small
        \begin{tabularx}{\textwidth}{X *4{c}}
            \toprule \addlinespace[6pt]
            Statistics & \multicolumn{2}{c}{April} & \multicolumn{2}{c}{June} \\
            \cmidrule(lr){2-3} \cmidrule(lr){4-5}
            &
            \tabcell{Cumulative\\Operating\\Time/h} &
            \tabcell{Average\\Operating\\Time/h} &
            \tabcell{Cumulative\\Operating\\Time/h} &
            \tabcell{Average\\Operating\\Time/h} \\
            \midrule
            Trawler     & 142.87 & 137.72 & 142.87 & 142.87 \\
            Purse-seine & 102.94 & 190.15 & 142.87 & 142.87\\
            \addlinespace[3pt]
            \toprule \addlinespace[6pt]
            Statistics & \multicolumn{2}{c}{September} & \multicolumn{2}{c}{October} \\
            \cmidrule(lr){2-3} \cmidrule(lr){4-5}
            &
            \tabcell{Cumulative\\Operating\\Time/h} &
            \tabcell{Average\\Operating\\Time/h} &
            \tabcell{Cumulative\\Operating\\Time/h} &
            \tabcell{Average\\Operating\\Time/h} \\
            \midrule
            Trawler     & -65.76 & -60.18 & 142.87 & 142.87 \\
            Purse seine &  42.37 &  36.11 & 142.87 & 142.87 \\
            \bottomrule
        \end{tabularx}
        \caption{Statistics of speed, heading and depth for OTB \& PS fishing vessel types}
        \label{table_statistics}
    \endgroup
    
    \bigskip X \dotfill{} X\bigskip
    
    \begin{tabularx}{0.7\linewidth}{X *4{c}}
        \toprule \addlinespace[6pt]
        Statistics & \multicolumn{2}{c}{April} & \multicolumn{2}{c}{June} \\
        \cmidrule(lr){2-3} \cmidrule(lr){4-5}
        & COT & AOT & COT & AOT \\
        \midrule
        Trawler     & 142.87 & 137.72 & 142.87 & 142.87 \\
        Purse-seine & 102.94 & 190.15 & 142.87 & 142.87\\
        \addlinespace[3pt]
        \toprule \addlinespace[6pt]
        Statistics & \multicolumn{2}{c}{September} & \multicolumn{2}{c}{October} \\
        \cmidrule(lr){2-3} \cmidrule(lr){4-5}
        & COT & AOT & COT & AOT \\
        \midrule
        Trawler     & -65.76 & -60.18 & 142.87 & 142.87 \\
        Purse seine &  42.37 &  36.11 & 142.87 & 142.87 \\
        \bottomrule
        \addlinespace[3pt]
        \multicolumn{5}{@{}l}{COT: Cumulative Operating Time/h} \\
        \multicolumn{5}{@{}l}{AOT: Average Operating Time/h} \\
    \end{tabularx}
    \caption{Statistics of speed, heading and depth for OTB \& PS fishing vessel types}
    \label{table_statistics2}
\end{table}

\end{document}

You must log in to answer this question.

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