使用listing
和词法minted
分析器pycon
来模拟 IPython 控制台,我想将标题字体大小更改为\footnotesize
。不幸的是,下面的代码不会改变标题“标题”的字体大小,即“清单 1:”的字体大小不会改变。
由于 IEEEtran 文档类,我无法使用标题包。
\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}
答案1
您可以listing
使用与 相同的标题设置figure
。
通过查看listing
包装可以找到以下方法:
\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}
答案2
对于这个特定方法,不推荐使用这种方法,documentclass
因为它以自己的方式处理字幕,而这种方式会破坏此功能。
由于您并没有真正分享您真正期望的输出,因此有一个可能的解决方案:
\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}