2

I am unable to space my table headers as expected in LaTeX.

My table is supposed to look like this:

How the table is supposed to look

But unfortunately it is showing up in the document like this:

enter image description here

Where it is not fitting the page's width, and the header's labels, such as "Number of recommended items" is taking over a single line on the table thus taking a lot of space. Part of the solution would be increasing the header's height.

I want to reduce as much whitespace as possible on the table to make it legible and fit the page.

Here is the code:

%Please add the following packages if necessary:
%\usepackage{booktabs, multirow} % for borders and merged ranges
%\usepackage{soul}% for underlines
%\usepackage[table]{xcolor} % for cell colors
%\usepackage{changepage,threeparttable} % for wide tables
%If the table is too wide, replace \begin{table}[!htp]...\end{table} with
%\begin{adjustwidth}{-2.5 cm}{-2.5 cm}\centering\begin{threeparttable}[!htb]...\end{threeparttable}\end{adjustwidth}
\begin{table}[!htp]\centering
\caption{Generated by Spread-LaTeX}\label{tab: }
\scriptsize
\begin{tabular}{lrrrrrrrr}\toprule
Execution environment &Number of recommended items &Dataset size &Total API endpoint execution time (seconds) &Endpoint execution latency &Recommendation execution &Data processing time (seconds) &Recommender algorithm execution time (seconds) \\\midrule
Local (API) &3 &20000263 &50.05549 &0.01421 &50.04128 &46.52477 &3.51651 \\
Local (Algorithm only) &3 &20000263 & & &53.21693 &48.71163 &4.50530 \\
Heroku (API) &3 &20000263 &MEMORY OVERFLOW & & & & \\
PAW (API) &3 &20000263 &MEMORY OVERFLOW & & & & \\
Local (API) &5 &20000263 &48.26075 &0.00957 &48.25118 &44.64684 &3.60434 \\
Local (Algorithm only) &5 &20000263 & & &64.97844 &60.10595 &4.87248 \\
Heroku (API) &5 &20000263 &MEMORY OVERFLOW & & & & \\
PAW (API) &5 &20000263 &MEMORY OVERFLOW & & & & \\
Local (API) &10 &20000263 &43.31767 &0.01661 &43.30106 &39.85879 &3.44227 \\
Local (Algorithm only) &10 &20000263 & & &44.16319 &40.60699 &3.55620 \\
Heroku (API) &10 &20000263 &MEMORY OVERFLOW & & & & \\
PAW (API) &10 &20000263 &MEMORY OVERFLOW & & & & \\
\multicolumn{1}{c}{AVERAGE} &45.78921 &0.01309 &50.78216 &46.78604 &3.99612 \\
& &STDV &3.4952824449691047 &0.00497738403016791 &8.855024886265406 &8.2442634610736 &0.6482773532436392 \\
\bottomrule
\end{tabular}
\end{table}

Thank you

4
  • 2
    You cannot have break lines in l, r, and c columns, but you can do it with p columns (e.g., p{5cm}) and with the tabulary package to use L,C, R,J columns and tabularx package to use X columns. There are a lot of examples of use if these packages in this site. See also thee manual of these packages and package array (run texdoc array). Said that, nothing can fix a very bad table design except redesign the table (rounded numbers, shoter headers, traspose row by columns, etc..) .
    – Fran
    Aug 8 at 4:35
  • 1
    On the other hand, the fix depend largely of the page dimensions and margins, so post a mininal but complete (compilable) example, not a chunk of code where is impossible reproduce your problem properly.
    – Fran
    Aug 8 at 4:38
  • Welcome to TeX.SE!
    – Zarko
    Aug 8 at 7:22
  • The makecell package allows manual line breaks in standard columns with it \thead and \makecell commands.
    – Bernard
    Aug 8 at 8:46

2 Answers 2

3

You can fit the table even in the standard LaTeX layout but you would have to get rid of those wordy headings and long numbers. For instance, I substituted headings with some symbols and added explanation of what each of the symbols represents at the bottom of the table. I don't think you need 15 decimal places. Finally, data size seems to be the same for each execution environment and I'd move it to somewhere else (annotation or title) to avoid repetition.

One way to put everything together is to use threeparttable. It can help with splitting a table environment into three parts: caption, the table itself and annotation. siunitx rounds long numbers to only a few decimal places; you can still keep the numbers in the table and work out the best option for you.

enter image description here

\documentclass{article}
\usepackage{mathtools}
\usepackage{threeparttable}
\usepackage{booktabs}
\usepackage{siunitx}

\sisetup{
    round-mode = places,
    round-precision = 2,
    minimum-decimal-digits = 1,
}

