2

I am using the caption package to create captions and subcaptions (with \caption*{}) below my figures. I simply want to change the text format of the subcaption to italic. I have a vague feeling that this should be possible via \captionsetup{} but I don't know how. I don't want to use the subcaptions package if possible.

Here is a minimal example:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{caption}
\usepackage[demo]{graphicx} % demo is just for the example

\begin{document}

\begin{figure}[t] \includegraphics[width=\textwidth,height=2cm]{x} \caption{Test 1} \caption*{This is the subtext to be placed below the caption of the figure. I want this to be in italic without having to type textit every time} \label{fig:test1} \end{figure}

\end{document}

BeSeLuFri
  • 109
  • Maybe this (https://tex.stackexchange.com/questions/822/change-the-font-of-figure-captions) answers your question? – Excelsior May 11 '21 at 13:30
  • @Excelsior - thank you very much for the link! But this only changes the caption text that follows the label (i.e. "Test 1" in my example). But I want to ONLY change the subcaption text to italic. Any idea how I could do that? – BeSeLuFri May 11 '21 at 13:40

1 Answers1

3

It appears that the caption package does not provide the ability to change the style only for the \caption* command. The simplest way I can see is to define a new \subcaption command in this way:

\newcommand{\subcaption}[1]{\caption*{\itshape #1}}

MWE

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{caption}
\usepackage[demo]{graphicx} % demo is just for the example

\newcommand{\subcaption}[1]{\caption*{\itshape #1}}

\begin{document}

\begin{figure}[t] \includegraphics[width=\textwidth,height=2cm]{x} \caption{Test 1} \subcaption{This is the subtext to be placed below the caption of the figure. I want this to be in italic without having to type textit every time} \label{fig:test1} \end{figure}

\end{document}

enter image description here

Ivan
  • 4,368
  • works like a charm - thank you very much! Just out of interest: what is the #1 in \newcommand{\subcaption}[1]{\caption*{\itshape #1}} for? – BeSeLuFri May 11 '21 at 14:09
  • #1stands for the first (and only) argument of \subcaption which is indeed defined as a command with one argument ([1]). In other words \subcation{<text>} simply expands to \caption*{\itshape <text>}, i.e. it substitutes #1 with the argument passed to \subcaption – Ivan May 11 '21 at 14:19
  • thank you - very helpful! – BeSeLuFri May 11 '21 at 14:26