使表格适合文本

使表格适合文本

我制作了一个表格,但遇到了以下问题:它不适合文本宽度。我尝试使用 \adjustbox 和 \tabularx 修复它,但都没有成功(它变得太小,几乎无法阅读)。我想知道是否还有其他选择可以让表格看起来更好。我在这里留下我的代码及其结果:

\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}

在此处输入图片描述

非常感谢!!

答案1

您需要将单元格中的长文本分成多行:

\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}

在此处输入图片描述

答案2

您可能可以允许在表格单元格内进行换行。

除此之外您还可以旋转太宽的表格。

\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}

在此处输入图片描述

在此处输入图片描述

相关内容