2

The following posts provides a solution for adding a full stop at the end of hanging captions, but I'm encountering issues when applying this in the context of xltabular.

Can I extend this functionality to also work for captions in xltabular? I would love to get help!

Below is a minimal working example (MWE). It demonstrates the successful implementation of adding a full stop to hanging captions but also illustrates the issue with xltabular table captions where the full stop is not being added.

\documentclass{article}

\usepackage{amsthm} % Adds a full stop at the end of each caption automatically (if there is none) \usepackage{caption} % Use 'caption' Package \usepackage{xltabular} % Load 'xltabular' package

\makeatletter % Custom caption format based on the original hang format with "ABC" appended \DeclareCaptionFormat{customhang}{% \caption@iflabelseparatorwithnewline {\caption@Error{% The option labelsep=\caption@labelsep@name' does not work\MessageBreak withformat=customhang'}}% {@hangfrom{#1#2}% \advance\caption@parindent\hangindent\relax \advance\caption@hangindent\hangindent\relax \caption@@par#3}} \NewDocumentCommand{\CUSTOMcaption}{sO{#3}m}{% \IfBooleanTF{#1}{% \CAPTIONcaption*[#2@addpunct{.}]{#3@addpunct{.}}% }{% \CAPTIONcaption[#2@addpunct{.}]{#3@addpunct{.}}% }% } \makeatother

\captionsetup{format=customhang}

\AtBeginDocument{% \NewCommandCopy\CAPTIONcaption\caption \RenewCommandCopy\caption\CUSTOMcaption }

\begin{document}

% ACTUAL ISSUE OCCURS HERE \begin{xltabular}{\linewidth}{X} DEMO \ \caption{Samle with xltabular} % Here a full stop should be added, but currently is not being added! \end{xltabular}

% Just to ensure that the new solution also works with normal captions inside figures: \begin{figure} \centering \caption{This is an example caption} \caption{Another sample with a very long caption and we hope that it will properly break into the next line with proper hanging...} \end{figure}

\end{document}

Mico
  • 506,678
Highnoon
  • 45
  • 6
  • Should the desired fixed apply only to "hanging" captions in your document, or should it apply to all captions? Please clarify. – Mico Nov 23 '23 at 05:34
  • 2
    I've taken the liberty of adding the instruction \usepackage{xltabular} in the preamble to make the sample compilable. Feel free to revert. – Mico Nov 23 '23 at 05:42
  • 2
    I'm definitely just using hanging captions - so if it makes things easier, then it's sufficient to work only with hanging captions. And thanks for the edit! – Highnoon Nov 23 '23 at 18:17
  • Would you be ok with a LuaLaTeX-based solution? Or do you have to use pdfLaTeX to compile your documents? – Mico Nov 23 '23 at 20:37
  • Sadly I have to use pdfLaTeX :/ – Highnoon Nov 23 '23 at 21:09

0 Answers0