如何调整此表格以防止文本进入下一个单元格

如何调整此表格以防止文本进入下一个单元格
\begin{table}[htbp]

    \caption{Experimental Set}
    \label{par1}
    \centering
    \begin{adjustbox}{width=1\textwidth}

    \begin{tabular}{ |p{2.5cm}|p{3cm}|p{2cm}|p{3cm}|
                      p{2cm}|p{3cm}|p{2cm}|p{2cm}|} 
        \hline
         {Experiments} & {No. Of Activities} &  {No. Of Resources} &  
         {No. Of Skills } &{Max. No. of Pred. \& Succ.} &{Task Duration} &
         {Max.Resources per Skill} & {Max.Resources per Task} \\
        \hline
        {Experiment 1} & {15} & 10& 4& 3,3&1-10&3&10 \\  \hline
         Experiment 2 & 30 &10&4&3,3&1-10&3&10 \\ \hline
         Experiment 3& 15 &15&4&3,3&1-10&3&10 \\ \hline 
        {Experiment 4} & {15} & 10& 2& 3,3&1-10&3&10 \\  \hline
        {Experiment 5} & {15} & 10& 4& 2,2&1-10&3&10 \\  \hline
        {Experiment 6} & {15} & 10& 4& 3,3&1-15&3&10 \\  \hline
        {Experiment 7} & {15} & 10& 4& 3,3&1-10&1&10 \\  \hline
        {Experiment 8} & {15} & 10& 4& 3,3&1-10&3&5 \\  \hline

    \end{tabular}
\end{adjustbox}
\end{table}

答案1

您的餐桌是远的太大了。真的。看看此主题一些选项。

使用adjustboxresizebox类似的东西来让表格适合页面是一个非常糟糕的想法,整个东西看起来会很奇怪,因为字体太小了。通常你会发现比重新缩放表格更好的方法。

为了回答这个问题,我彻底修改了你的表格。我注意到你有一个类似“参考”实验的东西,然后你在每个实验中更改一个参数。很抱歉,但你的表格并没有向读者展示这一点,它只是抛出了一堆看似随机的数字。

首先,我转置了您的表格,以便使表格如此宽的参数位于单个列中,从而占用的空间减少了大约 7 倍 (!)。

然后我删除了所有保持不变的参数,并用一个\same命令替换它们,我将其定义为---,但您可以将其更改为任何您喜欢的。

最后,我删除了表格的垂直规则,因为它们看起来很奇怪。

该表现在如下所示:

enter image description here

代码:

\documentclass{article}

\usepackage{booktabs}

\newcommand\same{---}

\begin{document}

\begin{table}
  \caption{Experimental Set}
  \label{par1}
  \centering
  \begin{tabular}{l *{8}{c}}
  \toprule
    & \multicolumn{8}{c}{Experiment}\\
  \cmidrule{2-9}
                               & 1     & 2     & 3     & 4     & 5     & 6     & 7     & 8     \\
  \midrule
    No. of Activities          & 15    & 30    & \same & \same & \same & \same & \same & \same \\
    No. of Resources           & 10    & \same & 15    & \same & \same & \same & \same & \same \\
    No. of Skills              & 4     & \same & \same & 2     & \same & \same & \same & \same \\
    Max. No. of Pred. \& Succ. & 3,3   & \same & \same & \same & 2,2   & \same & \same & \same \\
    Task Duration              & 1--10 & \same & \same & \same & \same & 1--15 & \same & \same \\
    Max. Resources per Skill   & 3     & \same & \same & \same & \same & \same & 1     & \same \\
    Max. Resources per Task    & 10    & \same & \same & \same & \same & \same & \same & 5     \\
  \bottomrule
  \end{tabular}
\end{table}

\end{document}

答案2

您可以旋转标题:

