# Set the font of the caption in a subfigure to the same of the figure

I am writing a paper using the IEEEtranTIE template (provided by IEEE Transaction on Industrial Electronics).

They slightly modified the IEEEtran template and one of the edits is a change in the caption font.

To obtain the information about the fonts I used the following macro:

\makeatletter
\newcommand{\showfont}{
Encoding: \f@encoding{},
Family: \f@family{},
Series: \f@series{},
Shape: \f@shape{},
Size: \f@size{}.
}
\makeatother


Using \caption{\showfont} I get Encoding: T1, Family: phv, Series: m, Shape: n, Size: 8. When I add a subfigure using the subcaption package as indicate by IEEEtran

\makeatletter
\let\MYcaption\@makecaption
\makeatother
\usepackage[labelformat=simple,font=footnotesize]{subcaption}
\makeatletter
\let\@makecaption\MYcaption
\renewcommand{\thesubfigure}{(\roman{subfigure})}
\makeatother


and I write a caption in a sub figure I get a different family. \subcaption{\showfont} gives Encoding: T1, Family: ptm, Series: m, Shape: n, Size: 8.. In order to have a consistent look&feel I would like to set the same font family (phv) but slightly smaller (7). How can be this obtained?

As a side question, is it possible to obtain a font of a certain environment and to assign it to an another environment?

Something like (pseudo-code):

\edef\subcaptionfont\captionfont


or (to be honest I still struggle to understand when to use \the):

\edef\subcaptionfont{\the\captionfont}


Possibly with also the ability to change some fields, like size or font family.

A MWE (the IEEEtranTIE class can be downloaded from the link above):

\documentclass[journal]{IEEEtranTIE}
\usepackage[pdftex,demo]{graphicx}
\usepackage{lipsum}

\makeatletter
\let\MYcaption\@makecaption
\makeatother

\usepackage[labelformat=simple,font=footnotesize]{subcaption}

\makeatletter
\let\@makecaption\MYcaption
\renewcommand{\thesubfigure}{(\roman{subfigure})}
\makeatother

\makeatletter
\newcommand{\showfont}{
Encoding: \f@encoding{},
Family: \f@family{},
Series: \f@series{},
Shape: \f@shape{},
Size: \f@size{}.
}
\makeatother

\title{Title}

\author{Author}

\begin{document}
\maketitle

\begin{abstract}
\lipsum[1-2]
\end{abstract}

\section{title}
\lipsum[1-3]

\begin{figure}[h]
\begin{subfigure}{\columnwidth}
\includegraphics[width=\textwidth]{dummy}
\subcaption{\showfont}
\label{fig1}
\end{subfigure}
\caption{\showfont}
\label{fig0}
\end{figure}

\end{document}


--EDIT-- With the help of @TeXnician I was able to get the desired result. The result is obtained by changing the part where subcaption is loaded, namely

\usepackage[labelformat=simple,font=footnotesize]{subcaption}


with

\usepackage[labelformat=simple]{subcaption}
\DeclareCaptionFont{myfont}{\fontfamily{phv}\scriptsize\sele‌​ctfont}
\captionsetup[sub]{font=myfont}


The last part of the question is still valid and can be rephrased as follows.

Is it possible to set the subcaption font to inherit the same of the caption using something similar to (but not a working example since \thecaptionfont is not a valid command):

\usepackage[labelformat=simple]{subcaption}
\DeclareCaptionFont{myfont}{\thecaptionfont\scriptsize\selec‌​tfont}
\captionsetup[sub]{font=myfont}


?

• Have a look at \DeclareCaptionFont{name}{\myfont\selectfont} (documentation of caption) which you can use as parameter for subcaption instead of footnotesize. Then select font family and size with usual macros. Apr 20, 2017 at 9:36
• I know that, but how is defined \selectfont? Apr 20, 2017 at 9:53
• If you know it why don't you use it? \selectfont is a macro defined by LaTeX which changes the font (only using \fontsize or similar is not enough). Apr 20, 2017 at 9:54
• Apr 20, 2017 at 10:03
• Because I would like to find a way to inherit from the caption font. Maybe by hand can be done using: \DeclareCaptionFont{myfont}{\fontfamily{phv}\fontsize{7}{\baselineskip}\selectfont}. Apr 20, 2017 at 10:06

In my opinion, you shouldn't use caption or subcaption with that class.

Anyway, since the font used in captions is \footnotesize\sffamily, you can get away with

