2

I am having difficult time with adjusting the following table. I have the code as follows:

\documentclass[dissertation,letterpaper,12pt]{utthesis}
\usepackage{tabularx}
\usepackages{multirow}
\begin{document}

\begin{table*}[hb]
  \centering
  \footnotesize
  \caption{Parameter settings and results for different scenarios. \label[tab]{results}}
  \begin{tabularx}{\textwidth}{c@{\extracolsep{\fill}}lcccccccccccc}
  \hline
\multirow{4}{*}{\begin{tabular}[c]{@{}l@{}}Part\\ Type \#\end{tabular}} & \multicolumn{12}{c}{$\mu_j=U(91,876)$}\\ \cline{2-13}
& \multicolumn{3}{c}{$\lambda_j=U(0.01,0.1)$} & \multicolumn{3}{c}{$\lambda_j=U(0.09,0.1)$} & \multicolumn{3}{c}{$\lambda_j=U(0.1,0.5)$} & \multicolumn{3}{c}{$\lambda_j=U(0.5,0.9)$} \\ \cline{2-13}
& \multicolumn{12}{c}{Planning Horizon (Years)}\\ \cline{2-13}
& 10& 20& 30& 10& 20& 30& 10& 20& 30& 10& 20& 30\\ \hline
1& I& I& A& I& A& I& A& I& A& A& I& A\\
2& I& I& A& I& I& A& I& I& A& A& A& A\\
3& I& I& I& I& A& A& A& A& I& I& I& I\\
4& I& I& I& I& A& A& I& A& I& I& A& I\\
5& I& P& P& I& I& P& A& I& P& P& P& A\\
6& I& A& A& I& I& A& A& I& A& I& A& I\\ \hline     
\end{tabularx}
\end{table*}

\end{document}

I am using the tabularx environment because it easily allows placing the textwidth. However, it does not always nicely fill it. For example, the above code produces something like:

enter image description here

I have two problems in this result. The first one is I want equal cell width for each 10,20,30 columns. The second one is cline does not fill the whole text (not equal to \textwidth). Any quick solutions?

8
  • 1
    Where did you get utthesis.cls from?
    – leandriis
    Oct 7, 2019 at 21:23
  • Please also clarify what \label[tab]{results}is supposed to do.
    – leandriis
    Oct 7, 2019 at 21:27
  • You're using tabularx but you have no X columns in your table. What do you expect it to do?
    – Alan Munn
    Oct 7, 2019 at 21:30
  • 1
    The column widths in your table appear to be disproportionate because the \multicolumn entries are longer than the combined widths of the three corresponding columns. For more information see here: Table column widths disproportionate due to multicolumn cell being too long. Probably you could introduce linebreaks in the column headers to circumvent this problem. I'd also recommend that you take a look at the horizontal lines from the booktabs package.
    – leandriis
    Oct 7, 2019 at 21:32
  • 1
    @user8028576 - In that case, @{\extracolsep{\fill}} doesn't belong in the picture at all. You should be using suitably modified versions of the X column type instead.
    – Mico
    Oct 7, 2019 at 21:40

2 Answers 2

5

NB! I Corrected the \label[tab]{results}, which is wrong syntax unless your thesis-package redefines the label-command. However, I really recommend you to have a look at cleveref.

Use tabular X-column since you are using tabularx. In addition, I used a fixed width column as first column using array’s w-column (require an updated version of array). Also, use booktabs rules instead of hline and cline to have better spacing between the rows. If you prefer more space between row 2 and row 3, use \addlinespace from booktabs:

Example 1

enter image description here

\documentclass[12pt]{article}
\usepackage{tabularx, booktabs, array, caption}
\usepackage{multirow}
\begin{document}

\begin{table*}
  \centering
  \footnotesize
  \caption{Parameter settings and results for different scenarios.
  \label{tab:results}}  %%%%  <------- Corrected
  \begin{tabularx}{\textwidth}{@{}>{\raggedright}wl{1.5cm}*{12}{>{\centering\arraybackslash}X}@{}}
  \toprule
\multirow{5}{*}{\begin{tabular}[c]{@{}l@{}}Part\\ Type \#\end{tabular}} & \multicolumn{12}{c}{$\mu_j=U(91,876)$}\\ \cmidrule{2-13}
& \multicolumn{3}{c}{$\lambda_j=U(0.01,0.1)$} & \multicolumn{3}{c}{$\lambda_j=U(0.09,0.1)$} & \multicolumn{3}{c}{$\lambda_j=U(0.1,0.5)$} & \multicolumn{3}{c}{$\lambda_j=U(0.5,0.9)$} \\ \cmidrule{2-13}
& \multicolumn{12}{c}{Planning Horizon (Years)}\\ \cmidrule{2-13}
& 10& 20& 30& 10& 20& 30& 10& 20& 30& 10& 20& 30\\ \midrule
1& I& I& A& I& A& I& A& I& A& A& I& A\\
2& I& I& A& I& I& A& I& I& A& A& A& A\\
3& I& I& I& I& A& A& A& A& I& I& I& I\\
4& I& I& I& I& A& A& I& A& I& I& A& I\\
5& I& P& P& I& I& P& A& I& P& P& P& A\\
6& I& A& A& I& I& A& A& I& A& I& A& I\\ \bottomrule
\end{tabularx}
\end{table*}

\end{document}

Example 2

This is with split cmidrule and !{\hspace*{0.25em}} to increase space between column 4 and 5, 7 and 8 and 10 and 11 to group columns. In addition, I used \addlinespace to increase space between row 2 and 3.

It is the (l) statement in \cmidrule(l){2-4} that split the rule. Just remove the parenthesis and their content to have a solid rule.

enter image description here

\documentclass[12pt]{article}
\usepackage{tabularx, booktabs, array, caption}
\usepackage{multirow}

\begin{document}


\begin{table*}
  \centering
  \footnotesize
  \setlength{\tabcolsep}{0.4em}
  \caption{Parameter settings and results for different scenarios.
  \label{tab:results}}  %%%%  <------- Corrected
  \begin{tabularx}{\textwidth}{@{}>{\raggedright}
                             wl{1.5cm}*{3}{>{\centering\arraybackslash}X}
                             !{\hspace*{0.25em}}*{3}{>{\centering\arraybackslash}X}
                             !{\hspace*{0.25em}}*{3}{>{\centering\arraybackslash}X}
                             !{\hspace*{0.25em}}*{3}{>{\centering\arraybackslash}X}
                             @{}
            }
\toprule
\multirow{6}{*}{\begin{tabular}[c]{@{}l@{}}Part\\ Type \#\end{tabular}}
& \multicolumn{12}{c}{$\mu_j=U(91,876)$}\\
\cmidrule(l){2-13}
& \multicolumn{3}{c}{$\lambda_j=U(0.01,0.1)$} & \multicolumn{3}{c}{$\lambda_j=U(0.09,0.1)$}
& \multicolumn{3}{c}{$\lambda_j=U(0.1,0.5)$} & \multicolumn{3}{c}{$\lambda_j=U(0.5,0.9)$} \\ 
\cmidrule(lr{\tabcolsep}){2-4}\cmidrule(lr{\tabcolsep}){5-7}
\cmidrule(lr{\tabcolsep}){8-10}\cmidrule(l){11-13}
\addlinespace[3pt]
& \multicolumn{12}{c}{Planning Horizon (Years)}\\ \cmidrule(l){2-13}
& 10& 20& 30& 10& 20& 30& 10& 20& 30& 10& 20& 30\\ \midrule
1& I& I& A& I& A& I& A& I& A& A& I& A\\
2& I& I& A& I& I& A& I& I& A& A& A& A\\
3& I& I& I& I& A& A& A& A& I& I& I& I\\
4& I& I& I& I& A& A& I& A& I& I& A& I\\
5& I& P& P& I& I& P& A& I& P& P& P& A\\
6& I& A& A& I& I& A& A& I& A& I& A& I\\ \bottomrule
\end{tabularx}
\end{table*}

\end{document}
4
  • At least of second \cmidrule{2-13} I would rather use \cmidrule(l){2-4}\cmidrule(l){5-7}\cmidrule(l){8-10}\cmidrule(l){11-13}
    – Zarko
    Oct 7, 2019 at 21:54
  • @Zarko I agree. I would also consider grouping the twelve rows with addition space between the rows 4 and 5, and 8 and 9. But OP said equal width.
    – Sveinung
    Oct 7, 2019 at 21:58
  • Wow, this looks much better! Now, I have to understand this all to be able to reapply. Thanks!
    – tcokyasar
    Oct 7, 2019 at 22:03
  • @Zarko, \cmidrule(l){2-4}\cmidrule(l){5-7}\cmidrule(l){8-10}\cmidrule(l){11-13} separate the lines which is not really what I want. Does it do anything other than separating the lines?
    – tcokyasar
    Oct 7, 2019 at 22:09
5

How to organize table is quite opinion base. Some ones might liked the following (based on Sveinung and my comment above):

enter image description here

\documentclass[12pt]{article}
\usepackage{geometry}
\usepackage{booktabs, makecell, multirow, tabularx}
\usepackage[skip=1ex]{caption}

\begin{document}
    \begin{table}[hb]
\centering
  \small
\caption{Results at $\mu_j=U(91,876)$ and different scenarios for $\lambda_j$.} 
\label{tab:results}
\begin{tabularx}{\textwidth}{@{}
                                  c *{3}{*{3}{>{\centering\arraybackslash}X}c} 
                                    *{3}{>{\centering\arraybackslash}X}
                             @{}}
    \toprule
    \addlinespace
    & \multicolumn{15}{c}{Planning Horizon (Years)}                 \\
\multirow{2}{*}{\makecell{Part\\ Type \#}}
    & 10& 20& 30    && 10& 20& 30   && 10& 20& 30   && 10& 20& 30   \\ 
    & \multicolumn{3}{>{\footnotesize}c}{$\lambda_j=U(0.01,0.1)$}
        && \multicolumn{3}{>{\footnotesize}c}{$\lambda_j=U(0.09,0.1)$}
            && \multicolumn{3}{>{\footnotesize}c}{$\lambda_j=U(0.1,0.5)$}
                && \multicolumn{3}{>{\footnotesize}c}{$\lambda_j=U(0.5,0.9)$}   \\
    \cmidrule(r){1-1}\cmidrule{2-4}\cmidrule{6-8}\cmidrule{10-12}\cmidrule{14-16}
1   & I & I & A     && I & A & I    && A & I & A    && A & I & A    \\
2   & I & I & A     && I & I & A    && I & I & A    && A & A & A    \\
3   & I & I & I     && I & A & A    && A & A & I    && I & I & I    \\
4   & I & I & I     && I & A & A    && I & A & I    && I & A & I    \\
5   & I & P & P     && I & I & P    && A & I & P    && P & P & A    \\
6   & I & A & A     && I & I & A    && A & I & A    && I & A & I    \\ 
    \bottomrule
\end{tabularx}
    \end{table}
\end{document}

You must log in to answer this question.

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