[Tex/LaTex] A single column Listing with Minted into a two column layout document

listingsmintedtwo-column

I have a two column document:

\documentclass[twocolumn]{elsarticle}

\usepackage{minted}
\usepackage{caption}
\captionsetup[listing]{position=top}
\usepackage{listings}

\begin{document}

\begin{listing}[H]
\begin{minted}[linenos=true, breaklines, breakafter=d, fontsize=\small]{java} 
public class Line extends IShape {
    /*...*/
}
\end{minted}
\caption{File Line.java}
\label{lst:example}
\end{listing}

\end{document}

I'm also using minted for listings, but I want to show some of them into a single column while the document remains into two columns. I tried \begin{listing*}...\end{listing*}, but it didn't work. Is there a simple way to achieve this? Thank you!

Best Answer

Use listings*; the code will be set at the top of a page (H makes no sense).

\documentclass[twocolumn]{elsarticle}

\usepackage{minted}
\usepackage{caption}
\usepackage{listings}

\usepackage{kantlipsum} % for mock text

\captionsetup[listing]{position=top}

\begin{document}

\kant

\begin{listing*}
\begin{minted}[linenos=true, breaklines, breakafter=d, fontsize=\small]{java} 
public class Line extends IShape {
    /*...*/
}
a long line which shows that we are using a single column even if the document is in twocolumn format
\end{minted}
\caption{File Line.java}
\label{lst:example}
\end{listing*}

\kant

\end{document}

enter image description here