\documentclass{scrartcl}
\usepackage{graphicx,booktabs}
\newcommand\RB[1]{\rotatebox{90}{#1}}
\begin{document}

\begin{table}[!htbp]
\caption{Experimental Set}\label{par1}
\centering
\begin{tabular}{@{} l *7c @{}} \toprule
Experiments & \RB{No. Of Activities} &  \RB{No. Of Resources} &  
         \RB{No. Of Skills } &\RB{Max. No. of Pred. \& Succ.} &\RB{Task Duration} &
         \RB{Max.Resources per Skill} & \RB{Max.Resources per Task} \\\midrule
Experiment 1 & {15} & 10& 4& 3,3&1-10&3&10 \\  
Experiment 2 & 30 &10&4&3,3&1-10&3&10 \\ 
Experiment 3 & 15 &15&4&3,3&1-10&3&10 \\  
Experiment 4 & {15} & 10& 2& 3,3&1-10&3&10 \\
Experiment 5 & {15} & 10& 4& 2,2&1-10&3&10 \\
Experiment 6 & {15} & 10& 4& 3,3&1-15&3&10 \\
Experiment 7 & {15} & 10& 4& 3,3&1-10&1&10 \\
Experiment 8 & {15} & 10& 4& 3,3&1-10&3&5 \\ 
 \bottomrule
\end{tabular}
\end{table}

\end{document}

enter image description here

答案3

这里有两种不使用adjustbox环境的解决方案。相反,它们使用tabularx环境或tabular*环境。在这两种情况下,表格的宽度都设置为\textwidth。请注意,简化和构造标题材料可以使材料适合文本块的宽度,而无需诉诸adjustbox。对于手头的材料,基于tabularxtabular*的解决方案提供非常相似的输出;您可以选择哪一个

如下面的屏幕截图所示,我还建议您让表格看起来更加开放,主要是通过删除所有垂直线和大多数水平线,并使用包的线条绘制宏来绘制booktabs剩余的必要水平线。

enter image description here

\documentclass{article}
\usepackage[a4paper,margin=2.5cm]{geometry} % choose page parameters suitably
\usepackage[skip=0.333\baselineskip]{caption} % optional
\usepackage{tabularx,booktabs,ragged2e,adjustbox}
\newcolumntype{C}{>{\Centering\arraybackslash}X}
\newcommand\mytab[1]{%
  \smash{\begin{tabular}[t]{@{}c@{}} #1 \end{tabular}}}
\begin{document}

\begin{table}[htbp]

    \caption{OP's original, \texttt{adjustbox}-based solution}
    \label{par1}
    \centering
    \begin{adjustbox}{width=1\textwidth}

    \begin{tabular}{ |p{2.5cm}|p{3cm}|p{2cm}|p{3cm}|
                      p{2cm}|p{3cm}|p{2cm}|p{2cm}|} 
        \hline
         {Experiments} & {No. Of Activities} &  {No. Of Resources} &  
         {No. Of Skills } &{Max. No. of Pred. \& Succ.} &{Task Duration} &
         {Max.Resources per Skill} & {Max.Resources per Task} \\
        \hline
        {Experiment 1} & {15} & 10& 4& 3,3&1-10&3&10 \\  \hline
         Experiment 2 & 30 &10&4&3,3&1-10&3&10 \\ \hline
         Experiment 3& 15 &15&4&3,3&1-10&3&10 \\ \hline 
        {Experiment 4} & {15} & 10& 2& 3,3&1-10&3&10 \\  \hline
        {Experiment 5} & {15} & 10& 4& 2,2&1-10&3&10 \\  \hline
        {Experiment 6} & {15} & 10& 4& 3,3&1-15&3&10 \\  \hline
        {Experiment 7} & {15} & 10& 4& 3,3&1-10&1&10 \\  \hline
        {Experiment 8} & {15} & 10& 4& 3,3&1-10&3&5 \\  \hline

    \end{tabular}
\end{adjustbox}
\end{table}

\begin{table}[htbp]
\caption{Solution based on \texttt{tabularx}} \label{par2}
\begin{tabularx}{\textwidth}{@{} l CCC cc CC @{}}
\toprule
Experiment
& \multicolumn{3}{c}{Number of} 
& \mytab{Max.\ No.\ of\\ Pred.\ \& Succ.}
& \mytab{Task\\ Duration}
& \multicolumn{2}{c@{}}{Max.\ Resources} \\
\cmidrule(lr){2-4} \cmidrule(l){7-8}
& Activities & Resources & Skills &&& per skill & per task\\
\midrule
1 & 15 & 10 & 4 & 3,3 & 1--10 & 3 & 10 \\  
2 & 30 & 10 & 4 & 3,3 & 1--10 & 3 & 10 \\ 
3 & 15 & 15 & 4 & 3,3 & 1--10 & 3 & 10 \\  
4 & 15 & 10 & 2 & 3,3 & 1--10 & 3 & 10 \\ \addlinespace 
5 & 15 & 10 & 4 & 2,2 & 1--10 & 3 & 10 \\  
6 & 15 & 10 & 4 & 3,3 & 1--15 & 3 & 10 \\  
7 & 15 & 10 & 4 & 3,3 & 1--10 & 1 & 10 \\  
8 & 15 & 10 & 4 & 3,3 & 1--10 & 3 &  5 \\ 
\bottomrule
\end{tabularx}

\vspace{0.25in}
%% Now for the tabular*-based solution.
%% Let LaTeX figure out optimal amount of intercolumn whitespace:
\setlength\tabcolsep{0pt} 
\caption{Solution based on \texttt{tabular*}} \label{par3}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} l *{7}{c} }
\toprule
Experiment
& \multicolumn{3}{c}{Number of} 
& \mytab{Max.\ No.\ of\\ Pred.\ \& Succ.}
& \mytab{Task\\ Duration}
& \multicolumn{2}{c@{}}{Max.\ Resources} \\
\cmidrule{2-4} \cmidrule{7-8}
& Activities & Resources & Skills &&& per skill & per task\\
\midrule
1 & 15 & 10 & 4 & 3,3 & 1--10 & 3 & 10 \\  
2 & 30 & 10 & 4 & 3,3 & 1--10 & 3 & 10 \\ 
3 & 15 & 15 & 4 & 3,3 & 1--10 & 3 & 10 \\  
4 & 15 & 10 & 2 & 3,3 & 1--10 & 3 & 10 \\ \addlinespace
5 & 15 & 10 & 4 & 2,2 & 1--10 & 3 & 10 \\  
6 & 15 & 10 & 4 & 3,3 & 1--15 & 3 & 10 \\  
7 & 15 & 10 & 4 & 3,3 & 1--10 & 1 & 10 \\  
8 & 15 & 10 & 4 & 3,3 & 1--10 & 3 &  5 \\ 
\bottomrule
\end{tabular*}
\end{table}

\end{document}

相关内容