我的标题如下:
图 1.1 | 一张船的图片(标题):
这艘船有蓝色的帆,是木制的(描述)。
但我想要:
图 1.1 | 一张船的图片(标题):这艘船有蓝色的帆,是木制的(描述)。
这是我的代码:
\usepackage[labelsep=pipe,font=small,labelfont={sf,bf},justification=RaggedRight]{caption}
\newcommand{\img}[4]{
\begin{figure}[H]
\centering
\includegraphics[width=#2\linewidth]{#1}
\caption{\textsf{\textbf{#3:}}}\nolinebreak[4]#4
\label{img:#1}
\end{figure}
}
\img{file.jpg}{0.5}{A picture of a boat (caption):}{This boat has a blue sail and is made of wood (description).}
非常感谢!(这是我的第一篇帖子,希望没问题)
解决方案
归功于Torbjørn T.\caption 能够显示图片列表中的内容,即 \caption[LoF entry]{my caption text}。重要提示:要获得结果,需要编译两次。因此,我的新代码是:
\usepackage[labelsep=pipe,font=small,labelfont={sf,bf},justification=RaggedRight]{caption}
\newcommand{\img}[4]{
\begin{figure}[H]
\centering
\includegraphics[width=#2\linewidth]{#1}
\caption[#3]{\textsf{\textbf{#3: }} #4}
\label{img:#1}
\end{figure}
}
\img{file.jpg}{0.5}{A picture of a boat (caption):}{This boat has a blue sail and is made of wood (description).}
答案1
这是您的设置的键值实现,如果您将来想改变主意,则可以提供更多的灵活性:
\documentclass{article}
\usepackage{caption,ragged2e}
\DeclareCaptionLabelSeparator{pipe}{ $\vert$ }
\captionsetup{
labelsep=pipe,
font={small,sf,bf},
justification=RaggedRight
}
\usepackage{xkeyval,float,graphicx}
\makeatletter
\define@cmdkey{myimages}[img@]{file}{}
\define@cmdkeys{myimages}[img@]{width,caption,description,label}[\relax]{}
\newcommand{\insertimage}[1]{%
\begin{figure}[H]
\setkeys{myimages}{file={}, width, caption, description, label,#1}
\centering
\expandafter\ifx\img@width\relax
\includegraphics{\img@file}%
\else
\includegraphics[width=\img@width]{\img@file}%
\fi
\expandafter\ifx\img@caption\relax\else
\caption[\img@caption]{\img@caption \expandafter\ifx\img@description\relax.\else~(caption): {\normalfont \img@description~(description).}\fi}
\expandafter\ifx\img@label\relax\else
\label{\img@label}%
\fi
\fi
\end{figure}
}
\makeatother
\begin{document}
\listoffigures
\insertimage{
file=example-image,
width=0.3\linewidth,
caption={A picture of a boat},
description={This boat has a blue sail and is made of wood},
label=img:boat
}
\insertimage{
file=example-image-a,
width=100pt,
caption={A picture of a fish}
}
\insertimage{
file=example-image-b,
width=.25\linewidth,
description={A picture of a whale}
}
\end{document}
假设如果您不提供caption
,则无需提供description
(即使您提供了,也不会设置)。 类似地,对于label
。此外,后缀(caption)
和(description)
会自动添加,而不会插入到 LoF 中。
从根本上讲, 和caption
都description
放入 中\caption
,只是字体格式不同。