使用全部列表更改标题的位置

使用全部列表更改标题的位置

我对 的标题位置有疑问lstlisting

这是一个最小的例子

\documentclass[12pt]{toptesi}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% INCLUSIONE PACCHETTI
\usepackage[utf8]{inputenc} %utf8
\usepackage[italian]{babel}
\usepackage[T1]{fontenc}
\usepackage{blindtext}
\usepackage{graphicx,wrapfig}
\usepackage{booktabs}
\usepackage{lmodern}
\usepackage{varioref}
\usepackage{url}
\usepackage{array}
\usepackage{paralist}{\obeyspaces\global\let =\space}
\usepackage{verbatim}
\usepackage{subfig}
\usepackage{tabularx}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{float}
\usepackage{amssymb}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{listings}
\usepackage[pass]{geometry}
\usepackage[figuresright]{rotating}
\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{amsmath}
\usepackage[babel]{csquotes}
\usepackage{hyperref}
\usepackage[backend=bibtex]{biblatex}
\usepackage{xcolor}
\usepackage{enumitem}
\usepackage{titlesec}

% CONFIGURAZIONE LISTATI/CODICE
\definecolor{commentgreen}{RGB}{2,112,10}
\definecolor{eminence}{RGB}{108,48,130}
\definecolor{weborange}{RGB}{255,165,0}
\definecolor{frenchplum}{RGB}{129,20,83}

\lstset {
    language=C++,
    frame=tb,
    tabsize=4,
    showstringspaces=false,
    numbers=left,
    %upquote=true,
    commentstyle=\color{commentgreen},
    keywordstyle=\color{eminence},
    stringstyle=\color{red},
    basicstyle=\small\ttfamily, % basic font setting
    emph={int,char,double,float,unsigned,void,bool},
    emphstyle={\color{blue}},
    escapechar=\&,
    % keyword highlighting
    classoffset=1, % starting new class
    otherkeywords={>,<,.,;,-,!,=,~},
    morekeywords={>,<,.,;,-,!,=,~},
    keywordstyle=\color{weborange},
    classoffset=0,
}

% definizione BITCOIN script
\lstdefinelanguage{bitcoinscript}{
    alsodigit = {-},
    keywords = {OP_DUP,OP_HASH160,OP_EQUALVERIFY,OP_CHECKSIG, OP_CHECKMULTISIG,
                OP_0, OP_2, OP_3, OP_EQUAL},
}

%Definizione MINISCRIPT
\lstdefinelanguage{miniscript}{
    keywords = {thresh,pk,older},
}

\begin{document}

\begin{lstlisting}[label={code:enumtx}, caption={Porzione di codice che riporta il tipo enumerazione nel file standard.h di bitcoin core.}]

enum txnouttype
{
    TX_NONSTANDARD,
    TX_PUBKEY,
    TX_PUBKEYHASH,
    TX_SCRIPTHASH,
    TX_MULTISIG,
    TX_NULL_DATA, //!< unspendable OP_RETURN script that carries data
    TX_WITNESS_V0_SCRIPTHASH,
    TX_WITNESS_V0_KEYHASH,
    TX_WITNESS_UNKNOWN, //!< Only for Witness versions not already defined above
};
\end{lstlisting}

\end{document}

这就是结果

在此处输入图片描述

在这个结果中,我有两个问题,

  1. 第 1 行溢出
  2. 标题位于顶部位置,但我希望它位于按钮位置

答案1

您可以使用captionpos=b 将标题放在列表下方而不是上方,同时breaklines=true通过允许换行来帮助避免行溢出:

在此处输入图片描述

\documentclass[12pt]{toptesi}

\usepackage{subfig}
\usepackage{listings}
\usepackage[pass]{geometry}
\usepackage{xcolor}

\definecolor{commentgreen}{RGB}{2,112,10}
\definecolor{eminence}{RGB}{108,48,130}
\definecolor{weborange}{RGB}{255,165,0}

\lstset {
    language=C++,
    frame=tb,
    tabsize=4,
    showstringspaces=false,
    numbers=left,
    %upquote=true,
    commentstyle=\color{commentgreen},
    keywordstyle=\color{eminence},
    stringstyle=\color{red},
    basicstyle=\small\ttfamily, % basic font setting
    emph={int,char,double,float,unsigned,void,bool},
    emphstyle={\color{blue}},
    escapechar=\&,
    % keyword highlighting
    classoffset=1, % starting new class
    otherkeywords={>,<,.,;,-,!,=,~},
    morekeywords={>,<,.,;,-,!,=,~},
    keywordstyle=\color{weborange},
    classoffset=0,
    captionpos=b,
    breaklines=true
}


\begin{document}

\begin{lstlisting}[label={code:enumtx}, caption={Porzione di codice che riporta il tipo enumerazione nel file standard.h di bitcoin core.}]

enum txnouttype
{
    TX_NONSTANDARD,
    TX_PUBKEY,
    TX_PUBKEYHASH,
    TX_SCRIPTHASH,
    TX_MULTISIG,
    TX_NULL_DATA, //!< unspendable OP_RETURN script that carries data
    TX_WITNESS_V0_SCRIPTHASH,
    TX_WITNESS_V0_KEYHASH,
    TX_WITNESS_UNKNOWN, //!< Only for Witness versions not already defined above
};
\end{lstlisting}

\end{document}

相关内容