18

How do I place a two column appendix in a single column report? I want it so that at the beginning of the appendix I'm in single column mode, then I want to place some source code listings in 2 column format within my appendix.

Thanks

Eddy
  • 1,875

3 Answers3

23

For multi-column typesetting of listings the listings package provides the multicols=n option, which in fact is a built-in interface to the multicol package.

\documentclass{report} 
\usepackage{listings,multicol}
\usepackage{lipsum}
\begin{document}
\chapter{foo}
\lipsum[1]
\begin{lstlisting}[numbers=left,xleftmargin=3em, multicols=2]
First line.
Second line.
Third line.
Next line.
Next Line
Next line.
Next Line
Next line.
Next Line
Next line.
Next Line
\end{lstlisting}
\lipsum[2]
\end{document}

Note that you have to load multicol explicitly with \usepackage{multicol} in the preamble.

Daniel
  • 37,517
8

You can use the package multicol or you can switch your document via \twocolumn in the new mode:

\documentclass{report} 
\usepackage{listings}
\usepackage{multicol}
\usepackage{lipsum}
\begin{document}
\chapter{foo}
\lipsum[1]
\begin{multicols}{2}
\begin{lstlisting}[numbers=left,xleftmargin=3em]
First line.
Second line.
Third line.
Next line.
Next Line
Next line.
Next Line
Next line.
Next Line
Next line.
Next Line
\end{lstlisting}
\end{multicols}
\lipsum[2]
\clearpage
\twocolumn
\lipsum[1]
\lipsum[2]
\begin{lstlisting}[numbers=left,xleftmargin=3em]
First line.
Second line.
Third line.
Next line.
Next Line
Next line.
Next Line
Next line.
Next Line
Next line.
Next Line
\end{lstlisting}
\lipsum[2]
\end{document}
Marco Daniel
  • 95,681
4

With the standard report class, you may use \twocolumn to switch to two column mode:

\documentclass[a5paper]{report}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{listings}

\begin{document}
\blinddocument
\appendix
\twocolumn
\chapter{Here and now! The two column listing}
\lstinputlisting[{language=[LaTeX]TeX},breaklines=true]{\jobname.tex}

\onecolumn
\chapter{One more chapter in one column mode}
\blindtext

\end{document}

But with this, you may not have additional one column text after the \chapter. With KOMA-Script \chapter may be used inside the optional argument of \twocolumn:

\documentclass[a5paper]{scrreprt}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{listings}

\begin{document}
\blinddocument
\appendix
\twocolumn[%
  \chapter{Here and now! The two column listing}
  \blindtext

  \vspace*{\baselineskip}
]


\lstinputlisting[{language=[LaTeX]TeX},breaklines=true]{\jobname.tex}

\onecolumn
\chapter{One more chapter in one column mode}
\blindtext

\end{document}

But there's a alround suggestion for the standard classes too: multicol

\documentclass[a4paper]{report}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{listings}
\usepackage{multicol}

\begin{document}
\blinddocument
\appendix
\chapter{Here and now! The two column listing}
\blindtext

\begin{multicols}{2}
\lstinputlisting[{language=[LaTeX]TeX},breaklines=true]{\jobname.tex}
\end{multicols}

\chapter{One more chapter in one column mode}
\blindtext

\end{document}

And this is indeed the same like

\documentclass[a4paper]{report}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{listings}
\usepackage{multicol}

\begin{document}
\blinddocument
\appendix
\chapter{Here and now! The two column listing}
\blindtext

\lstinputlisting[{language=[LaTeX]TeX},breaklines=true,multicols=2]{\jobname.tex}

\chapter{One more chapter in one column mode}
\blindtext

\end{document}

Note, that if you are using option multicols you have to load package multicol. Package listings does not load multicol itself!

For more information about \begin{multicols}{…}[…] please have a look at the package manual.

Schweinebacke
  • 26,336