0

I have a problem with setting up a table, created in tabularx, to the text width of my article. What can I do?

Here is the dummy example:

\documentclass[12pt]{article}
\usepackage{ltablex,booktabs}
\usepackage{lipsum}

\begin{document}

\lipsum[100]
\begin{tabularx}{\textwidth}{lX}
\caption{cccc} \\
\toprule
\textbf{Definition} & \textbf{Counts} \\
\midrule

\textit{A}             &  68\\ 
\textit{B}             &  10\\
\textit{C}             &  10\\
\midrule
$\sum$                 &  88\\

\bottomrule
\end{tabularx}
\end{document}

The PDF view:

example

17
  • 4
    At least one X column is required.
    – Bernard
    Commented Oct 2, 2018 at 15:25
  • 1
    Could you post a full compilable code, not just a snippet?
    – Bernard
    Commented Oct 2, 2018 at 15:33
  • 2
    (i) please provide complete small document with your table and image of table (your table has width of text).; (ii) off-topic: \caption should not be inside tabularx environment
    – Zarko
    Commented Oct 2, 2018 at 15:33
  • 1
    Your code doesn't even load tabularx!
    – Bernard
    Commented Oct 2, 2018 at 15:55
  • 2
    please always post a complete small document that shows the problem, I would guess you are using the ltablex package but you do not say. Commented Oct 2, 2018 at 16:16

1 Answer 1

3

enter image description here

This is a ltablex "feature" which you can turn off as shown, however there is no reason to stretch the tabular, it just makes it harder to read, if you use a centered tabular it is fine.

\documentclass[12pt]{article}
\usepackage{ltablex,booktabs}
\keepXColumns
\begin{document}


\begin{tabularx}{\textwidth}{lX}
\caption{cccc} \\
\toprule
\textbf{Definition} & \textbf{Counts} \\
\midrule

\textit{A}             &  68\\ 
\textit{B}             &  10\\
\textit{C}             &  10\\
\midrule
$\sum$                 &  88\\

\bottomrule
\end{tabularx}

\end{document}
1
  • Carlile: I found the solution! It looks it's not enough to add \keepXColumns, as you suggested, but I had to tweak a bit the line \begin{tabularx}{\textwidth}{lX} to the following one \begin{tabularx}{\linewidth}{Xr}
    – Jo-Achna
    Commented Oct 2, 2018 at 16:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .