我需要对不同的图形(表格)使用不同的标题设置。例如,如果图形(表格)的标题是单行,则应居中,否则应两端对齐并悬挂。我在网站上看到了有关标题设置的以下代码。
\documentclass{article}
\usepackage{caption}
\DeclareCaptionFormat{tfigureFormat}{#1#2#3\hrulefill}
\DeclareCaptionFormat{bfigureFormat}{\hrulefill\par\medskip#1#2#3}
\begin{document}
\captionsetup[figure]{format=tfigureFormat}
\begin{figure}[!t]
...
\end{figure}
\captionsetup[figure]{format=bfigureFormat}
\begin{figure}[!t]
...
\end{figure}
\end{document}
我对上述代码进行了如下修改。
\documentclass{article}
\usepackage{caption}
\DeclareCaptionFormat{single}{\captionsetup[figure]{labelsep=period,justification=centering}}
\DeclareCaptionFormat{multiple}{\captionsetup[figure]{format=hang,labelsep=period,justification=justified}}
\begin{document}
\captionsetup[figure]{format=single}
\begin{figure}[!t]
...
\end{figure}
\captionsetup[figure]{format=multiple}
\begin{figure}[!t]
...
\end{figure}
\end{document}
但是,字幕消失了。你能帮我吗?提前谢谢!谨致问候。
答案1
太期待评论了...
您追求的是字幕的标准功能。您不需要声明单独的字幕设置:
\documentclass{article}
\usepackage{graphicx}
\usepackage[format=hang,labelsep=period]{caption} % this is sufficient
\begin{document}
\begin{figure}[!ht]
\centering
\includegraphics[height=33mm]{example-image-a}
\caption{one line caption, centered}
\end{figure}
\begin{figure}[!ht]
\centering
\includegraphics[height=33mm]{example-image-b}
\caption{two lines long line caption which has a hang format two lines long line caption which has a hang format}
\end{figure}
\end{document}