\begin{document}
\begin{table}[!htp]\centering
    \small
    \begin{threeparttable}
        \caption{Generated by Spread-LaTeX}
        \label{tab: }
        \begin{tabular}{
            l
            r
            S[table-format=2.1, round-precision = 1]
            S[table-format=1.3, round-precision = 4]
            *2{S[table-format=2.1, round-precision = 1]}
            S[table-format=1.2, round-precision = 2]
        }
        \toprule
            $E$\textsubscript{ENV}\tnote{1}
                & $N$\textsubscript{REC}\tnote{2}   % etc.
                & {$T$\tnote{3}}
                & {$L$\tnote{4}}
                & {$R$\tnote{5}}
                & {$P$\tnote{6}}
                & {$A$\tnote{7}} \\
            \midrule
            Local (API)            &  3 & 50.05549 &  0.01421 & 50.04128 & 46.52477 & 3.51651 \\
            Local (Algorithm only) &  3 &     {--} &     {--} & 53.21693 & 48.71163 & 4.50530 \\
            Heroku (API)           &  3 &     {MO} &     {--} &     {--} &     {--} &    {--} \\
            PAW (API)              &  3 &     {MO} &     {--} &     {--} &     {--} &    {--} \\
            Local (API)            &  5 & 48.26075 &  0.00957 & 48.25118 & 44.64684 & 3.60434 \\
            Local (Algorithm only) &  5 &     {--} &     {--} & 64.97844 & 60.10595 & 4.87248 \\
            Heroku (API)           &  5 &     {MO} &     {--} &     {--} &     {--} &    {--} \\
            PAW (API)              &  5 &     {MO} &     {--} &     {--} &     {--} &    {--} \\
            Local (API)            & 10 & 43.31767 &  0.01661 & 43.30106 & 39.85879 & 3.44227 \\
            Local (Algorithm only) & 10 &     {--} &     {--} & 44.16319 & 40.60699 & 3.55620 \\
            Heroku (API)           & 10 &     {MO} &     {--} &     {--} &     {--} &    {--} \\
            PAW (API)              & 10 &     {MO} &     {--} &     {--} &     {--} &    {--} \\
            \midrule[\cmidrulewidth]
            \multicolumn{2}{r}{AVERAGE} & 45.78921 & 0.01309  & 50.78216 & 46.78604 &  3.99612 \\
               \multicolumn{2}{r}{STDV} &  3.4952824449691047 &  0.00497738403016791 &  8.855024886265406 & 8.2442634610736 & 0.6482773532436392 \\
            \bottomrule
        \end{tabular}
        Data size: \num[minimum-decimal-digits=0,round-precision=0]{20000263},\quad
        MO: Memory Overflow\par
        \medskip
        \tnote{1}~Execution environment,\quad%
        \tnote{2}~Number of recommended items,\quad%
        \tnote{3}~Total API endpoint execution time (seconds),\quad%
        \tnote{4}~Endpoint execution latency,\quad%
        \tnote{5}~Recommendation execution,\quad%
        \tnote{6}~Data processing time (seconds),\quad%
        \tnote{7}~Recommender algorithm execution time (seconds)
    \end{threeparttable}
\end{table}

\end{document}
2
  • a nice answer by @Celdor
    – js bibra
    Aug 8 at 10:59
  • Thank you for your answer. Aug 10 at 3:24
0

Welcome, I have a a start for you

\documentclass[12pt, A4]{article}
\usepackage[utf8]{inputenc}
\usepackage{fourier} 
\usepackage{array}
\usepackage{makecell}
\usepackage{adjustbox}

\renewcommand\theadalign{bc}
\renewcommand\theadfont{\bfseries}
\renewcommand\theadgape{\Gape[4pt]}
\renewcommand\cellgape{\Gape[4pt]}

\begin{document}

\setlength\extrarowheight{3pt}

\begin{table}[ht]
\centering
\begin{adjustbox}{width=1\textwidth}
\small

\begin{tabular}{|c|clc|c|c|c|c|c|}
\hline
\thead{Execution \\ environment} & \thead{Number of \\ recomended  items} & \thead{Data size} & \thead{Total endpoint} & \thead{execution  time\\ (seconds)} &  \thead{Endpoint execution} & \thead{Data processing  \\time} & \thead{Recommender \\ Algorith time \\ (seconds)} \\ \hline
Local (API) &3 &20000263 &50.05549 &0.01421 &50.04128 &46.52477  &3.51651 \\
Local (Algorithm only) &3 &20000263 & & &53.21693 &48.71163 &4.50530  \\
Heroku (API) &3 &20000263 &MEMORY OVERFLOW & & & & \\
PAW (API) &3 &20000263 &MEMORY OVERFLOW & & & & \\
Local (API) &5 &20000263 &48.26075 &0.00957 &48.25118 &44.64684  &3.60434 \\
Local (Algorithm only) &5 &20000263 & & &64.97844 &60.10595 &4.87248  \\
Heroku (API) &5 &20000263 &MEMORY OVERFLOW & & & & \\
PAW (API) &5 &20000263 &MEMORY OVERFLOW & & & & \\
Local (API) &10 &20000263 &43.31767 &0.01661 &43.30106 &39.85879  &3.44227 \\
Local (Algorithm only) &10 &20000263 & & &44.16319 &40.60699 &3.55620  \\
Heroku (API) &10 &20000263 &MEMORY OVERFLOW & & & & \\
PAW (API) &10 &20000263 &MEMORY OVERFLOW & & & & \\
\multicolumn{1}{c}{AVERAGE} &45.78921 &0.01309 &50.78216 &46.78604  &3.99612 \\
& &STDV &3.4952824449691047 &0.00497738403016791 &8.855024886265406  &8.2442634610736 &0.6482773532436392 \\
    \hline
    \end{tabular}
    \end{adjustbox}

        \end{table} 

        \end{document}

There is a few extra line of code not needed but I just used an old table of mine, hope it can help.

1
  • Thank you for your answer. Aug 10 at 3:24

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.