为什么其中有一列太宽?

为什么其中有一列太宽?

为什么最后一列太宽了?

    \begin{table}[!h]
\caption{Total times in second and number of sub-problems of  Algorithm 1,2 and 3}
 \label{table2}
\centering
\begin{tabular}{|c|c|c|c|c|}
\hline
Name  &  Al & Cycle & TTs &  NSP\\
\hline
 P1    &  1  & $(1,2,3,4,5)$ & 3.1 &3\\
   \hline
P2 &  2 &  (1,15,7,5,12)  & 17 & 11 \\
   \hline
  P2 &  3 & $ (1,15,7,5,12)$  $(2,9,13,14,8)$ & 97& 36  \\
   \hline
P3 &  2 & $(1,7,12,16,19,21,6)$, & 15&14\\
 \hline
P4 & 2 &   $(11,28,29,38,44,25,20,37)$ &335& 36\\
 \hline
P4 & 3 &   \shortstack{ $(11,28,29,38,44,25,20,37)$,\\   $(18,33,34,24,40,36,41,39)$} &  566 & 91\\
 \hline
  \multicolumn{5}{@{}l@{}}{ Al: Algorithm; NSP: Number of sub-problems; TTs: Total time in second.}\\
\end{tabular}
\end{table}

在此处输入图片描述

答案1

我建议你使用一个threeparttable环境,以及它的\tnote指令和tablenotes环境来强制标题脚注材料与环境占据相同的宽度tabular

在此处输入图片描述

\documentclass{article}
\usepackage{stackrel,array}
\usepackage[flushleft,para]{threeparttable}
\renewcommand{\TPTtagStyle}{\textit} % optional
\begin{document}
\begin{table}[!h]
\setlength\extrarowheight{2pt} % for a less cramped look
\begin{threeparttable}
\caption{Total times in second and number of sub-problems of algorithm 1, 2 and 3}
\label{table2}
\centering
\begin{tabular}{|c|c|c|c|c|}
\hline
Name  &  Al\tnote{a} & Cycle & TTs\tnote{b} &  NSP\tnote{c}\\
\hline
 P1 &  1 & $(1,2,3,4,5)$ & 3.1 &3\\
   \hline
 P2 &  2 &  (1,15,7,5,12)  & 17 & 11 \\
   \hline
 P2 &  3 & $ (1,15,7,5,12)$  $(2,9,13,14,8)$ & 97& 36  \\
   \hline
 P3 &  2 & $(1,7,12,16,19,21,6)$, & 15&14\\
   \hline
 P4 & 2 &  $(11,28,29,38,44,25,20,37)$ &335& 36\\
   \hline
 P4 & 3 &  \shortstack{ $(11,28,29,38,44,25,20,37)^{\mathstrut}$,\\   
            $(18,33,34,24,40,36,41,39)$} &  566 & 91\\
 \hline
 \end{tabular}
 
 \smallskip
 \footnotesize
 \begin{tablenotes}
   \item[a] Al: Algorithm
   \item[b] TTs: Total time, in seconds
   \item[c] NSP: Number of sub-problems.
 \end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}

答案2

以下是您可以使用最新版本nicematrix(2022-07-28 的 v 6.12) 执行的操作。

\documentclass{article}
\usepackage{nicematrix,enumitem,caption}

\NiceMatrixOptions{caption-above,notes/para}

\begin{document}

\begin{table}[!h]
\centering
\begin{NiceTabular}{ccccc}%
[ 
  hvlines ,
  caption = { Total times in second and number of sub-problems of  Algorithm 1,2 and 3 } ,
  label = table2 ,
]
Name & Al\tabularnote{Al: Algorithme} & Cycle                                                          &
TTs\tabularnote{TTS: Total time in second} & NSP\tabularnote{NSP: Number of sub-problems} \\ 
P1   & 1  & (1,2,3,4,5)                                                    & 3.1 & 3   \\ 
P2   & 2  & (1,15,7,5,12)                                                  & 17  & 11  \\ 
P2   & 3  & (1,15,7,5,12) (2,9,13,14,8)                                    & 97  & 36  \\ 
P3   & 2  & (1,7,12,16,19,21,6),                                           & 15  & 14  \\ 
P4   & 2  & (11,28,29,38,44,25,20,37)                                      & 335 & 36  \\ 
P4   & 3  & \Block{}{(11,28,29,38,44,25,20,37)\\(18,33,34,24,40,36,41,39)} & 566 & 91  \\ 
\end{NiceTabular}
\end{table}

\end{document}

您需要多次编译(因为nicematrix在后台使用 PGF/Tikz 节点)。

上述代码的输出

答案3

\documentclass{article}
\usepackage{makecell}
\begin{document}

\begin{table}[!h]
\caption{Total times in second and number of sub-problems of  Algorithm 1,2 and 3}
\label{table2}
\centering
\begin{tabular}{|c|c|c|c|c|}
\hline
Name & Al & Cycle                                                           & TTs & NSP \\ \hline
P1   & 1  & (1,2,3,4,5)                                                     & 3.1 & 3   \\ \hline
P2   & 2  & (1,15,7,5,12)                                                   & 17  & 11  \\ \hline
P2   & 3  & (1,15,7,5,12) (2,9,13,14,8)                                     & 97  & 36  \\ \hline
P3   & 2  & (1,7,12,16,19,21,6),                                            & 15  & 14  \\ \hline
P4   & 2  & (11,28,29,38,44,25,20,37)                                       & 335 & 36  \\ \hline
P4   & 3  & \makecell{(11,28,29,38,44,25,20,37)\\(18,33,34,24,40,36,41,39)} & 566 & 91  \\ \hline
\multicolumn{5}{@{}c@{}}{\makebox[1em]{\parbox{\linewidth}{Al: Algorithm; NSP: Number of sub-problems; TTs: Total time in second.}}} \\
\end{tabular}
\end{table}

\end{document}

在此处输入图片描述

答案4

使用talltblr,相当于threeparttable在包中定义的tabularray

\documentclass{article}
\usepackage[inline]{enumitem}
\usepackage{tabularray}

\begin{document}
    \begin{table}[!h]
    \centering
\begin{talltblr}[
caption = {Total times in second and number of sub-problems of  Algorithm 1,2 and 3},
  label = {table2},
 note{} = {\footnotesize
           \begin{enumerate*}[label=\textsuperscript{\alph*}, itemjoin={{; }}]
           \item    Al: Algorithm
           \item    TTs: Total time, in seconds
           \item    NSP: Number of sub-problems.
           \end{enumerate*}}
                ]{hlines, vlines,
                  colspec = {cc c cc}
                  }  
Name & Al\TblrNote{a} 
        & Cycle 
            & TTs\TblrNote{b}
                & NSP\TblrNote{c}   \\
P1  & 1 & (1,2,3,4,5)
            & 3.1   & 3             \\
P2  & 2 & (1,15,7,5,12)                                                 
            & 17    & 11            \\
P2  & 3 & (1,15,7,5,12) (2,9,13,14,8)                                    
            & 97    & 36            \\
P3  & 2 & (1,7,12,16,19,21,6),                                           
            & 15    & 14            \\
P4  & 2 & (11,28,29,38,44,25,20,37)                                      
            & 335   & 36            \\
P4  & 3 & {(11,28,29,38,44,25,20,37)\\
           (18,33,34,24,40,36,41,39)}
            & 566   & 91            \\
\end{talltblr}
    \end{table}
\end{document}

在此处输入图片描述

相关内容