0

I have a problem with the position of the caption with the lstlisting.

This is a minimal example

\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}

This is the result

enter image description here

In this result, I have 2 problems,

  1. The line 1 is overflow
  2. the caption in the top position but I want it in the button position
4
  • 1
    Could you please edit your code to include a complete compilable minimal working example (MWE) that includes the documentclass, as well as the relevant packages. Currently, your preamble snippet is filled with a bunch of unrelate packages. Also, the file exampleComplexNoMiniscript.btcs is not available to us. – leandriis Oct 4 '19 at 20:23
  • captionpos=b might help to place the caption below the listing instead of above while breaklines=true might help to prevent to overflowing line. – leandriis Oct 4 '19 at 20:24
  • @leandriis I have updated my question, sorry my superficiality – vincenzopalazzo Oct 4 '19 at 20:42
  • @leandriis your solution works well thanks – vincenzopalazzo Oct 4 '19 at 20:42
1

You can use captionpos=b to place the caption below the listing instead of above while breaklines=true hleps to avoid overflowing lines by allowing linebreaks:

enter image description here

\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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.