0

I made a table but I have the following problem: it does not fit within the text width. I tried to fix it with \adjustbox and \tabularx, both of them without success (it becomes too small and almost unreadable). I was wondering if there is another option to make the tables look better. I leave you here my code and the result of it:

\begin{center}
    \begin{tabular}{ccccc}
    \hline
    Verification & Deterministic Versions Comparison & Expected Outcome & True? & Proof \\
    \hline
    1     & Current allocation vs. Optimized & Optimized - Cheaper allocation & Yes & \euro 411,03M vs. \euro 405,82M \\
    
    2     & Optimized vs. Capacity constrained (no UK-EUR) & Optimized - Cheaper allocation & Yes & \euro 405,82M vs.\euro 406,40M \\
    
    3     & Capacity constrained (no UK-EUR) vs. 70\%-30\% volume split by brewery (no UK-EUR) & Capacity constrained (no UK-EUR) - Cheaper allocation & Yes & \euro 406,40M vs. \euro 407,05M \\
  
    4     & 70\%-30\% volume split by brewery (no UK-EUR) vs. Sustainable version (no UK-EUR) & Sustainable version (no UK-EUR) - Lower transportation costs & Yes & \euro 16,79M vs. \euro 14,40M \\
     \hline
    \end{tabular}
      \caption{Verification of the expected outcomes of the versions of the deterministic model.}
    \end{center}

enter image description here

Thank you very much!!

2 Answers 2

3

You need to break long text in cells into more lines:

\documentclass{article}
\usepackage{geometry}
\usepackage{eurosym}
\usepackage{booktabs, makecell, tabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}

\begin{document}
\begin{table}[ht]
\setcellgapes{3pt}
\makegapedcells
\begin{tabularx}{\linewidth}{@{}cLLcL@{}}
\toprule
Ver. & Deterministic Versions Comparison & Expected Outcome & True? & Proof \\
\midrule
1     & Current allocation vs. Optimized & Optimized - Cheaper allocation & Yes & \euro 411,03M vs. \euro 405,82M \\

2     & Optimized vs. Capacity constrained (no UK-EUR) & Optimized - Cheaper allocation & Yes & \euro 405,82M vs.\euro 406,40M \\

3     & Capacity constrained (no UK-EUR) vs. 70\%-30\% volume split by brewery (no UK-EUR) & Capacity constrained (no UK-EUR) - Cheaper allocation & Yes & \euro 406,40M vs. \euro 407,05M \\

4     & 70\%-30\% volume split by brewery (no UK-EUR) vs. Sustainable version (no UK-EUR) & Sustainable version (no UK-EUR) - Lower transportation costs & Yes & \euro 16,79M vs. \euro 14,40M \\
 \bottomrule
\end{tabularx}
  \caption{Verification of the expected outcomes of the versions of the deterministic model. Ver. is abbreviation for Verification.}
\end{table}
\end{document}

enter image description here

3
  • this works extremely well. Really nice layout! The only problem I have is that the table starts on the following page. I tried to substitute table by longtable, but this does not seem to work. How could I solve this problem? Commented Sep 1, 2020 at 7:04
  • @MaxLombaVrouenraets, I forgot to add table placement [ht] (now added). From your comment follows, that your table is very large or for it is enough place, where is inserted. If table is still shorter than on page, it is sensible that it float to the top of the next page If you like to have as long table, over two pages, the package xltabular is appropriate for such tables.
    – Zarko
    Commented Sep 1, 2020 at 7:11
  • I would like my table to start just after the text (see picture of my question). As you can see, it is almost the end of the page, and consequently, the table would need to split into two pages. I tried xltabular but my document does not recompile anymore.. Commented Sep 1, 2020 at 7:26
0

You can probably allow line-breaking within the table-cells themselves.

Besides this you can probably rotate tables that are too wide.

\documentclass{article}
\usepackage{microtype}
\usepackage{graphicx}%
\usepackage[official]{eurosym}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{array}
\usepackage{varwidth}
\newsavebox\tablebox

\newcolumntype{L}[1]{%
  >{%
     \raggedright
     \hsize=#1\hsize
     \begin{varwidth}[t]{\hsize}%
     \narrowragged
     \hyphenpenalty=50
     \exhyphenpenalty=50
     \doublehyphendemerits=50
     \let\newline\\%
     \arraybackslash
     \hspace{0pt}%
     \vrule width 0pt height 1.25\ht\strutbox depth 0pt %
   }%
  X%
  <{%
     \vrule width 0pt height 0pt depth \dimexpr1.25\ht\strutbox-\ht\strutbox+\dp\strutbox
     \end{varwidth}%
   }%
}

