2

I'm writing an article with the IEEEtran template, which have two columns.

I'd like to have a listing with source code that spans the two columns of the article, like in the attached figure.

I'm using the following command: \lstinputlisting[frame=single, caption={blablabla}, label={blablabla}]{listings/blablabla.java}

Does anybody know how to do it?

enter image description here

  • by span you mean continuing in the second column from first or occupying the space that is pagewide instead of using only one column? It's much easier to work with an example if you include a short and compilable one – percusse Oct 6 '14 at 23:00
  • in an analogy with a figure, this is a code that spans two columns: \begin{figure*}...\end{figure*} i'd like to have a listing that behaves like that. sorry if a didn't put a code, but it's exactly what I want to discover. – Bruno Cartaxo Oct 6 '14 at 23:10
  • You can at least put the listing code that you want to make it span instead of us making up random nonsense. – percusse Oct 6 '14 at 23:11
  • \lstinputlisting[frame=single, caption={blablabla}, label={blablabla}]{listings/blablabla.java} – Bruno Cartaxo Oct 6 '14 at 23:12
  • Related: IEEE-Template: Algorithm over both columns – Werner Oct 7 '14 at 0:51
5
\documentclass{IEEEtran} 
\usepackage{listings,multicol}  % <--- multicol only required, if the multicols= option shall be used
\usepackage{filecontents}       % <--- only needed to provide example code
\usepackage{lipsum}             % <--- only needed to provide dummy text

\lstset{language=Java, basicstyle=\ttfamily\footnotesize}

\begin{filecontents*}{stuff.java}
package awt;

import java.awt.Frame;
import java.awt.Label;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class Hello {

  public static void main(String[] args) {
    Frame f=new Frame("Hello World example of awt application");
    Label label1=new Label("Hello World", Label.CENTER);
    f.add(label1);

    f.setSize(300,100);
    f.setVisible(true);
    f.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent event) {
        System.exit(0);
      }
    });
  }
}
\end{filecontents*}


\begin{document}


\lipsum
\lstinputlisting[float=*t, caption={A wide listing float, single column}]{stuff.java}
\lstinputlisting[float=*, multicols=2, caption={A wide listing float, itself dobule-column}]{stuff.java}
\lipsum
\lipsum
\end{document}

enter image description here

| improve this answer | |
4

Until now I didn't find a way to make a listing span two colums using the command that reads the code from a file (\lstinputlisting).

However, I managed how to do it by putting the code in the latex document, as follows:

\begin{lstlisting}[float=*]
code goes here
\end{lstlisting}
| improve this answer | |
0

Actually this can be done using \lstinputlisting. Here is the example for a C file:

\usepackage{listings}

\lstinputlisting[language=C,float=*,basicstyle=\footnotesize]{filename.c}

Change the language and basicstyle according to your source file and document requirements.

| improve this answer | |

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.