将短标题(用于图表列表)与长标题的一部分同步

将短标题(用于图表列表)与长标题的一部分同步

我想动态地将长标题的第一句话复制到短标题中以生成图形列表。每当我对长标题进行更改时,短标题都会相应更新。

更准确地说,我希望为我的所有图形标题提供某种 setter-getter 机制。

\caption[text_A_getter]{text_A_setter. text_B.}

我可以将 textA 保存到文件中,但发现同时维护大量图形很困难。

答案1

不确定这是否真的是最好的想法并且实用,但您可以使用命令并在需要时重新定义它:

在此处输入图片描述

\documentclass{article}
\newcommand{\firstsent}{}
\begin{document}

\listoffigures

\begin{figure}
\renewcommand{\firstsent}{This is the first sentence.}
\caption[\firstsent]{\firstsent{} And here comes the rest of the long caption.}
\end{figure}

\begin{figure}
\renewcommand{\firstsent}{This caption gets a different first sentence.}
\caption[\firstsent]{\firstsent{} Remaining text}
\end{figure}

\end{document}

相关内容