I've a slight problem when using the tabularx package.
I would like all of the tables in my thesis to be the width of the page. I am trying to achieve this by using the tabularx package. It mostly works. However, if I have a caption that is less than 58 characters long the table does not spread across the page.
I include a MWE below. The first table has 59 characters and produces the desired output, the second has 58 characters and is not how I would like it.
Code: Select all
% ************ Preamble ****************
\documentclass[a4paper,12pt]{report}
\usepackage[top=2cm, bottom=2cm, left=3.5cm, right=2cm]{geometry} % sets margins
\usepackage{natbib} % for harvard style referencing
\usepackage[margin=10pt, labelfont=bf, format=hang, textfont={small,it}]{caption} % for more interesting captions
\captionsetup[subfigure]{style=default, margin=0pt, labelfont=bf, textfont={small,it}, singlelinecheck=true} % makes subfigure captions a bit more interesting.
\usepackage{multirow} % allows merging of rows in tables
\usepackage{ltablex} % Combines tabularx and longtable functionality
\usepackage{booktabs} % For professional looking tables
% *********** BEGIN! ******************
\begin{document}
\begin{tabularx}{\textwidth}{X X X X X X X}
\caption{An example table that does not spread across the whole widt}\\
\toprule
\textbf{Number} & \multicolumn{6}{l}{\textbf{Number}} \\
\textbf{(samples)} & \textbf{0} & \textbf{1} & \textbf{2} & \textbf{3} & \textbf{4} & \textbf{5} \\ \hline
1 & \textit{1} & -- & -- & -- & -- & --\\
2 & \textit{2} & -- & -- & -- & -- & --\\
3--5 & \textit{3} & -- & -- & -- & -- & --\\
6--10 & \textit{4} & \textit{5} & -- & -- & -- & --\\
11--18 & \textit{6} & \textit{7} & \textit{8} & -- & -- & --\\
\bottomrule
\label{tab:this_one_does}
\end{tabularx}
\begin{tabularx}{\textwidth}{X X X X X X X}
\caption{An example table that does not spread across the whole wid}\\
\toprule
\textbf{Number} & \multicolumn{6}{l}{\textbf{Number}} \\
\textbf{(samples)} & \textbf{0} & \textbf{1} & \textbf{2} & \textbf{3} & \textbf{4} & \textbf{5} \\ \hline
1 & \textit{1} & -- & -- & -- & -- & --\\
2 & \textit{2} & -- & -- & -- & -- & --\\
3--5 & \textit{3} & -- & -- & -- & -- & --\\
6--10 & \textit{4} & \textit{5} & -- & -- & -- & --\\
11--18 & \textit{6} & \textit{7} & \textit{8} & -- & -- & --\\
\bottomrule
\label{tab:this_one_does_not}
\end{tabularx}
\end{document}
Thank you.
Jon