1

This table works OK. However,

\begin{tabularx}{\textwidth}{lllX}
    \toprule
    A & B & C & D\\
    \midrule

    A & B & C & aaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaa \\
    \hline

\end{tabularx}

when I change the font size, as in the next table,

\begin{tabularx}{\textwidth}{lllX}
    \toprule
    A & B & C & D\\
    \midrule
    \footnosize
    A & B & C & aaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaa \\
    \hline
\end{tabularx}

I get the error message:

Undefined control sequence. \end{tabularx}.

Also, I cannot add a caption; if I do,

\begin{tabularx}{\textwidth}{lllX}
    \toprule
    A & B & C & D\\
    \midrule
    \caption{ABC}
    A & B & C & aaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaa \\
    \hline
\end{tabularx}

I get a list of error messages:

! You can't use `\hrule' here except with leaders.
\caption@hrule ->\hrule 
                        \@height \z@ 
l.167 \end{tabularx}

To put a horizontal rule in an hbox or an alignment,
you should use \leaders or \hrulefill (see The TeXbook).

! Missing number, treated as zero.
<to be read again> 
                   \vskip 
l.167 \end{tabularx}

A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)

! Illegal unit of measure (pt inserted).
<to be read again> 
                   \vskip 
l.167 \end{tabularx}
...

I have worked around the title issue by adding the line \captionof{table}{\textbf{Inflation categories}} before \begin{tabularx}, but the downside is that the title and table can end up in different pages.

How can I solve this issues?

EDIT 1 After the messages below, this is a working solution:

\begin{table}
    \caption{ABC}
    \footnotesize
    \begin{tabularx}{\textwidth}{lllX}
    \toprule
    A & B & C & D\\
    \midrule

    A & B & C & aaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaa \\
    \hline
\end{tabularx}
\end{table}

I had a typo in \footnotesize and tabularx needs to be encapsulated by table.

6
  • 2
    If you wrote ``\footnotesize` instead of \foonosize? For the caption, it has to be inside of a tableenvironment, like this: \begin{table}\caption{ABC}\label{some label}\begin{tabularx}{lllX} ..... \end{tabularx} \end{table}.
    – Bernard
    Commented Dec 9, 2019 at 18:11
  • 2
    Undefined control sequence. \end{tabularx}. is not the format of a tex error message. the tex error would show you which command is undefined. (look in the log file) Commented Dec 9, 2019 at 18:33
  • 2
    do you use texstudio? Commented Dec 9, 2019 at 18:33
  • @Bernard Your comments solved the issue. Commented Dec 9, 2019 at 18:48
  • 2
    please consider leaving a comment here sourceforge.net/p/texstudio/feature-requests/1068 I know nothing about texstudio but it is so depressing that I can recognise its use, just by user confusion over undefined commands. They really could fix this. Commented Dec 9, 2019 at 18:58

1 Answer 1

3

When I compile the following document,

\documentclass{article}
\usepackage{tabularx,booktabs}
\begin{document}
\begin{tabularx}{\textwidth}{lllX}
    \toprule
    A & B & C & D\\
    \midrule
    \footnosize
    A & B & C & aaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaaaaaa aaaaa aaaaa \\
    \hline
\end{tabularx}
\end{document}

I get the following error message:

! Undefined control sequence.
<recently read> \footnosize 

l.11 \end{tabularx}

Thus, it is \footnosize, not \end{tabularx}, that's the subject of the complaint. What to do? Just in case it's not painfully obvious: change \footnosize to \footnotesize.

I assume you're aware that the \footnotesize directive doesn't affect the entire row, but only the first cell of the row in question.

To apply a \caption to this table, it's necessary to embed the tabularx environment in a table environment, something like this:

\begin{table}
\caption{Stuff} \label{tab:stuff}
\begin{tabularx}{\textwidth}{lllX}
...
\end{tabularx}
\end{table}

You must log in to answer this question.

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