2

While trying to rename a long table from 'Table 11' (automatically assigned by latex) to 'Table A.5' I got problems while using \renewcommand{\thetable}{A.5}. The problem is that the caption text is out of bound and Latex reports the error " Misplaced not align" and "Misplaced omit".

While hoping to sufficiently clearly explain the problem, Could You please help me to solve this issue?

Thanks in advance.

I report a screenshot of my code to help You understand the problem. Note that of course at the end of the long table I coded: "end{\longtable}.

enter image description here

1 Answer 1

1

Next time please help us to help you by providing a MWE in text form not as screenshot so that we can copy the code and try our answer.

This looks like a xy problem to me. Could it be that you are actually trying to reset the table counter every time another counter is incremented and use both counters to reference the table? If so the newfloat package can help you.

In the following example the table counter is reset at the end of each section and both the section counter and table counter are printed by \caption.

Please note that I have redefined \thesection instead of \thetable to match the format requested while avoiding an inconsistency between using sometimes numbers and sometimes letters for the same counter.

\documentclass{article}
\usepackage{longtable}
\usepackage[within=section]{newfloat}
% see https://en.wikibooks.org/wiki/LaTeX/Counters#Counter_style
\renewcommand{\thesection}{\Alph{section}}

\begin{document}
    \section{Abcdef}
    \begin{longtable}{ll}
        \caption{Abc}
    \end{longtable}
    \begin{longtable}{ll}
        \caption{Def}
    \end{longtable}

    \section{Ghijkl}
    \begin{longtable}{ll}
        \caption{Ghi}
    \end{longtable}
    \begin{longtable}{ll}
        \caption{Jkl}
    \end{longtable}
\end{document}

enter image description here

As a side note I would recommend taking a look at the booktabs package documentation which gives a few recommendations on how to format tables.


To answer the question that you have asked:

The problem is that \renewcommand inserts unexpandable tokens before \caption. If you really want to change the numbering of a single table only (which I would discourage without knowing the context) redefine \thetable before the table and keep the definition local with an explicit \begingroup ...\endgroup:

\documentclass{article}
\usepackage{longtable}

\begin{document}
    \begingroup
    \renewcommand{\thetable}{A.5}
    \begin{longtable}{ll}
        \caption{Abc}
    \end{longtable}
    \endgroup

    \begin{longtable}{ll}
        \caption{Def}
    \end{longtable}
\end{document}

enter image description here

You must log in to answer this question.

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