1

I need to use different caption setups for different figures (tables). For example, if the title of a figure (table) is a single line, it should be centered, otherwise it should be justified and hanging. I saw the following codes concerning caption setups on the site.

\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}

I adapted the above code as follows.

\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}

However, captions disappeared. Would you assist me? Many thanks in advance! Best regards.

1 Answer 1

3

To long for the comment ...

What you after is standard features of caption. You not need to declare separate caption setup:

\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}

enter image description here

1
  • It totally worked. I appreciate that. I'm so sorry I didn't think of such a simple solution :)
    – Burak
    Nov 1, 2023 at 7:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .