使表格適合文本

使表格適合文本

我製作了一個表格,但有以下問題:它不適合文字寬度。我嘗試用​​ \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}

在此輸入影像描述

在此輸入影像描述

相關內容