[Tex/LaTex] Create a table with specified column widths and centre spacing in tabularx

tablestabularx

I would like to create a table where I can adjust the overall width of the table, hence the tabularx environment. However I am having difficulty in configuring my tables such that I can control:

  1. The individual width of each column.
  2. Centre each column.

This is the code I am using:

\documentclass[15pt,twoside]{report}
\usepackage{amsfonts}
\usepackage{tabularx, booktabs}
\usepackage{siunitx}
\usepackage{array}
\begin{document}
\begin{table}[h!]
\centering
\begin{tabularx}{\textwidth}{p{1.5cm}p{1.5cm}p{1.5cm}p{2.5cm}p{1.5cm}}\toprule\\[0.09ex]
Modelling & Reference & $\mu_{s}$ & Modelling & Outcome \\ Noise RMS &  Input Noise & & Time Duration \\ [2ex] \midrule\\ [0.5ex]
Optimal (0.3)& & 0.5 & Stopped once converged & Converged \\ [2ex]
0.05 & & 0.25 & $n=10000$ & Failed to converge \\ [2ex]
 0.1 & & 0.25 & $n=10000$ & Destabilised \\ [2ex]
0.15 & & 0.25 & $n=10000$ & Destabilised \\ [2ex]
0.2 & & 0.25 & $n=10000$ & Destabilised \\ [2ex]
0.25 & & 0.25 & $n=10000$ & Destabilised \\ [2ex]
0.3 & & 0.25 & $n=10000$ & Destabilised \\ [2ex]
0.35 & & 0.25 & $n=10000$ & Destabilised \\ [2ex]
0.4 & & 0.25 & $n=10000$ & Destabilised \\ [2ex]
0.45 & & 0.25 & $n=10000$ & Destabilised \\ [2ex]
 0.5 & & 0.25 & $n=10000$ & Destabilised \\ [0.5ex]\\ \bottomrule
\end{tabularx}
\end{table}

I have deliberately kept the second column empty for now. Any help on this is greatly appreciated as I have been trying to solve this for hours (including searching similar posts on tex stack exchange) to no avail. Thanks.

Best Answer

You don't need tabularx if you don't use its X columns which adjust their width according to the available space.

You probably just need a new column type M defined in this way:

\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}

You don't also need to use different rows for long cells, since they are wrapped into new lines automatically.

MWE:

\documentclass[twoside]{report}
\usepackage{amsfonts}
\usepackage{tabularx, booktabs}
\usepackage{siunitx}
\usepackage{array}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\begin{document}
\begin{table}[h!]
\centering
\begin{tabular}{M{1.7cm}M{1.5cm}M{1.5cm}M{2.5cm}M{2cm}}
\toprule
Modelling Noise RMS & Reference Input Noise & $\mu_{s}$ & Modelling Time Duration & Outcome \\
\midrule\\ [0.5ex]
Optimal (0.3)& & 0.5 & Stopped once converged & Converged \\ [2ex]
0.05 & & 0.25 & $n=10000$ & Failed to converge \\ [2ex]
 0.1 & & 0.25 & $n=10000$ & Destabilised \\ [2ex]
0.15 & & 0.25 & $n=10000$ & Destabilised \\ [2ex]
0.2 & & 0.25 & $n=10000$ & Destabilised \\ [2ex]
0.25 & & 0.25 & $n=10000$ & Destabilised \\ [2ex]
0.3 & & 0.25 & $n=10000$ & Destabilised \\ [2ex]
0.35 & & 0.25 & $n=10000$ & Destabilised \\ [2ex]
0.4 & & 0.25 & $n=10000$ & Destabilised \\ [2ex]
0.45 & & 0.25 & $n=10000$ & Destabilised \\ [2ex]
 0.5 & & 0.25 & $n=10000$ & Destabilised \\ [0.5ex]\\ \bottomrule
\end{tabular}
\end{table}
\end{document} 

Output

enter image description here

As a side note, 15pt is not a valid option for the report class.

Related Question