The Oxford Bioinformatics journal's template is one of my favorites and I use it for many of my school assignments. The template uses a two-column layout, but in an appendix at the end of the document I would like to include some source code. This of course looks horrible in the two-column layout, but I have been unable to suppress the two-column mode using multicol
macros. Is there any way I can do this?
3 Answers
Just put \onecolumn
before the appendix. Note that the commands \onecolumn
and \twocolumn
start a new page.
You can put your source code inside a starred version of figure which will span both the columns in a two column document ( a misuse but for good).
\usepackage{graphicx}
\begin{figure*}
\begin{verbatim}
Your source code here.
\end{verbatim}
\caption{The source code for bla bla bla}
\label{source-1}
\end{figure*}
But these starred versions will either put the figure in a new page of their own or at the top of the page. (htbp do not work so neatly) To cure this one can load
\usepackage{dblfloatfix}
in the preamble. Then the place holders option [tbp] can be used to put the figure at top, bottom of the page or in a new page. But [h] will still not be available.
Reference: wikibook
Insert the following in the preamble to be able to have full width code, and multicolumn text:
\usepackage{xcolor,listings,etoolbox,multicol,lipsum}
\lstnewenvironment{Code}[1][]
{\lstset{language=[LaTeX]TeX}\lstset{%
breaklines=true,
framesep=5pt,
basicstyle=\ttfamily,
showstringspaces=false,
keywordstyle=\ttfamily\textcolor{blue},
stringstyle=\color{orange},
commentstyle=\color{black},
rulecolor=\color{gray!10},
breakatwhitespace=true,
showspaces=false, % shows spacing symbol
xleftmargin=0pt,
xrightmargin=5pt,
aboveskip=0pt, % compact the code looks ugly in type
belowskip=0pt, % user responsible to insert any skips
backgroundcolor=\color{gray!15}, #1
}}
{}
\makeatletter
%% Hack to have one column environments for Code
\def\multicols@string{multicols}
\BeforeBeginEnvironment{Code}{%
\ifx\@currenvir\multicols@string
\xdef\resume@multicols{\noexpand\begin{multicols}{\number\col@number}}%
\end{multicols}%
\else
\global\let\resume@multicols\@empty
\fi}
\AfterEndEnvironment{Code}{\resume@multicols}
\makeatother
In the Appendix code is written as:
\onecolumn
\begin{multicols}{2}
\lipsum[2]
\begin{Code}
......
\end{Code}
\end{multicols}
As a general suggestion add text in between code fragments rather than a long code listing it will look better.
\figure*
environment and put your source code inside.