1

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!

2
  • 1
    You might try the strip environment from the cuted package (sttools bundle). It won't be a float any more, so you'll have to use \captionof{listing}{...}
    – Bernard
    Jul 30, 2018 at 15:01
  • @Bernard Yes, now the code snippets are in two columns, but the background color bgcolor=bg or frame=single is appearing only in the left column (on the left part of the listing). (btw, I had to remove the properties of [...breaklines, breakafter=d...] too. Jul 30, 2018 at 18:02

1 Answer 1

1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .