2

With listing and minted and a pycon lexer to emulate an IPython console, I'd like to change the caption font size to be \footnotesize. Unfortunately, my code below does not change the fontsize of the caption "heading" i.e. the fontsize of "Listing 1:" does not change.

I can't use the caption package because of the IEEEtran document class.

\documentclass[journal,12pt,onecolumn,draftclsnofoot,]{ieee_template/IEEEtran/IEEEtran}
\usepackage{listing}    
\usepackage[usenames, dvipsnames]{color}

\usepackage{minted}
\definecolor{bg}{rgb}{0.95,0.95,0.95}
\newminted{pycon}{bgcolor=bg, linenos=true, tabsize=4}

\begin{document}

    \begin{listing}[]% * for across both columns
        \begin{minted}[mathescape, frame=lines, framesep=2mm, fontsize=\footnotesize]{pycon} 
        In [1]: %run listing_minted_demo.py
        Hello World!
        x = 3 + 2 
        \end{minted}
    \caption[]{\footnotesize{Example caption. I'd like the caption AND the label Listing 1 to be footnotesize.}}
    %\label{mwe}
    \end{listing}

\end{document}

Here's the output (see "Listing 1" is typeset in a larger font): enter image description here

1
  • 2
    Hey and welcome to tex.sx. Your MWE is not compiling well (e.g. you have \usepackages before the \documentclass). Could you fix this? This will make it easier for others to help you. And maybe also specify what exactly you're asking, as this is not clear from your post.
    – sheß
    Commented Mar 2, 2019 at 13:06

2 Answers 2

2

You can make listing to use the same setup for the caption as figure.

Looking in the listing package one finds the way:

\documentclass[journal,12pt,onecolumn,draftclsnofoot]{IEEEtran}
\usepackage{listing}    
\usepackage[usenames, dvipsnames]{color}

\usepackage{minted}
\definecolor{bg}{rgb}{0.95,0.95,0.95}

\newminted{pycon}{bgcolor=bg, linenos=true, tabsize=4}

% let `listing` use the same caption format as figure
\makeatletter
\let\@float@c@listing\@caption
\makeatother

\begin{document}

\begin{listing}[htp]% * for across both columns
\begin{minted}[mathescape, frame=lines, framesep=2mm, fontsize=\footnotesize]{pycon} 
In [1]: %run listing_minted_demo.py
Hello World!
x = 3 + 2 
\end{minted}
\caption{Example caption. I'd like the caption AND the label Listing 1 to be footnotesize.}
\label{mwe}
\end{listing}

\begin{figure}[htp]
\fbox{\rule{0pt}{3cm}\rule{3cm}{0pt}}
\caption{Example caption}
\end{figure}

\end{document}

enter image description here

1
  • @problemofficer Maybe you have some reason; but downvoting before asking is rude, on this site.
    – egreg
    Commented Nov 28, 2021 at 20:49
0

Non-recommended way for this specific documentclass because it handles captions its own way and this way breaks this functionality.

A possible solution since you don't really share what you really expect as output:

\documentclass[journal,12pt,onecolumn,draftclsnofoot,]{IEEEtran}
\usepackage[usenames, dvipsnames]{color}
\usepackage{listing}
\usepackage{minted}
\usepackage{caption}
\captionsetup{font={normalsize}, textfont={sf}, labelfont={bf,sf}}
\definecolor{bg}{rgb}{0.95,0.95,0.95}
\newminted{pycon}{bgcolor=bg, linenos=true, tabsize=4}

\begin{document}

    \begin{listing}[]% * for across both columns
        \begin{minted}[mathescape, frame=lines, framesep=2mm, fontsize=\footnotesize]{pycon} 
        In [1]: %run listing_minted_demo.py
        Hello World!
        x = 3 + 2 
        \end{minted}
        \captionsetup{font={footnotesize}}
    \caption[]{\footnotesize Example caption. I'd like the caption AND the label Listing 1 to be footnotesize.}
    %\label{mwe}
    \end{listing}

\end{document}

enter image description here

5
  • Why normalsize and not footnotesize as the OP seems to want a footnotesize caption (See the contents of the caption command: 'I'd like the caption AND the label Listing 1 to be footnotesize.' ?
    – leandriis
    Commented Mar 2, 2019 at 13:26
  • @leandriis I did it for the specific caption... may be (s)he don't want this option to be global across the document and the post doesn't share enough details. This way I give more possible choices to every usage because I used \captionsetup globally but locally too.
    – koleygr
    Commented Mar 2, 2019 at 13:28
  • I'm sorry, I have overlooked the local definition of the caption's font. Apart from that, combining the caption package and IEEEtran documentclass seems to be discuraged in the documentation ('[...] caption.sty, which, in its default con-figuration, will overrride IEEEtran’s handling of captions — resulting in non-IEEE style main captions' (see page 10)) and also results in a corresponding warning.
    – leandriis
    Commented Mar 2, 2019 at 13:31
  • @leandriis thanks... I forgot that! You are right... I will add a non-suggested comment on the top of my answer (and a non-suggested documentclass in this comment :P )
    – koleygr
    Commented Mar 2, 2019 at 13:33
  • Sorry for the confusion. When I first posted, my explanatory text before the Latex was omitted. Hopefully, what I have added helps.
    – ljk07
    Commented Mar 2, 2019 at 13:40

You must log in to answer this question.

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