Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
2  
Try the \figure* environment and put your source code inside. –  Harish Kumar Mar 24 '12 at 14:43
    
@HarishKumar Excellent idea. I tried it myself, and it would have worked...except that the source code is longer than a single page. :( –  Daniel Standage Mar 24 '12 at 15:23
add comment

3 Answers

up vote 5 down vote accepted

Just put \onecolumn before the appendix. Note that the commands \onecolumn and \twocolumn start a new page.

share|improve this answer
    
This worked. Thanks! –  Daniel Standage Mar 25 '12 at 3:27
add comment

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

share|improve this answer
add comment

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}

enter image description here

As a general suggestion add text in between code fragments rather than a long code listing it will look better.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.