\documentclass[journal]{IEEEtranTIE}
\usepackage[demo]{graphicx}
\usepackage{lipsum}

\makeatletter
\let\MYcaption\@makecaption
\makeatother

\usepackage[labelformat=simple,font={footnotesize,sf}]{subcaption}

\makeatletter
\let\@makecaption\MYcaption
\renewcommand{\thesubfigure}{(\roman{subfigure})}
\makeatother

\makeatletter
\newcommand{\showfont}{
Encoding: \f@encoding{},
Family: \f@family{},
Series: \f@series{},
Shape: \f@shape{},
Size: \f@size{}.
}
\makeatother

\title{Title}

\author{Author}

\begin{document}
\maketitle

\begin{abstract}
\lipsum[1-2]
\end{abstract}

\section{title}
\lipsum[1-3]

\begin{figure}[h]
\begin{subfigure}{\columnwidth}
\includegraphics[width=\textwidth]{dummy}
\subcaption{\showfont}
\label{fig1}
\end{subfigure}
\caption{\showfont}
\label{fig0}
\end{figure}

\end{document}


Here is the setup with subfig, which is compatible with the class.

\documentclass[journal]{IEEEtranTIE}
\usepackage[demo]{graphicx}
\usepackage{lipsum}

\usepackage[caption=false]{subfig}

\captionsetup[subfloat]{font={footnotesize,sf}}

\makeatletter
\newcommand{\showfont}{
Encoding: \f@encoding{},
Family: \f@family{},
Series: \f@series{},
Shape: \f@shape{},
Size: \f@size{}.
}
\makeatother

\title{Title}

\author{Author}

\begin{document}
\maketitle

\begin{abstract}
\lipsum[1-2]
\end{abstract}

\section{title}
\lipsum[1-3]

\begin{figure}[htp]
\subfloat[\showfont\label{fig1}]{%
\includegraphics[width=\columnwidth]{dummy}%
}
\caption{\showfont}
\label{fig0}
\end{figure}

\end{document}


The output is the same.

• Thanks a lot! Anyway, how do you know it is \footnotesize\sffamily? Is it something that should be obvious or is there a systematic way to find it? Apr 20, 2017 at 12:11
• @Alex Look in the class file for the definition of \@makecaption. Apr 20, 2017 at 12:12

Here's a working version setting the font to ptm for both captions. Feel free to change it to another font (if you want that you'd have to change the caption font too):

\documentclass[journal]{IEEEtran}
\usepackage[demo]{graphicx}
\usepackage{lipsum}

\makeatletter
\let\MYcaption\@makecaption
\makeatother

\usepackage[compatibility=false]{caption}
\DeclareCaptionFont{quackfont}{\fontfamily{ptm}\fontsize{7pt}{9pt}\selectfont}
\usepackage[labelformat=simple,font=quackfont]{subcaption}

\makeatletter
\let\@makecaption\MYcaption
\renewcommand{\thesubfigure}{(\roman{subfigure})}
\makeatother

\makeatletter
\newcommand{\showfont}{
Encoding: \f@encoding{},
Family: \f@family{},
Series: \f@series{},
Shape: \f@shape{},
Size: \f@size{}.
}
\makeatother

\title{Title}

\author{Author}

\begin{document}
\maketitle

\begin{abstract}
\lipsum[1-2]
\end{abstract}

\section{title}
\lipsum[1-3]

\begin{figure}[h]
\begin{subfigure}{\columnwidth}
\includegraphics[width=\textwidth]{dummy}
\subcaption{\showfont}
\label{fig1}
\end{subfigure}
\caption{\showfont}
\label{fig0}
\end{figure}

\end{document}

• Is it possible to possible to set the font as the same of the caption as (not working example (\thecaptionfont is not a valid command)): \usepackage[labelformat=simple]{subcaption} \DeclareCaptionFont{myfont}{\thecaptionfont\scriptsize\selectfont} \captionsetup[sub]{font=myfont}? Apr 20, 2017 at 10:22
• @Alex Well, yes and no, it is possible, but you have to enter the specifications yourself. Apr 20, 2017 at 10:26
• Ah, I see, It can not be inherited directly from the caption font then... In the end I used: \usepackage[labelformat=simple]{subcaption} \DeclareCaptionFont{myfont}{\fontfamily{phv}\scriptsize\selectfont} \captionsetup[sub]{font=myfont}. Thanks a lot for your help! Apr 20, 2017 at 10:28
• I rephrased the OP to include the last question. Apr 20, 2017 at 10:45