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 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}
share|improve this question
    
    
@MarcoDaniel I tried but it doesn't work unfortunately =/ –  Cemre Aug 11 '12 at 10:38
1  
@Cemre: your example does not compile. \documentclass, \begin{document}, ... are missing. A complete MWE one can copy to run it without changes or writing extra code. Please complete it. –  Kurt Aug 11 '12 at 10:49
    
@Kurt Sorry it should be ok now –  Cemre Aug 11 '12 at 10:55
1  
Use \sloppy to allow breaks –  Marco Daniel Aug 11 '12 at 10:55

1 Answer 1

up vote 3 down vote accepted

The UK-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}
share|improve this answer
    
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. –  Peter Grill Aug 11 '12 at 15:39
    
@PeterGrill: If I put \sloppy outside the group it won't work local. –  Marco Daniel Aug 11 '12 at 18:21
    
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. –  Peter Grill Aug 11 '12 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 '12 at 0:11

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.