4

I have a code listing as shown in the picture (number 4) that goes a bit out of the margin although breaklines=true. When I try to break new line it gives me an error Listings Error: lstinline ended by EOL. How can I break this up so that the arguments line up in a more elegant way like:

 computeInitialValues(const Query& query,
                      const std::vector<const Array*> &objects,
                      std::vector< std::vector<unsigned char>> &values,
                      bool &hasSolution)

enter image description here

EDIT: Code sample:

\documentclass[a4paper,11pt,twoside]{report}
\usepackage[left=2.5cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage{amsmath, graphicx, tikz, enumerate, amssymb, pgf}
\usepackage{fancyhdr}
\usepackage{setspace}
\usepackage{pgfplots}
\usepackage{slashbox}
\usepackage{bchart}
\usepackage{float}
\usepackage{caption}
\raggedbottom
\usepackage[bottom]{footmisc}

\usepackage{listings}
\usepackage{color}
\usepackage{textcomp}
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\lstset{
%frame=tb,
   language=C++,
   aboveskip=3mm,
   belowskip=3mm,
   showstringspaces=false,
   columns=flexible,
   basicstyle=\ttfamily\footnotesize\bfseries,
   numbers=none,
   numberstyle=\tiny\color{gray},
   commentstyle=\color{dkgreen},
   breaklines=true,
   breakatwhitespace=true,
   tabsize=3
}
\begin{document}

\lstinline$bool computeInitialValues(const Query& query, const vector<const Array*>& objects, vector<vector<unsigned char>>& values, bool& hasSolution )$ computes the initial values for a list of objects.   

\end{document}
5
  • @MarcoDaniel I tried but it doesn't work unfortunately =/
    – Cemre
    Aug 11, 2012 at 10:38
  • 1
    Use \sloppy to allow breaks Aug 11, 2012 at 10:55
  • Thanks @MarcoDaniel it worked. Please post it as an answer so I can accept it. Also, thanks everyone for taking their time to help as well.
    – Cemre
    Aug 11, 2012 at 10:59
  • @Cemre: Done. Hope it helps Aug 11, 2012 at 11:38

1 Answer 1

4

The TeX FAQ describes your behavior in the article (La)TeX makes overfull lines

In your case the command \sloppy helps. To avoid \tolerance9999 for the whole document you must set \sloppy local.

Please note the following sentence from the FAQ:

\sloppy ... can allow pretty poor-looking breaks

Here an real minimal example without non-related packages:

\documentclass{report}
\usepackage{listings}
\lstset{basicstyle=\ttfamily,breaklines=true}
\begin{document}
{\sloppy\lstinline$bool computeInitialValues(const Query& query, const vector<const Array*>& objects, vector<vector<unsigned char>>& values, bool& hasSolution )$} computes the initial values for a list of objects.   

\end{document}
4
  • In this case there does not appear to be any different in the output with or without \sloppy. I am not sure, but think it has to do with there not being an end of paragraph within which \sloppy is to apply as the output it better if you move the \sloppy outside of the brace group. Aug 11, 2012 at 15:39
  • @PeterGrill: If I put \sloppy outside the group it won't work local. Aug 11, 2012 at 18:21
  • 1
    Yes I agree. But the MWE you provided does not show any difference with, or without the addition of \sloppy. Now that I re-read it, my earlier comment does not seem very clear. What I meant was that applying \sloppy outside of the brace group does show that it works in this MWE. It works inside only if there is another paragraph. So applying something like \endgraf at the end makes it work. But perhaps there is a better way to do this that I am not aware of. Aug 11, 2012 at 18:34
  • @PeterGrill local \sloppy didn't work at first (it only worked if it wasn't local) as you said but than I extended the range of braces a bit which made it work but I am not sure why
    – Cemre
    Aug 12, 2012 at 0:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .