如何在铸造清单上方制作标题?

如何在铸造清单上方制作标题?

我正在使用minted包来处理我的代码:

\begin{listing}[htbp]
\begin{minted}[baselinestretch=1, 
                linenos, 
                xleftmargin=1.5em,
                breaklines]{solidity}
contract Delegate {
    address public owner;
    function pwn() {
        owner = msg.sender;
    }  }
contract Delegation {
    address public owner;
    Delegate delegate;
    function() {
      if(delegate.delegatecall(msg.data)) {
        this;
    }  }  }
\end{minted}
\caption{The Triangle example}
\label{list:triangle}
\end{listing}

但包裹总是给我这样的:

在此处输入图片描述

我的问题是如何使该代码看起来像:

在此处输入图片描述

答案1

我使用包(由 加载)的命令\floatstyle和。\newfloat\floatnamefloatminted

\documentclass{article}
\usepackage{minted}

\floatstyle{ruled}
\newfloat{listing}{H}{lox}
\floatname{listing}{\strut Listing}

\begin{document}

\begin{listing}[htbp]
\begin{minted}[baselinestretch=1, 
                linenos, 
                xleftmargin=2em,
                breaklines]{solidity}
contract Delegate {
    address public owner;
    function pwn() {
        owner = msg.sender;
    }  }
contract Delegation {
    address public owner;
    Delegate delegate;
    function() {
      if(delegate.delegatecall(msg.data)) {
        this;
    }  }  }
\end{minted}
\caption{The Triangle example}
\label{list:triangle}
\end{listing}

\end{document}

上述代码的输出

相关内容