如何将内容放入 LaTeX 表格的某一列中?

如何将内容放入 LaTeX 表格的某一列中?

我正在尝试用 LaTeX 创建表格。但是我的列的内容超出了宽度并侵入了另一列。请帮我解决这个问题。代码粘贴在下面。输出的屏幕截图附在此处

在此处输入图片描述

\documentclass[sigconf, authordraft]{acmart}

\usepackage{booktabs}
\usepackage{multirow}
%
\begin{document}

\begin{table*}[!h]
\centering
\caption{Quality metrics with reference image-MS and HH SAR}                                    
\label{tab:table2}
\begin{tabular}{p{0.6 cm} p{1.3 cm} p{1.5 cm} p{1.5 cm} p{1.5 cm} p{1.5 cm}p{1.5 cm}}
\toprule
Sl. No. & Metric & Band  &PCA &DWT &IHS-DWT &PCA-DWT \\
\midrule
  \multirow{4}{*}{1} & \multirow{4}{*}{SCC (SAR \& Fused Image)} & Green  &0.635  &0.550 &0.590 &0.525  \\
 & & Red &0.453 &0.468 &0.514 &0.343  \\                
 & & NIR &0.783 &0.501 &0.368 &0.486 \\                                 
 & & SWIR &0.642    &0.504 &0.432 &0.425 \\ 
  \bottomrule
  \multirow{4}{*}{2} & \multirow{4}{*}{SCC  (Original MS \& Fused Image)} & Green  &0.214  &0.595 &0.343 &0.540  \\
 & & Red &0.701 &0.649 &0.554 &0.830  \\                
 & & NIR &0.321 &0.623 &0.846 &0.687 \\                                 
 & & SWIR &0.463    &0.615 &0.738 &0.731 \\ 
  \bottomrule
\end{tabular}
\end{table*}
\end{document}

答案1

通过手动硬编码列宽,您让简单的事情变得复杂。只需使用自然列宽,lllcccc除非某些列中的文本真的很长。

\documentclass[sigconf, authordraft]{acmart}    
\usepackage{booktabs}
\usepackage{multirow}
%
\begin{document}

\begin{table*}[!h]
\centering
\caption{Quality metrics with reference image-MS and HH SAR}                                    
\label{tab:table2}
\begin{tabular}{@{}lllcccc@{}}
\toprule
Sl. No.            & Metric                                             & Band  & PCA   & DWT   & IHS-DWT & PCA-DWT \\
\midrule
\multirow{4}{*}{1} & \multirow{4}{*}{SCC (SAR \& Fused Image)}          & Green & 0.635 & 0.550 & 0.590   & 0.525   \\
                   &                                                    & Red   & 0.453 & 0.468 & 0.514   & 0.343   \\
                   &                                                    & NIR   & 0.783 & 0.501 & 0.368   & 0.486   \\
                   &                                                    & SWIR  & 0.642 & 0.504 & 0.432   & 0.425   \\
\bottomrule
\multirow{4}{*}{2} & \multirow{4}{*}{SCC (Original MS \& Fused Image)}  & Green & 0.214 & 0.595 & 0.343   & 0.540   \\
                   &                                                    & Red   & 0.701 & 0.649 & 0.554   & 0.830   \\
                   &                                                    & NIR   & 0.321 & 0.623 & 0.846   & 0.687   \\
                   &                                                    & SWIR  & 0.463 & 0.615 & 0.738   & 0.731   \\
\bottomrule
\end{tabular}
\end{table*}
\end{document}

在此处输入图片描述

答案2

您可以使第二列稍微宽一些(p{1.7 cm}而不是p{1.3 cm}),并使用\shortstack它来换行:

\documentclass[sigconf, authordraft]{acmart}

\usepackage{booktabs}
\usepackage{multirow}
%
\begin{document}

\begin{table*}[!h]
\centering
\caption{Quality metrics with reference image-MS and HH SAR}
\label{tab:table2}
\begin{tabular}{p{0.6 cm} p{1.7 cm} p{1.5 cm} p{1.5 cm} p{1.5 cm} p{1.5 cm}p{1.5 cm}}
\toprule
Sl. No. & Metric & Band  &PCA &DWT &IHS-DWT &PCA-DWT \\
\midrule
  \multirow{4}{*}{1} & \multirow{4}{*}{\shortstack{SCC \\ (SAR \\ \& Fused Image)}} & Green  &0.635  &0.550 &0.590 &0.525  \\
 & & Red &0.453 &0.468 &0.514 &0.343  \\
 & & NIR &0.783 &0.501 &0.368 &0.486 \\
 & & SWIR &0.642    &0.504 &0.432 &0.425 \\
  \bottomrule
  \multirow{4}{*}{2} & \multirow{4}{*}{\shortstack{SCC \\ (Original MS \\ \& Fused Image)}} & Green  &0.214  &0.595 &0.343 &0.540  \\
 & & Red &0.701 &0.649 &0.554 &0.830  \\
 & & NIR &0.321 &0.623 &0.846 &0.687 \\
 & & SWIR &0.463    &0.615 &0.738 &0.731 \\
  \bottomrule
\end{tabular}
\end{table*}
\end{document}

在此处输入图片描述

相关内容