5

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. – TeXnician Apr 20 '17 at 9:36
  • I know that, but how is defined \selectfont? – Alex Pacini Apr 20 '17 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). – TeXnician Apr 20 '17 at 9:54
  • 1
  • 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}. – Alex Pacini Apr 20 '17 at 10:06
6

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}

enter image description here

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? – Alex Pacini Apr 20 '17 at 12:11
  • 1
    @Alex Look in the class file for the definition of \@makecaption. – egreg Apr 20 '17 at 12:12
3

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):

picture

\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}? – Alex Pacini Apr 20 '17 at 10:22
  • @Alex Well, yes and no, it is possible, but you have to enter the specifications yourself. – TeXnician Apr 20 '17 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! – Alex Pacini Apr 20 '17 at 10:28
  • I rephrased the OP to include the last question. – Alex Pacini Apr 20 '17 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.