在 `xltabular` 中强制在悬挂字幕末尾使用句号

在 `xltabular` 中强制在悬挂字幕末尾使用句号

关注帖子提供了在悬挂字幕末尾添加句号的解决方案,但我在 的上下文中应用该解决方案时遇到了问题xltabular

我可以扩展此功能以用于字幕吗xltabular?我很乐意获得帮助!

下面是一个最小工作示例 (MWE)。它演示了向悬挂标题添加句号的成功实现,同时也说明了 xltabular 表格标题中未添加句号的问题。

\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
       with `format=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}

相关内容