Every figure, table, formula and listing in my document has a caption that ends with a period. The problem is, that these periods are also displayed in the ToC, which they shouldn't.

I found a similar question which had the goal of removing trailing periods from the section numbers by preventing them from getting written to the .aux file:

\def\remove@@dot\csname the#1\endcsname{\Roman{#1}}

However, I haven't figured out a way to do the same for the captions themselves - that being said, I am pretty new to LaTeX. Of course it would be possible to provide a second argument without the period to the \caption command to specify a short spelling, that is used for the ToC, like this: \caption[Some caption]{Some caption.}, but these are redundancies I'd rather avoid.



%% Setup for list of equations
%% ========================================

%% Actual document
%% ========================================

%% Example elements with captions ending in a period
    \caption{Some figure.}

    \caption{Some table.}

\end{equation}\eqcaption{Some equation.}

\begin{lstlisting}[caption={Some code.}]


1 Answer 1


So I found a solution that works, but definitely isn't perfect.

For figures and tables I override the default \caption command to gobble the trailing period, if present, but only for the ToC entry.



The same goes for the equation captions, with the only difference being that the command is already custom, so that wasn't a problem.


Finally for the listings I tried to patch the underlying TeX macro via xpatch but couldn't get it to work, so instead I added a new command that defines two values which I use for the caption parameter - one with the period and the other one without it.


\lstcaption{Some code}

I also added the functionality that a period will automatically be appended to the caption, if it wasn't explicitly specified.

You must log in to answer this question.

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