即使使用 tabularx 后,表格中的多列仍然不平等

即使使用 tabularx 后,表格中的多列仍然不平等

我开始使用 latex,并尝试撰写论文。我需要一个具有给定格式的表格。但在多列中,我需要所有三列宽度相等。我搜索了很多,发现我需要使用 tabularx 来实现此目的。但是,我仍然做错了什么。我做错了什么?

在此处输入图片描述

\documentclass{article}


\usepackage{textcomp}
\usepackage{multirow}

\usepackage{tabularx,booktabs}
\newcolumntype{Y}{>{\centering\arraybackslash}X}

\begin{document}

\begin{table}
\caption{Caption explaining the table will come here which will be 
really long } 
\label{Table-1}
\begin{center}
\begin{footnotesize}
%\begin{tabular}{|l|l|l|l|}
\begin{tabularx}{\textwidth}{ |l| *{3}{Y|} }
\hline
\multicolumn{4}{|c|}{}\\
\multicolumn{4}{|c|}{\textsc{HEADING HERE FOR ONE TYPE OF 
CLASSIFICATION}} \\
\multicolumn{4}{|c|}{}\\
\multirow{2}{*}{Classification One} & \multicolumn{3}{l|}{A really 
really really long statement will come here} \\
& \multicolumn{3}{l|}{and continue here as well} \\
Classification Two & \multicolumn{3}{l|}{Another really 
really really long statement will come here} \\
\multicolumn{4}{|c|}{}\\
\multicolumn{4}{|c|}{\textsc{Another heading here for the next 
section}}\\
\multicolumn{4}{|c|}{}\\
& \multicolumn{1}{c|}{\textbf{C1}} & 
\multicolumn{1}{c|}{\textbf{C2}} & 
\multicolumn{1}{c|}{\textbf{C3}} \\
\cline{2-4}

& \multicolumn{1}{c|}{} &\multicolumn{1}{c|}{} &\multicolumn{1}{c|}{} \\
Another long name for a classification appears here & 
\multicolumn{1}{c|}{0.555\textdegree} & 
\multicolumn{1}{c|}{0.555\textdegree} & 
\multicolumn{1}{c|}{0.555\textdegree} \\
& 
\multicolumn{1}{c|}{($\sim$ 
25.0 km)} & \multicolumn{1}{c|}{($\sim$ 18.0 km)} & 
\multicolumn{1}{c|}{($\sim$ 33.0 km)} \\


Another long name for a classification appears here & 
\multicolumn{1}{c|}{0.2525\textdegree} & 
\multicolumn{1}{c|}{0.2525\textdegree} & 
\multicolumn{1}{c|}{0.2525\textdegree}\\
Another long name for a classification appears here & 
\multicolumn{1}{c|}{100} & 
\multicolumn{1}{c|}{100} & \multicolumn{1}{c|}{100} \\
Another long name for a classification appears here & 
\multicolumn{1}{c|}{100} & 
\multicolumn{1}{c|}{100} & \multicolumn{1}{c|}{100} \\
Another long name for a classification appears here & 
\multicolumn{1}{c|}{50} 
&\multicolumn{1}{c|}{ 50} & \multicolumn{1}{c|}{50} \\
A short name for a classification appears here& 
\multicolumn{1}{c|}{60} & 
\multicolumn{1}{c|}{60} & \multicolumn{1}{c|}{30} \\

\hline

\end{tabularx}
%\end{tabular}
\end{footnotesize}
\end{center}
\end{table}

\clearpage


\end{document}

答案1

  • 您的问题在于过度使用\multicolumn单元格。大多数单元格都是多余的,应该删除。
  • 最后一列较宽,因为跨越最后三列的单元格太宽。您需要将它们的宽度限制为最后三列\multicolumn的宽度X
  • 我将使用该siunitx包来写数量。

因此,你的 MWE 可能如下:

\documentclass{article}
\usepackage{geometry}
\usepackage{textcomp}

