1

I am starting out with latex, and trying to write a thesis. I need a table with the given format. But in the multicolumn, I need all the three columns in equal width. I searched a lot, found out that I need to use tabularx for this purpose. However, I am still not getting it right. What am I doing wrong?

enter image description here

\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}

2
  • 1
    Unrelated don't use the center env to center inside a float like table. Both the table env and the center env adds vertical space so you end up with too much vertical space. Replace \begin{center} by \centering and remove the end part
    – daleif
    Commented Jul 10, 2021 at 15:29
  • Noted. Thanks for pointing it out! Commented Jul 10, 2021 at 16:13

2 Answers 2

1
  • You have problem with too extensive use of \multicolumn cells. Most of them are superfluous and should be removed.
  • Last column is wider because \multicolumn cells, which spanned last three columns are too wide. You need to limit their widths to the width of the last three X column
  • I would employ the siunitx package for writing quantities.

So, your MWE could be as follows:

\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}

enter image description here

7
  • Thank you, this is great! I am trying to understand this, but I cannot run this in Kile. It is showing error "undefined control sequence \end{tabularx}. I am trying to figure out now if I went wrong in copying the code. Commented Jul 10, 2021 at 17:02
  • @AnnaThomas, I use MiKTeX on Windows machine, recent version (21.6.28), MWE is tested and result is shown in answer. Please, verify, if you have installed up-to-date packages.
    – Zarko
    Commented Jul 10, 2021 at 17:29
  • I am using Kile 2.9.91 on Ubuntu 18.04. I will look into the compatibility. Thanks again! Commented Jul 10, 2021 at 17:38
  • @Bernard, thank you very much for editing!
    – Zarko
    Commented Jul 10, 2021 at 18:34
  • 1
    You have installed old version of siunitx (version 2) meanwhile in my answer is anticipated, that you have installed recent version 3. Proposed solution also work with version 2 if you replace \qty with SI.
    – Zarko
    Commented Jul 11, 2021 at 5:26
1

What about the following alternative approach?

enter image description here

\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}
3
  • Looks great, I might just try this!! Thank you!. But I am not able to run the code, similar problem with Zarko's code as well. I am trying to figure out what went wrong. Error message is undefined control sequence \end{tabularx} Commented Jul 10, 2021 at 17:04
  • The problem is with siunitx package which doesn't seem to work inside tabularx in the system I use (Kile 2.9.91, Ubuntu 18.04). I added the textcomp package and removed the siunitx syntax (\qty{} and $\sim$) and it worked. Thanks a lot for your efforts, I learned a lot. Commented Jul 11, 2021 at 4:06
  • Correction: I retained $\sim$ Commented Jul 11, 2021 at 4:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .