lstlisting over whole text width in twocolumn article in latex

2.2k views Asked by At

I have an article in latex that has two columns. I am also using the lstlisting package to display code, and want the code two span over both columns similar to how \begin{figure*} works. If I place the listing in \onecolumn \twocolumn the listing is placed on a page by its own, but I would like the listing on the same page as text.

\documentclass[APA,STIX2COL]{WileyNJD-v2}
\lstdefinestyle{basic}{
    numbers= none,
    numberstyle=\scriptsize,
    basicstyle=\ttfamily\scriptsize,
    tabsize=2, 
    breaklines=true, 
    backgroundcolor=\color{black!10}
}
\begin{document}
\begin{lstlisting} [style=basic,float,floatplacement=htbp]
public class Main {
  public static void main(String[] args) {
    System.out.println("Hello, World!");
  }
}
\end{lstlisting}
\end{document}

Document class can be found here https://www.overleaf.com/latex/templates/a-demonstration-of-the-latex-class-file-for-wiley-njd-journals/bfwqvgnbgcjc

1

There are 1 answers

0
user14199933 On

Use Figure. For example:

\begin{figure*}[t]
\begin{lstlisting}
......
......
\end{lstlisting}
\end{figure*}