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:

table with tabularx alone

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:

table 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{ltablex}

    Heading 1 & Heading 2\\
    Lorem ipsum & Dolor sit\\
    Amet consectetuer & Adipiscing elit\\
  • 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.
    – leandriis
    Nov 4 '21 at 19:14
  • I didn't know I could wrap the tabularx inside a table. That solved my problem Thanks!
    – Hady
    Nov 4 '21 at 19:20
  • Any tabular-like environment that is not supposed to span multiple pages can be placed inside of table.
    – leandriis
    Nov 4 '21 at 19:21
  • Oh alright, thanks for the help @leandriis.
    – Hady
    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.

  • Thanks for the help!
    – Hady
    Nov 4 '21 at 19:22

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.