将表格标题居中放置,而无需将表格扩展到一列

将表格标题居中放置,而无需将表格扩展到一列
\documentclass{article}
\usepackage{booktabs}

\begin{document}

\begin{table}[htbp]
\centering
\caption{The output of the cross-validation used for the hyperparameters optimization}
\label{table:hyper} 
\begin{tabular}{ p{2.2cm} p{3.5cm} p{2cm} }
  \toprule
    Hyperparameters           & \textbf{Values}                  & \textbf{Selected Values}       \\ 
  \midrule
    N\underline {o} of layers & 2,3,4,5,6,7,8                    & 2 – both encoding and decoding \\
    Neurons in each laye      & 80,70,60,50,45,40,30,25,20,15,10 & 70,50,30                       \\
    Dimensions for coding     & 80,70,60,50,45,40,30,25,20,15,10 & 45,25                          \\
    Sparsity                  & 10e-5,10e-3,10e-1                & 10e-5                          \\
    Activation function       & Relu, Sigmoid                    & Relu, Sigmoid                  \\
    Optimizer                 & Default                          & adadelta                       \\ 
  \bottomrule
\end{tabular} 
\end{table}

\end{document}

在此处输入图片描述

答案1

对于有限的范围(此处,在表格内),我使逗号处于活动状态并将其定义为

\def,{\char`,\allowbreak}

这样,它就可以允许中断。我还稍微加宽了左列,并将第 1 列和第 3 列\raggedright也设为了。最后,我添加了一些\arraystretch来分隔行。

\documentclass{article}
\usepackage{booktabs,array}

\begin{document}

\begin{table}[htbp]
\centering
\caption{The output of the cross-validation used for the hyperparameters optimization}
\label{table:hyper} 
\catcode`,=\active
\def,{\char`,\allowbreak}
\renewcommand\arraystretch{1.2}
\begin{tabular}{p{2.4cm}<{\raggedright} p{3.5cm} p{2cm}<{\raggedright} }
  \toprule
    Hyperparameters           & \textbf{Values}                  & \textbf{Selected Values}       \\ 
  \midrule
    N\underline {o} of layers & 2,3,4,5,6,7,8                    & 2 – both encoding and decoding \\
    Neurons in each layer      & 80,70,60,50,45,40,30,25,20,15,10 & 70,50,30                       \\
    Dimensions for coding     & 80,70,60,50,45,40,30,25,20,15,10 & 45,25                          \\
    Sparsity                  & 10e-5,10e-3,10e-1                & 10e-5                          \\
    Activation function       & Relu, Sigmoid                    & Relu, Sigmoid                  \\
    Optimizer                 & Default                          & adadelta                       \\ 
  \bottomrule
\end{tabular} 
\end{table}

\end{document}

在此处输入图片描述

相关内容