0

I have two listings which are my Makefile sources. Some lines in this Makefiles are long. I need to fit them side by side in a particular location in my report. I tried to do something like this but I was not successful.

\documentclass[12pt, a4paper, titlepage]{scrartcl}

\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{graphicx}
\graphicspath{{./Figures/}}

\usepackage{url}
%\usepackage{titlesec}
%\newcommand{\sectionbreak}{\clearpage}
\usepackage{dirtree}
\usepackage{color}
\usepackage{listings}
\usepackage{caption}

%to get clickable links from table of contents
\usepackage{hyperref}
\hypersetup{
    colorlinks,
    citecolor=black,
    filecolor=black,
    linkcolor=black,
    urlcolor=black
}
\newcommand{\courierword}[1]{\textsf{\itshape #1}}{\fontfamily{pcr}\selectfont}%

\setlength{\parindent}{0.0cm}
\setlength{\parskip}{1ex}

\setkomafont{sectioning}{\normalcolor\bfseries}

The actual content is as below

\begin{figure}[!ht]
\begin{minipage}{.5\textwidth}
\captionof{figure}{Makefile for 'aocs' Collection}
\lstset{language=make,
        commentstyle=\color{red},
        breaklines=true,
}
\begin{lstlisting}[frame=single][t]
This section contains my Makefile 2
Some lines are really toooooooooooooooooooooooooooooooooo long
\end{lstlisting}
\end{minipage}%
\begin{minipage}{.5\textwidth}
\captionof{figure}{Makefile for 'aocsApFw' Constituent}
\lstset{language=make,
        commentstyle=\color{red},
        breaklines=true,
}
\begin{lstlisting}[frame=single][t]
This section contains my Makefile 2
Some lines are really toooooooooooooooooooooooooooooooooo long
\end{lstlisting}
\end{minipage}
\end{figure}
1
  • 1
    Would a landscape page be an option? Or setting them on a left/right page pair? The bets font I found for long lines in listings was Latin Modern TT Condensed; that might help a lot. – Chris H Feb 22 '17 at 12:08
1

Some remarks to your code:

  1. Your are using the listings option frame. Due to this your listings itself get wider. The new listings has the width:

    framerule+framesep+0.5\linewidth+framesep+framerule
    

    To take care of this you have to add the following option:

    xleftmargin=3.4pt,xrightmargin=3.4pt,
    
  2. With the option breaklines=true listings can break to long lines. However the breaks occurs only at characters declared as other. The following table shows the default definition (see documentation) enter image description here

  3. The environent minipage has an optional argument do adjust the vertical position. In Your case you can use t. Please note that caption needs the same amount of lines.

Here is the modication of your code with the result

\documentclass[12pt, a4paper, titlepage]{scrartcl}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{graphicx}
\graphicspath{{./Figures/}}

\usepackage{url}
%\usepackage{titlesec}
%\newcommand{\sectionbreak}{\clearpage}
\usepackage{dirtree}
\usepackage{color}
\usepackage{listings}
\usepackage{caption}

%to get clickable links from table of contents
\usepackage{hyperref}
\hypersetup{
    colorlinks,
    citecolor=black,
    filecolor=black,
    linkcolor=black,
    urlcolor=black
}
\newcommand{\courierword}[1]{\textsf{\itshape #1}}{\fontfamily{pcr}\selectfont}%

\setlength{\parindent}{0.0cm}
\setlength{\parskip}{1ex}

\setkomafont{sectioning}{\normalcolor\bfseries}


\begin{document}
\begin{figure}[!ht]
\begin{minipage}[t]{.5\textwidth}
\caption{Makefile for 'aocs' Collection}\par\strut
\lstset{language=make,breakatwhitespace=false,xleftmargin=3.4pt,xrightmargin=3.4pt,
        commentstyle=\color{red},
        breaklines=true,
}
\begin{lstlisting}[frame=single][t]
This section contains my Makefile 2
Some lines are really tooooooooooooooo ooooooooooooooooooo long
\end{lstlisting}
\end{minipage}%
\begin{minipage}[t]{.5\textwidth}
\caption{Makefile for 'aocsApFw' Constituent}
\lstset{language=make,,xrightmargin=3.4pt,,xleftmargin=3.4pt,
        commentstyle=\color{red},
        breaklines=true,
}
\begin{lstlisting}[frame=single][t]
This section contains my Makefile 2
Some lines are really toooooooooooooooo oooooooooooooooooo long
\end{lstlisting}
\end{minipage}
\end{figure}
\end{document}

enter image description here

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.