5

My code is being formatted in a way that makes it drift off the page when it's too long rather than just jump to a new line. I have tried lots of different things, pasted all kinds of examples from the answers on here for code formatting but none of it seems to stop the lengthy bits from going over. I don't know why it is happening so I am at a loss on how to fix it.

Here is an example of the worst offending (it just goes right out the page for no good reason)

 \documentclass{article}
 \usepackage[margin=2cm]{geometry}
 \usepackage[svgnames]{xcolor}
\usepackage{changepage}
\usepackage{framed}
\usepackage{tikz}
\usepackage{listings}
\usepackage{bbding}


    \lstset{backgroundcolor=\color{LightSteelBlue!20},
    frame=trbl,
    rulecolor=\color{black!30},
    xrightmargin=7pt}

   \begin{document}
   \begin{lstlisting}


public void write(double step, double max, PrintWriter locusOutFile, PrintWriter impOutFile) throws IOException {

\end{lstlisting}
\end{document}

Thanks in advance.

1
  • 2
    You haven't used breaklines=true Commented Dec 19, 2012 at 16:02

1 Answer 1

8

enter image description here

As noted in comment on the question you were missing breaklines=true

 \documentclass{article}
 \usepackage[margin=2cm]{geometry}
 \usepackage[svgnames]{xcolor}
\usepackage{changepage}
\usepackage{framed}
\usepackage{tikz}
\usepackage{listings}
\usepackage{bbding}


    \lstset{breaklines=true,backgroundcolor=\color{LightSteelBlue!20},
    frame=trbl,
    rulecolor=\color{black!30},
    xrightmargin=7pt}

   \begin{document}
   \begin{lstlisting}


public void write(double step, double max, PrintWriter locusOutFile, PrintWriter impOutFile) throws IOException {

\end{lstlisting}
\end{document}
5
  • Genius! That worked.
    – Magpie
    Commented Dec 19, 2012 at 16:06
  • I just searched for long in the listings manual. Commented Dec 19, 2012 at 16:08
  • why did you search for long?
    – Magpie
    Commented Dec 19, 2012 at 16:14
  • first few letters of "long line" lucky guess? But really most verbatim listing packages will not line break by default just like a pre in html does not (as you see in your question) Commented Dec 19, 2012 at 16:19
  • @cmhughes note added as requested Commented Dec 19, 2012 at 17:04

You must log in to answer this question.

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