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.

I am trying to make a side by side comparison of the result of listing-mode and minted-mode for a piece of Ruby and Java-code. I have problems making this look 'side by side'. Any suggestions to make the programming code appear side by side?

 % !TEX TS-program = pdflatex
% !TEX encoding = UTF-8 Unicode

% This is a simple template for a LaTeX document using the "article" class.
% See "book", "report", "letter" for other types of document.

\documentclass{article} % use larger type; default would be 10pt

\usepackage[utf8]{inputenc} % set input encoding (not needed with XeLaTeX)

%%% Examples of Article customizations
% These packages are optional, depending whether you want the features they provide.
% See the LaTeX Companion or other references for full information.

%%% PAGE DIMENSIONS
\usepackage{geometry} % to change the page dimensions
\geometry{a4paper} % or letterpaper (US) or a5paper or....
% \geometry{margin=2in} % for example, change the margins to 2 inches all round
% \geometry{landscape} % set up the page for landscape
%   read geometry.pdf for detailed page layout information

\usepackage{graphicx} % support the \includegraphics command and options

% \usepackage[parfill]{parskip} % Activate to begin paragraphs with an empty line rather than an indent

%%% PACKAGES
\usepackage{booktabs} % for much better looking tables
\usepackage{array} % for better arrays (eg matrices) in maths
\usepackage{paralist} % very flexible & customisable lists (eg. enumerate/itemize, etc.)
\usepackage{verbatim} % adds environment for commenting out blocks of text & for better verbatim
\usepackage{subfig} % make it possible to include more than one
                    % captioned figure/table in a single float
\usepackage{multicol}
\usepackage{xcolor}
\usepackage{minted}
\usepackage{listings}
\lstloadlanguages{Ruby}
\lstloadlanguages{Java}
\lstset{%
basicstyle=\ttfamily\color{black},
commentstyle = \ttfamily\color{red},
keywordstyle=\ttfamily\color{blue},
stringstyle=\color{orange}}

% These packages are all incorporated in the memoir class to one degree or another...

%%% HEADERS & FOOTERS
\usepackage{fancyhdr} % This should be set AFTER setting up the page geometry
\pagestyle{fancy} % options: empty , plain , fancy
\renewcommand{\headrulewidth}{0pt} % customise the layout...
\lhead{}\chead{}\rhead{}
\lfoot{}\cfoot{\thepage}\rfoot{}

%%% SECTION TITLE APPEARANCE
\usepackage{sectsty}
\allsectionsfont{\sffamily\mdseries\upshape} % (See the fntguide.pdf for font help)
% (This matches ConTeXt defaults)

%%% ToC (table of contents) APPEARANCE
\usepackage[nottoc,notlof,notlot]{tocbibind} % Put the bibliography in the ToC
\usepackage[titles,subfigure]{tocloft} % Alter the style of the Table of Contents
\renewcommand{\cftsecfont}{\rmfamily\mdseries\upshape}
\renewcommand{\cftsecpagefont}{\rmfamily\mdseries\upshape} % No bold!

%%% END Article customizations

%%% The "real" document content comes below...

\title{Verschil listing of minted syntax hightlighting \\ Een onderzoekje}

\author{ir. G.M. Borkent}
%\date{} % Activate to display a given date or no date (if empty),
         % otherwise the current date is printed 

\begin{document}
\maketitle

\section{Verschil tussen listing en minted syntax highlighting}
\subsection{Vergelijking Ruby}
\begin{minipage}[b]{0.5\linewidth}
\centering
Listing-mode:
\begin{lstlisting}[language=Ruby]

#this is a comment

a = 5
b = a * 5
puts b
puts b + 3

class Test < Test::SomeClass
@test = 3
    def bar
        if foo
            puts "foo"
        else
            puts "bar"
        end
    end
end
\end{lstlisting}
\end{minipage}
\begin{minipage}[b]{0.5\linewidth}
\centering
\noindent
Minted-mode:
\begin{minted}{ruby}
#this is a comment

a = 5
b = a * 5
puts b
puts b + 3

class Test < Test::SomeClass
@test = 3
    def bar
        if foo
            puts "foo"
        else
            puts "bar"
        end
    end
end
\end{minted}
\end{minipage}

\subsection{Vergelijking Java}
\begin{minipage}[b]{0.5\linewidth}
\centering
\noindent
Listing-mode
\begin{lstlisting}[language=Java]
public static void main(String[] args) {
    int a = 3;
}
\end{lstlisting}

\end{minipage}

\begin{minipage}[b]{0.5\linewidth}
\centering
\noindent
Minted-mode
\begin{minted}{java}

public static void main(String[] args) {
    int a = 3;
}
\end{minted}

\end{minipage}

\section{Conclusie}
Minted-mode ziet er mooier uit\ldots 

\end{document}
share|improve this question
    
Welcome to TeX.sx! We prefer full but minimal working example (MWE) that illustrates the problem and allow people to compile it for themselves with no hassle. Then proposed solution can directly be added, tested and presented in an answer. –  Martin Scharrer Oct 9 '11 at 11:40
    
Added my complete code, hopefully it is minimal enough... –  Michiel Borkent Oct 9 '11 at 11:51
add comment

1 Answer

up vote 4 down vote accepted

You need either to allow line breaks (option breaklines for listings), use a smaller font size to fit the text on the \columnwidth, or scale the code environments directly to \columnwidth using \Resizebox{\columnwidth}{!}{<content>} (realboxes package) or \begin{adjustbox}{width=\columnwidth} ... \end{adjustbox} (adjustbox package). Note that the normal \scalebox or \resizebox doesn't work with verbatim content.


Edit:

It seems that minted environments can't be saved in boxes (I get a Something's wrong--perhaps a missing \item. error), which breaks the use of adjustbox. I already noted before that the LaTeX part of minted isn't very good implemented. Looking at the code I even see that unwanted spaces are introduces, which is kind of a beginner error. You might want to simply lower the font size until it fits, e.g. use \scriptsize around the code environments.

share|improve this answer
    
Tnx, I lowered the fontsize until fit and also switched back to multicols instead of minipages. The result is good enough for me now: dl.dropbox.com/u/3914693/syntax-highlighting.pdf –  Michiel Borkent Oct 9 '11 at 12:30
    
There should be no more whitespaces introduced by the minted package. If you find any, please contact me. That said, there are probably a lot of beginner’s errors in the package. –  Konrad Rudolph Nov 6 '11 at 2:36
    
@MichielBorkent Could you add the LaTeX code of your solution? (Your PDF is no longer accessible at the URL.) This is a useful topic! –  Jodi Schneider Aug 31 '13 at 9:15
1  
@JodiSchneider For your convenience I have added the src + pdf here: dl.dropboxusercontent.com/u/3914693/syntax-highlighting.zip –  Michiel Borkent Aug 31 '13 at 10:49
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.