\newcolumntype{C}[1]{%
  >{%
     \centering
     \hsize=#1\hsize
     \begin{varwidth}[t]{\hsize}%
     \narrowragged
     \hyphenpenalty=50
     \exhyphenpenalty=50
     \doublehyphendemerits=50
     \let\newline\\%
     \arraybackslash
     \hspace{0pt}%
     \vrule width 0pt height 1.25\ht\strutbox depth 0pt %
   }%
  X%
  <{%
     \vrule width 0pt height 0pt depth \dimexpr1.25\ht\strutbox-\ht\strutbox+\dp\strutbox
     \end{varwidth}%
   }%
}

\fboxsep=-\fboxrule

\begin{document}

\noindent text text text text text text text text text\linebreak

\savebox\tablebox{%
   \begin{tabularx}{\textwidth}{@{}C{.6}L{1.5}L{1.4}C{0.55}L{.95}@{}}%
   \toprule
   Veri\-fi\-ca\-tion&Deterministic Versions Comparison&Expected Outcome&True?&Proof\\
   \midrule
   1 & Current allocation vs. Optimized & Optimized~-- Cheaper allocation & Yes & \euro 411,03M vs. \euro 405,82M \\
   2 & Optimized vs. Capacity constrained (no UK-EUR) & Optimized~-- Cheaper allocation & Yes & \euro 405,82M vs. \euro 406,40M \\
   3 & Capacity constrained (no UK-EUR) vs. 70\%-30\% volume split by brewery (no UK-EUR) & Capacity constrained (no UK-EUR)~-- Cheaper allocation & Yes & \euro 406,40M vs. \euro 407,05M \\
   4 & 70\%-30\% volume split by brewery (no UK-EUR) vs. Sustainable version (no UK-EUR) & Sustainable version (no UK-EUR)~-- Lower transportation costs & Yes & \euro 16,79M vs. \euro 14,40M\\
   \bottomrule
   \end{tabularx}%
}%

\begin{table}
%\centering
%\rotatebox[origin=c]{0}{%
   \begin{minipage}{\wd\tablebox}%
   \usebox{\tablebox}%
   \caption{Verification of the expected outcomes of the versions of the deterministic model.}%
   \end{minipage}%
%}%
\end{table}


\newpage

\noindent text text text text text text text text text\linebreak

\savebox\tablebox{%
   \begin{tabularx}{1.25\textwidth}{@{}C{.5}L{1.9}L{1.45}C{0.35}L{.8}@{}}%
   \toprule
   Veri\-fi\-ca\-tion&Deterministic Versions Comparison&Expected Outcome&True?&Proof\\
   \midrule
   1 & Current allocation vs. Optimized & Optimized~-- Cheaper allocation & Yes & \euro 411,03M vs. \euro 405,82M \\
   2 & Optimized vs. Capacity constrained (no UK-EUR) & Optimized~-- Cheaper allocation & Yes & \euro 405,82M vs. \euro 406,40M \\
   3 & Capacity constrained (no UK-EUR) vs. 70\%-30\% volume split by brewery (no UK-EUR) & Capacity constrained (no UK-EUR)~-- Cheaper allocation & Yes & \euro 406,40M vs. \euro 407,05M \\
   4 & 70\%-30\% volume split by brewery (no UK-EUR) vs. Sustainable version (no UK-EUR) & Sustainable version (no UK-EUR)~-- Lower transportation costs & Yes & \euro 16,79M vs. \euro 14,40M\\
   \bottomrule
   \end{tabularx}%
}%

\begin{table}
\centering
\rotatebox[origin=c]{90}{%
   \begin{minipage}{\wd\tablebox}%
   \usebox{\tablebox}%
   \caption{Verification of the expected outcomes of the versions of the deterministic model.}%
   \end{minipage}%
}%
\end{table}


\end{document}

enter image description here

enter image description here

2
  • Thank you for your reply! Since I have made other tables in my document and I already used the \newcolumntype{L}[1], it will affect the layout of my other tables. I was wondering how can I avoid this. Commented Sep 1, 2020 at 7:39
  • @MaxLombaVrouenraets If the name "L" is already in use for some column-type, then instead of "L" choose another name for the to be defined new column-type. A name which is not already in use. Of course you need to ensure to use the new column-name within table-column-declarations/\multicolumn-commands where columns of this type are used, too. Commented Sep 1, 2020 at 22:53

You must log in to answer this question.

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