\usepackage{booktabs, multirow, tabularx}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\usepackage{siunitx}

\begin{document}
    \begin{table}
    \caption{Caption explaining the table will come here which will be really long }
    \label{Table-1}
\centering
\small
\begin{tabularx}{\textwidth}{ |l| *{3}{Y|} }
    \hline
\multicolumn{4}{|c|}{}                          \\
\multicolumn{4}{|c|}{\textsc{HEADING HERE FOR ONE TYPE OF CLASSIFICATION}}  \\
\multicolumn{4}{|c|}{}                          \\
\multirow{2}{*}{Classification One} 
    & \multicolumn{3}{>{\hsize=\dimexpr3\hsize+4\tabcolsep\relax}X|}{%
    A really really really very long statement at least two lines long}     \\
Classification Two 
    & \multicolumn{3}{>{\hsize=\dimexpr3\hsize+4\tabcolsep\relax}X|}{%
    Another really really really long statement will come here}             \\
\multicolumn{4}{|c|}{}                          \\
\multicolumn{4}{|c|}{\textsc{Another heading here for the next section}}    \\
\multicolumn{4}{|c|}{}                          \\
    &   \textbf{C1}
        &   \textbf{C2}
            &   \textbf{C3}                     \\
    \cline{2-4}
    &   &   &                                   \\
Another long name for a classification appears here 
    &   \qty{0.555}{\degree} 
        &   \qty{0.555}{\degree} 
            &   \qty{0.555}{\degree}            \\
    &   (\qty{\sim 25.0}{km})
        &   (\qty{\sim 18.0}{km})
            &   (\qty{\sim 33.0}{km})           \\
Another long name for a classification appears here 
    &   \qty{0.2525}{\degree} 
            &   \qty{0.2525}{\degree} 
                    &   \qty{0.2525}{\degree}   \\
Another long name for a classification appears here 
    &   100
        &   100
            &   100                             \\
Another long name for a classification appears here 
    &   100
        &   100
            &   100                             \\
Another long name for a classification appears here 
    &   50
        &   50
            &   50                             \\
A short name for a classification appears here
    &   60
        &   60
            &   60                             \\
    \hline
\end{tabularx}
    \end{table}
\end{document}

在此处输入图片描述

答案2

那么下面的替代方法怎么样?

在此处输入图片描述

\documentclass{article}
\usepackage{tabularx,booktabs}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\usepackage{siunitx}
\usepackage{tcolorbox}
\usepackage{makecell}
\usepackage{caption}

\begin{document}

\begin{table}
\caption{Caption explaining the table will come here which will be 
really long } 
\label{Table-1}
\footnotesize
\begin{tcolorbox}[arc=0pt, colback=white]
\centering
\textsc{Heading here for one type of classification}\medskip

\begin{tabularx}{\linewidth}{@{}l X @{}}
Classification One & A really really really long statement will come here and continue here as well \\
Classification Two & Another really really really long statement will come here \\
\end{tabularx}
\bigskip

\textsc{Another heading here for the next section} \medskip

\begin{tabularx}{\linewidth}{@{}X ccc @{}}
& \textbf{C1} & \textbf{C2} & \textbf{C3} \\\midrule
Another long name for a classification appears here & 
\makecell{0.555\textdegree\\($\sim$ \qty{25.0}{\km})}  
& \makecell{0.555\textdegree\\($\sim$ \qty{18.0}{\km})} 
& \makecell{0.555\textdegree\\($\sim$ \qty{30.0}{\km})} \\

Another long name for a classification appears here 
  & 0.2525\textdegree & 0.2525\textdegree & 0.2525\textdegree\\
Another long name for a classification appears here 
  & 100 & 100 & 100 \\
Another long name for a classification appears here 
  & 100 & 100 & 100 \\
Another long name for a classification appears here 
  & 50 & 50 & 50 \\
A short name for a classification appears here 
  & 60 & 60 & 60 \\

\end{tabularx}
\end{tcolorbox}
\end{table}


\end{document}

相关内容