# Several problems regarding tabularx in threeparttable

\documentclass[a4paper]{article}
\usepackage[top=1in, bottom=1.25in, left=1.25in, right=1.25in]{geometry}
\usepackage{colortbl,threeparttable,tabularx,multirow,booktabs,makecell,tabularx,ltxtable,afterpage,siunitx,ltablex,blindtext}
\newcolumntype{Y}{>{\centering\arraybackslash}X}

\begin{document}
\blindtext
\begin{table}[htbp!]
\begin{threeparttable}
[![enter image description here][1]][1]\centering
\caption{Analysis on results obtained from experiments in $75\times75$ simulated terrain}
\footnotesize
\renewcommand*{\arraystretch}{.7}%
\begin{tabularx}{\textwidth}{c >{\columncolor[gray]{0.9}}Y >{\columncolor[gray]{0.9}}Y YYY}
\toprule
\multirow{4}{*}{Weight, $\mathbf{w}$}   &\multicolumn{5}{c}{Distance of $c(\pi_{st}^*)$ from $c^*$}\\\cmidrule{2-6}
&\multicolumn{2}{c}{\cellcolor[gray]{0.9}$75\times75$ with $|\Lambda|=20$}  &\multicolumn{3}{c}{$75\times75$ with $|\Lambda|=30$}\\\cmidrule{2-6}
&&SS2   &\multirow{2}{*}{SS1}   &SS2    &SS2\\
&\multirow{-2}{*}{SS1}  &(5 clusters)\tnote{a}  &&(6 clusters)\tnote{b} &(7 clusters)\tnote{c}\\\midrule
$(0.9,0.05,0.05)$    &214.98  &302.86  &80.80   &347.33  &212.39\\
$(0.05,0.9,0.05)$    &142.84  &376.70  &112.16  &366.14  &177.94\\
$(0.05,0.05,0.9)$    &184.61  &329.48  &201.10  &320.26  &231.53\\
$(0.7,0.1,0.2)$      &146.08  &302.34  &126.41  &349.37  &174.03\\
$(0.2,0.7,0.1)$      &123.75  &289.72  &108.34  &307.59  &172.54\\
$(0.1,0.2,0.7)$      &184.40  &328.80  &150.47  &297.72  &185.81\\
$(0.45,0.45,0.1)$    &296.60  &273.83  &35.93   &313.63  &158.76\\
$(0.45,0.1,0.45)$    &186.59  &324.37  &110.51  &302.53  &161.04\\
$(0.1,0.45,0.45)$    &288.61  &309.21  &133.32  &276.34  &171.12\\
$(0.33,0.33,0.34)$   &149.46  &302.62  &137.89  &282.16  &163.97\\\bottomrule
\end{tabularx}

\begin{tablenotes}
\item[] Measurements in $\text{min}:\text{max}:\text{average}$ format:
\item[a] $\text{Cluster radius}=37.01:66.48:52.95$. $\text{Intercluster distance}=8.06:47.52:22.83$
\item[b] $\text{Cluster radius}=35.01:38.91:36.86$. $\text{Intercluster distance}=7.28:56.64:25.31$
\item[c] $\text{Cluster radius}=24.04:39.56:31.89$. $\text{Intercluster distance}=7.07:63.81:26.22$
\end{tablenotes}
\end{threeparttable}
\end{table}

\blindtext
\end{document}


That's what I get from my code. I have three issues here:

1) I want the table to span the entire textwidth as long as possible.

2) I already declared \newcolumntype to center the columns, why it is not working?

3) I don't want the spacing between the table and tablenotes. How can I do that?

If I use tabular instead of tabularx, all the column are centered and there is no spacing between table and tablenotes, except that the table is not spanning.

• Remove ltablex from your preamble. Also make sure that you load packages only once. If you need a package that combines the features of tabularx and longtable, I'd recommend the use of xltabular (instead of ltablex and ltxtable). Commented Jul 23, 2019 at 6:52

Since there is no need for automatic line breaks in any of the columns, it would seem that tabular* is a better choice than tabularx.

\documentclass[a4paper]{article}
\usepackage[top=1in, bottom=1.25in, hmargin=1.25in]{geometry}
\usepackage[flushleft]{threeparttable}
\usepackage{tabularx,booktabs,siunitx}

\begin{document}

\begin{table}[htbp!]
\begin{threeparttable}
\setlength\tabcolsep{0pt} % let LaTeX figure out the intercol. whitespace
\caption{Analysis on results obtained from experiments
in $75\times75$ simulated terrain}
%\footnotesize % not needed
%\renewcommand*{\arraystretch}{.7}% % a very bad idea -- don't do it!
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} l *{5}{S[table-format=3.2]}}
\toprule
Weight, $\mathbf{w}$ &\multicolumn{5}{c}{Distance of $c(\pi_{st}^*)$ from $c^*$}\\
\cmidrule{2-6}
&\multicolumn{2}{c}{$75\times75$ with $|\Lambda|=20$}
&\multicolumn{3}{c}{$75\times75$ with $|\Lambda|=30$} \\
\cmidrule{2-3} \cmidrule{4-6}
& {SS1} & {SS2} & {SS1} & {SS2} & {SS2} \\
& &{(5 clusters)\tnote{a}}  &
&{(6 clusters)\tnote{b}}
&{(7 clusters)\tnote{c}}\\
\midrule
$(0.9,0.05,0.05)$  &214.98  &302.86  &80.80   &347.33  &212.39\\
$(0.05,0.9,0.05)$  &142.84  &376.70  &112.16  &366.14  &177.94\\
$(0.05,0.05,0.9)$  &184.61  &329.48  &201.10  &320.26  &231.53\\
$(0.7,0.1,0.2)$    &146.08  &302.34  &126.41  &349.37  &174.03\\
$(0.2,0.7,0.1)$    &123.75  &289.72  &108.34  &307.59  &172.54\\
$(0.1,0.2,0.7)$    &184.40  &328.80  &150.47  &297.72  &185.81\\
$(0.45,0.45,0.1)$  &296.60  &273.83  &35.93   &313.63  &158.76\\
$(0.45,0.1,0.45)$  &186.59  &324.37  &110.51  &302.53  &161.04\\
$(0.1,0.45,0.45)$  &288.61  &309.21  &133.32  &276.34  &171.12\\
$(0.33,0.33,0.34)$ &149.46  &302.62  &137.89  &282.16  &163.97\\
\bottomrule
\end{tabular*}

\begin{tablenotes}
\small
\item[] Measurements in min : max : average format.
\item[a] Cluster radius${}=37.01:66.48:52.95$. Intercluster distance${}=8.06:47.52:22.83$.
\item[b] Cluster radius${}=35.01:38.91:36.86$. Intercluster distance${}=7.28:56.64:25.31$.
\item[c] Cluster radius${}=24.04:39.56:31.89$. Intercluster distance${}=7.07:63.81:26.22$.
\end{tablenotes}
\end{threeparttable}
\end{table}

\end{document}