使用可选参数\caption
可以更改放入图形列表中的条目。我在论文中使用的样式始终为图形添加“标题”或“标题”,即我使用 以粗体打印的标题的一小部分textbf
。在我的情况下,这始终与我放入标题可选参数中的内容相同:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\begin{document}
\listoffigures
\newpage
\begin{figure}[h!]
\centering
\includegraphics{example-image-a}
\caption[The universe]{\textbf{The Universe}\\Some very long description of this image that should not be in the list of figures...}
\label{fig:universe}
\end{figure}
\end{document}
现在,我The universe
同时拥有了图表列表中的条目和标题开头的粗体行。但是,有没有办法自动实现这一点?我经常会不小心只更改其中一个,例如,最后得到
\caption[Something new]{\textbf{The Universe}\\Some very long description of this image that should not be in the list of figures...}
现在在哪里Something new
!=The Universe
答案1
定义新命令\captionx
\newcommand{\captionx}[2]{\caption[#1]{\textbf{#1}\\ #2}}
用作
\captionx{Something new!}{Some very long description of this image that should not be in the list of figures...}
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\newcommand{\captionx}[2]{\caption[#1]{\textbf{#1}\\ #2}} % added <<<<<<<<<<<<<<<<
\begin{document}
\listoffigures
\newpage
\begin{figure}[h!]
\centering
\includegraphics{example-image-a}
\caption[The universe]{\textbf{The Universe}\\Some very long description of this image that should not be in the list of figures...}
\label{fig:universe}
\end{figure}
\begin{figure}[h!]
\centering
\includegraphics{example-image-b}
\captionx{Something new!}{Some very long description of this image that should not be in the list of figures...} % <<<<<<<<<<<<<<
\label{fig:new}
\end{figure}
\end{document}