1

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.

  • 1
    tabularx adjusts the width of the, table by adjusting the width of X columns but you have none, so it can do nothing useful here just use tabular and >{\centering\arraybackslash}p{1.5cm} for centred columns – David Carlisle Mar 25 '15 at 10:04
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – karlkoeller Mar 25 '15 at 10:14
  • You could also use \resizebox. – John Kormylo Mar 25 '15 at 14:24
2

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.

2

Here is a variant:

\documentclass[12pt,twoside]{report}
\usepackage{amsfonts}
\usepackage{tabularx, booktabs}
\usepackage{siunitx}
\usepackage{array}
\usepackage{ragged2e}
\newcolumntype{P}[1]{>{\Centering\arraybackslash}p{#1}}

\begin{document}
\begin{table}[h!]
\centering
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}S[table-format=1.2]P{1.4cm}
                            S[table-format=1.2]P{2.5cm}P{1.8cm}}\toprule
{Modelling} & Reference & {$\mu_{s}$} & Modelling & Outcome \\ 
{Noise RMS} &  Input Noise & & Time Duration \\ [2ex] \midrule
{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 \\ \bottomrule
\end{tabular*}
\end{table}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.