【Latex】表格的调整—如何一行内容写满,不换行?(含具体示例)

一、问题描述

这是我的最初表格,不难看出,APm和APl在一行中没有写满,实现了换行。
在这里插入图片描述

\begin{
    
    table*}[ht]
\centering
\setlength{
    
    \tabcolsep}{
    
    15pt}
\begin{
    
    tabular}{
    
    cccccccc}
\hline
& CSAM & STRCSM & Lean-neck & AP & AP50 & AP75 & APs & APm & APl \\
\hline
& \checkmark & \checkmark &  & 0.302 & 0.508 & 0.312 & 0.198 & 0.417 & 0.521 \\
& \checkmark &  & \checkmark & 0.300 & 0.503 & 0.309 & 0.195 & 0.416 & 0.532 \\
& & \checkmark  & \checkmark & 0.302 & 0.504 & 0.311 & 0.189 & 0.427 & 0.561 \\
& \checkmark & \checkmark & \checkmark & 0.306 & 0.513 & 0.317 & 0.203 & 0.427 & 0.544 \\
\hline
\end{
    
    tabular}
\caption{
    
    Detection results with different module combinations.}
\label{
    
    tab:detection_results2}
\end{
    
    table*}

我想转成九列,不要把APm和APl放到下面,最上面用一行表示。

二、问题解决

如果我们想要将表格转换成单行九列的格式,而不是将 APm 和 APl 放在下面,可以按照以下方式修改 LaTeX 表格的代码:

\begin{
    
    table*}[ht]
\centering
\setlength{
    
    \tabcolsep}{
    
    10pt}
\begin{
    
    tabular}{
    
    ccccccccc}
\toprule
CSAM & STRCSM & Lean-neck & $\text{
    
    AP}$ & $\text{
    
    AP}_{
    
    50}$ & $\text{
    
    AP}_{
    
    75}$ & $\text{
    
    AP}_{
    
    \text{
    
    s}}$ & $\text{
    
    AP}_{
    
    \text{
    
    m}}$ & $\text{
    
    AP}_{
    
    \text{
    
    l}}$ \\
\midrule
\checkmark & \checkmark &            & 0.302 & 0.508 & 0.312 & 0.198 & 0.417 & 0.521 \\
\checkmark &            & \checkmark & 0.300 & 0.503 & 0.309 & 0.195 & 0.416 & 0.532 \\
           & \checkmark & \checkmark & 0.302 & 0.504 & 0.311 & 0.189 & 0.427 & 0.561 \\
\checkmark & \checkmark & \checkmark & 0.306 & 0.513 & 0.317 & 0.203 & 0.427 & 0.544 \\
\bottomrule
\end{
    
    tabular}
\caption{
    
    Detection results with different module combinations.}
\label{
    
    tab:11}
\end{
    
    table*}

这段代码将创建一个表格,其中 APm 和 APl 与其他指标在同一行内,并且所有列都是并排的。记得根据我们的具体需求调整 \tabcolsep 的值来改变列间距,以及确保表格内容不会超过页面的宽度。如果表格内容太宽,可能需要进一步调整字体大小或页面布局。

如果此时的表格没有显示线条,可能是因为我们的 LaTeX 环境中没有正确安装 booktabs 包,或者没有正确使用它的命令。下面的代码示例使用了 booktabs 包,它提供了 \toprule\midrule\bottomrule 命令,这些命令分别用于表格的顶部、中部和底部线条。

确保我们的 LaTeX 文档的导言区域包含了下面的行来导入 booktabs 包:

\usepackage{
    
    booktabs}

我们看一下展示的结果:

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/wzk4869/article/details/135179165