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}
\usepackage{xltabular}in the preamble to make the sample compilable. Feel free to revert. – Mico Nov 23 '23 at 05:42