1

I am trying to create the following table in latex:

enter image description here

I am having a problem fitting this table to an A4 page. My idea was to make the text wrap in the column headers but after having searched for over an hour online and having seen many solutions, I have not been able to make it work.

This is the latex code I have right now (N.B. I have cut all but the first two rows to reduce the amount of code for readablity.


\documentclass[a4paper, oneside]{discothesis}

\usepackage{tabulary}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{array}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{makecell}
\usepackage{ragged2e}

\begin{document}

\begin{table}[h!]
\setlength\tabcolsep{6pt}
\centering
\caption{Flushing efficiencies.}
\resizebox{\textwidth}{!}{\begin{tabular}{cp{0.082\textwidth} cp{0.082\textwidth} cp{0.082\textwidth} cp{0.082\textwidth} 
cp{0.082\textwidth} cp{0.082\textwidth} cp{0.082\textwidth} cp{0.082\textwidth} cp{0.082\textwidth} cp{0.082\textwidth} cp{0.082\textwidth} cp{0.082\textwidth}}
            
        \toprule
        \multirow{2}{*}{\makecell{Loca- \\ tion}} & \multirow{2}{*}{\makecell{Reser- \\ voir}} & 
\multirow{2}{*}{\makecell{Flushing \\ type}} & \multirow{2}{*}{\makecell{Flushing \\ Year(s)}} & 
\multirow{2}{*}{\makecell{$V_{s,out}$ \\ $[m^3]$}} & \multirow{2}{*}{$V_{w,out} [m^3]$} & 
\multirow{2}{*}{\makecell{Volumetric \\ mixture \\ concentra- \\ tion $\sigma$ \\ $[ml/l]$}} & 
\multirow{2}{*}{Mean volumetric mixture concentration $\sigma_{,m} [ml/l]$} & \multirow{2}{*}{$V_{s,m,out} (FL) [m^3/a]$} & \multirow{2}{*}{$MAS (=V_{s,m,in}) [10^3 m^3/a]$} & 
\multicolumn{2}{*}{Flushing efficiencies $\eta_{f} [\%]$} \\
        
          &   &   &   &   &   &   &   &   &   & $\eta_{\sigma}$ & $\eta_v$ \\
        
        \multirow{5}{*}{CH} & \multirow{5}{*}{Ferden} & E   & 2018  &  96,000  &  2,285,000  & 42.01 & \multirow{5}{*}{47.97} & \multirow{5}{*}{112,667} & \multirow{5}{*}{50} & 4.20  & \multirow{5}{*}{225.3} \\
              &       & E     & 2016  &       120,000  & 4,030,000  & 29.78 &       &       &       & 2.98  &  \\
              &       & E     & 2014  &         60,000  &  2,803,000  & 21.41 &       &       &       & 2.14  &  \\
              &       & E     & 2013  &       160,000  &   3,796,000  & 42.15 &       &       &       & 4.22  &  \\
              &       & E     & 2012  &       240,000  &   2,297,000  & 104.48 &       &       &       & 10.45 &  \\

        \bottomrule
        \end{tabular}}
  \label{tab3:cp_values}
\end{table}

\end{document}

Right now, it gives me the following table (for some reason the \eta_sigma and \eta_v get pushed to the very right instead of being placed under the "flushing efficiencies"-cell):

enter image description here

Also, as you can see, the multirows with E's in them get pushed up into the column headers.

Thank you!

Edit 1: removed unnecessary packages

Edit 2: new table after having removed "c" from cp{0.082\textwidth}

enter image description here

12
  • Welcome to TeX SX! Where can we find the discothesis class file?
    – Bernard
    Jan 3, 2021 at 15:27
  • Thank you. I think it is a custom template. I could post it here in a moment.
    – euler132
    Jan 3, 2021 at 15:29
  • Is there a reason for defining a total of 24 columns while only needing 12?
    – leandriis
    Jan 3, 2021 at 15:30
  • @leandriis Where did I define 24 columns?
    – euler132
    Jan 3, 2021 at 15:34
  • 1
    rather than provide discothesis it would be better to see if you can demonstrate the issue using article class (and simplify the example by removing every package not used in the example (which is almost all the packages you list) Jan 3, 2021 at 15:49

2 Answers 2

1

In the following table, I combined column 1 and 2 into a single column to save some space. Additionally, I also removed lengthy explanatory text from the column headers and placed it below the table. For the units and in order to improve the alignment of numbers inside of the columns, I used siunitx. Lastly, and since the table was still too wide for a portrait oriented page, I used landscape from the pdflscape package.

Since the originally used documentclass was not avialable, I used a regular article in combination with geometry for smaller margins. Depending on the actual size of your textblock and the font and font size in your document, you might need to so some further adjustments in order to make sure, the table fits into the available space.

enter image description here

\documentclass[a4paper, oneside]{article}
\usepackage{geometry}

\usepackage{multirow}
\usepackage{booktabs}
\usepackage{makecell}


\usepackage{siunitx}
\sisetup{per-mode=symbol}
\usepackage{pdflscape}
\begin{document}
\begin{landscape}
\begin{table}[h!]
\centering
\caption{Flushing efficiencies.}
\begin{tabular}{c 
                c 
                c 
                S[table-format=3] 
                S[table-format=4] 
                S[table-format=3.2]
                c 
                c 
                c 
                S[table-format=2.2] 
                c}
            
  \toprule
  \makecell{Reservior\\ (Location)}  
    & \makecell{Flushing \\ type} 
      & \makecell{Flushing \\ Year(s)} 
        & {\makecell{$V_{s,out}$ \\ {[\SI{E3}{\cubic\m}]}}} 
          & {\makecell{$V_{w,out}$  \\ {[\SI{E3}{\cubic\m}]}}} 
            & {\makecell{$\sigma_{s}$ \\ {[\si{\mL\per\L}]}}} 
              & {\makecell{$\sigma_{s,m}$ \\ {[\si{\mL\per\L}]}}}  
                & \makecell{$V_{s,m,out}$  (FL)\\ {[\si{\cubic\m\per a}]}} 
                  & \makecell{MAS  $(=V_{s,m,in})$\\  {[\SI{E3}{\cubic\m\per a}]}} 
                    & \multicolumn{2}{c}{\makecell{Flushing\\ efficiencies  $\eta_{f}$ {[\si{\percent}]}}} \\
                     \cmidrule{10-11}
        
     &   &   &   &   &   &   &   &   &    {$\eta_{\sigma}$} & {$\eta_v$} \\
     
     \midrule
        
         \multirow{5}{*}{Ferden (CH)} & E   & 2018  &  96  &  2285  & 42.01 & \multirow{5}{*}{47.97} & \multirow{5}{*}{112,667} & \multirow{5}{*}{50} & 4.20  & \multirow{5}{*}{225.3} \\
                     & E     & 2016  &       120  & 4030  & 29.78 &       &       &       & 2.98  &  \\
                     & E     & 2014  &         60  &  2800  & 21.41 &       &       &       & 2.14  &  \\
                     & E     & 2013  &       160  &   3796  & 42.15 &       &       &       & 4.22  &  \\
                     & E     & 2012  &       240  &   2297  & 104.48 &       &       &       & 10.45 &  \\
    \midrule
                     & E     & 2016  &       120  & 4030  & 29.78 &       &       &       & 2.98  &  \\
                     & E     & 2014  &         60  &  2803  & 21.41 &       &       &       & 2.14  &  \\
                     & E     & 2013  &       160  &   3796  & 42.15 &       &       &       & 4.22  &  \\
    \midrule
                     & E     & 2012  &       240  &   2297  & 104.48 &       &       &       & 10.45 &  \\
    \midrule
                     & E     & 2016  &       120  & 4030  & 29.78 &       &       &       & 2.98  &  \\
                     & E     & 2014  &         60  &  2803  & 21.41 &       &       &       & 2.14  &  \\
    \midrule
                     & E     & 2013  &       160  &   3796  & 42.15 &       &       &       & 4.22  &  \\
    \midrule
                     & E     & 2012  &       240  &   2297  & 104.48 &       &       &       & 10.45 &  \\
                     & E     & 2016  &       120  & 4030  & 29.78 &       &       &       & 2.98  &  \\
     \midrule
                     & E     & 2014  &         60  &  2803  & 21.41 &       &       &       & 2.14  &  \\
                     & E     & 2013  &       160  &   3796  & 42.15 &       &       &       & 4.22  &  \\
                     & E     & 2012  &       240  &   2297  & 104.48 &       &       &       & 10.45 &  \\
                     & E     & 2016  &       120  & 4030  & 29.78 &       &       &       & 2.98  &  \\
    \midrule
                     & E     & 2014  &         60  &  2803  & 21.41 &       &       &       & 2.14  &  \\
                     & E     & 2013  &       160  &   3796  & 42.15 &       &       &       & 4.22  &  \\
                     & E     & 2012  &       240  &   2297  & 104.48 &       &       &       & 10.45 &  \\
                     & E     & 2013  &       160  &   3796  & 42.15 &       &       &       & 4.22  &  \\
    \midrule
                     & E     & 2012  &       240  &   2297  & 104.48 &       &       &       & 10.45 &  \\
        \bottomrule
    \multicolumn{11}{l}{\small $\sigma_{s}$ = volumetric mixture concentration,  $\sigma_{sm}$ = mean volumetric mixture concentration}\\
        \end{tabular}
  \label{tab3:cp_values}
\end{table}
\end{landscape}

\end{document}
1
  • Oh, thank you soooo much!!! You are a legend! I will have to look into the siunitx package. Also, I have never seen this \sisetup{}; going to read about it as well. Have a great day!!
    – euler132
    Jan 3, 2021 at 16:35
2

Avoid scaling tables it produces inconsistent font sizes and rule widths, I used \small here (although I don't know your actual text width, I assumed the same as article class A4 paper)

enter image description here

\documentclass[a4paper]{article}

\usepackage{booktabs,makecell}

\begin{document}

\begin{table}\small\centering
\setlength\tabcolsep{1.3pt}
\begin{tabular}{@{}cccrrrrrrrrr@{}}            
        \toprule
\makecell[t]{Loca- \\ tion}&
\makecell[t]{Reser- \\ voir} & 
\makecell[t]{type} &
\makecell[t]{Year} & 
\makecell[t]{$V_{s,\mathrm{out}}$ \\ $[m^3]$} &
$V_{w,\mathrm{out}} [m^3]$ & 
\makecell[t]{$\sigma$ \\ $[ml/l]$} & 
\makecell[t]{$\sigma_{,m}$\\ $[ml/l]$} & 
\makecell[t]{$V_{s,m,\mathrm{out}}$\\ $[m^3/a]$} &
\makecell[t]{$\mathrm{MAS} $\\ $\![10^3\!m^3/\!a]\!$} & 
\makecell[t]{$\eta_{f}$\\ $[\%]$} \\
        
          &   &   &   &   &   &   &   &   &   & $\eta_{\sigma}$ & $\eta_v$ \\
        
       CH & Ferden & E   & 2018  &  96,000  &  2,285,000  & 42.01 & 47.97 & 112,667 & 50 & 4.20  & 225.3 \\
              &       & E     & 2016  &       120,000  & 4,030,000  & 29.78 &       &       &       & 2.98  &  \\
              &       & E     & 2014  &         60,000  &  2,803,000  & 21.41 &       &       &       & 2.14  &  \\
              &       & E     & 2013  &       160,000  &   3,796,000  & 42.15 &       &       &       & 4.22  &  \\
              &       & E     & 2012  &       240,000  &   2,297,000  & 104.48 &       &       &       & 10.45 &  \\

        \bottomrule
        \end{tabular}
  \label{tab3:cp_values}

\raggedright

$\sigma$ = Volumetric mixture concentration

$\sigma_{,m}$ = Mean volumetric  mixture concentration 

$\mathrm{MAS} = V_{s,m,in}$

$\eta_f$ = Flushing efficiencies

\end{table}

\end{document}
2
  • I was going to add that the units would be better set with siunitx but leandriis has done that now already so I'll leave this as is. Jan 3, 2021 at 16:37
  • Thank you very much, David. This is a great solution, too. Also, kudos for the \mathrm{} suggestion. I had always wondered how to improve the subscript text in this way. I will upvote your answer as soon as I have 15 reputation))
    – euler132
    Jan 3, 2021 at 16:40

You must log in to answer this question.

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