'caption' 包未调整 'minted' 中 'listing' 环境中的标题

'caption' 包未调整 'minted' 中 'listing' 环境中的标题

看来该包caption无法调整列表中的标题minted。在下面的示例中,figuretable环境的标题受 影响\captionsetup,但环境的标题listing不受影响:

\documentclass[a4paper, 12pt]{article}

\usepackage{caption}
\usepackage{parskip}
\usepackage{fontspec}
\usepackage{cite}
\usepackage[nonumberlist]{glossaries}
\usepackage{hyperref}
\usepackage{xcolor}
\usepackage[margin=2cm]{geometry}
\usepackage{graphicx}
\usepackage{array}
\usepackage{mfirstuc}
\usepackage[official]{eurosym}
\usepackage{minted}

\graphicspath{{./images/}}

\setmonofont{Courier New}
\definecolor{bg}{rgb}{0.85, 0.85, 0.85}
\setmintedinline{bgcolor=bg}
\setminted{bgcolor=bg, linenos}
\renewcommand{\theFancyVerbLine}{\small\arabic{FancyVerbLine}}
\captionsetup[table]{skip=40pt}
\captionsetup[figure]{skip=40pt}
\captionsetup[listing]{skip=40pt}

\begin{document}
    
    \begin{listing}[H]
        \begin{minted}[gobble=12]{python}
            def f(x):
                return x**2
            
            if __name__=="__main__":
                x = 3
                y = f(x)
                print(y)
        \end{minted}
        \caption{A python code block}
        \label{lst:python-code-block}\end{listing}

    \begin{figure}[H]
        \centering
        \label{fig:banana}
        \includegraphics[scale=1.0]{banana.jpg}
        \caption{my-caption}
    \end{figure}

    \begin{table}[h]
        \caption{Simple table caption}
        \label{tab:my-simple-table}
        \centering
        \begin{tabular}{|c|c|c|c|}
            \hline
            Right &
            Left &
            Center &
            Default \\
            \hline\hline
            12 &
            12 &
            12 &
            12 \\
            \hline
            123 &
            123 &
            123 &
            123 \\
            \hline
            1 &
            1 &
            1 &
            1 \\
            \hline
        \end{tabular}
    \end{table}
\end{document}

有没有办法使用该caption包来调整环境的字幕listing?如果没有,我该如何调整环境的字幕间距minted listing

答案1

minted使用密钥加载包newfloat

\usepackage[newfloat=true]{minted}

listing将使用该包创建新类型的浮点数newfloat(更现代)。

\documentclass[a4paper, 12pt]{article}

\usepackage{caption}
\usepackage{parskip}
\usepackage{fontspec}
\usepackage{cite}
\usepackage[nonumberlist]{glossaries}
\usepackage{hyperref}
\usepackage{xcolor}
\usepackage[margin=2cm]{geometry}
\usepackage{graphicx}
\usepackage{array}
\usepackage{mfirstuc}
\usepackage[official]{eurosym}
\usepackage[newfloat=true]{minted}

\graphicspath{{./images/}}

\setmonofont{Courier New}
\definecolor{bg}{rgb}{0.85, 0.85, 0.85}
\setmintedinline{bgcolor=bg}
\setminted{bgcolor=bg, linenos}
\renewcommand{\theFancyVerbLine}{\small\arabic{FancyVerbLine}}
\captionsetup[table]{skip=40pt}
\captionsetup[figure]{skip=40pt}
\captionsetup[listing]{skip=40pt}

\begin{document}
    
    \begin{listing}
        \begin{minted}[gobble=12]{python}
            def f(x):
                return x**2
            
            if __name__=="__main__":
                x = 3
                y = f(x)
                print(y)
        \end{minted}
        \caption{A python code block}
        \label{lst:python-code-block}\end{listing}

    \begin{figure}
        \centering
        \label{fig:banana}
        \includegraphics[scale=1.0]{banana.jpg}
        \caption{my-caption}
    \end{figure}

    \begin{table}
        \caption{Simple table caption}
        \label{tab:my-simple-table}
        \centering
        \begin{tabular}{|c|c|c|c|}
            \hline
            Right &
            Left &
            Center &
            Default \\
            \hline\hline
            12 &
            12 &
            12 &
            12 \\
            \hline
            123 &
            123 &
            123 &
            123 \\
            \hline
            1 &
            1 &
            1 &
            1 \\
            \hline
        \end{tabular}
    \end{table}
\end{document}

上述代码的输出

相关内容