# tabularx table not taking page width after importing ltablex

I want some tables to take up the page width. I was able to do this using the tabularx package and the X parameter.

Here is an example of what a table looks like:

However, I need to use captions but I also want to use them with a tabularx table. I used the ltablex package and captions work. However, after importing them tables no longer take the full page width. Tables look something like this after importing ltablex:

I've already tried using \linewidth instead of \textwidth but I still get the same result. I couldn't find a solution to the problem.

Code Sample:

\documentclass[a4paper, 12pt]{article}

\usepackage{tabularx}
% \usepackage{ltablex}
\usepackage{multirow}
\usepackage{caption}
\captionsetup[table]{skip=5pt}

\begin{document}
\noindent\begin{tabularx}{\textwidth}{|X|X|}
\hline
\hline\hline
Lorem ipsum & Dolor sit\\
\hline
\hline
\end{tabularx}
\end{document}

• Why exactly do you want to use the ltablex package? Do you want to use X columns in tables that are longer than a page? If so, try xltabular instead. Your comment "However, I need to use captions but I also want to use them with a tabluarx table. I used the ltablex package and captions work." makes me wonder if you just added ltablex for the captions. If that's the case, please keep in mind that you could just place the tabularx table inside of a table environment and use \caption there. Nov 4 '21 at 19:14
• I didn't know I could wrap the tabularx inside a table. That solved my problem Thanks!
Nov 4 '21 at 19:20
• Any tabular-like environment that is not supposed to span multiple pages can be placed inside of table. Nov 4 '21 at 19:21
• Oh alright, thanks for the help @leandriis.
Nov 4 '21 at 19:22

The behaviour you observe is caused by the following feature of the ltablex package: (Quoted from the package manual)
Another feature that has been added is to treat the X columns like l columns if the table contents would allow that to happen without exceeding the specified width of the table. In other words, the specified width is treated as the maximum allowed and not the exact width of the table. This feature is the default but can be disabled (or enabled) with \keepXColumns (or \convertXColumns).
Since the actual question is "How to add a caption to a tabularx environment", here is a comment on that, as well. Just place the tabularx in a table environment and use the \caption command there.