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'm trying to put a frame around my code, but the frame has the wrong dimension. How can I set them right?

\begin{lstlisting}[language=C++,frame=single,tabsize=2,showspaces=false,showstringspaces=false,
  keywordstyle=\color{blue},morekeywords={QStringList,QDate,QString,QIODevice},commentstyle=\color{CadetBlue},caption={Zistenie, či sme v daný deň, už záznam o rýchlosti uložili}]
QStringList lines;
//ziskaj aktualny datum
QDate date = QDate::currentDate(); 
//preved ho na retazec
QString dateString = date.toString("dd.MM."); 
if (speed_file.open(QIODevice::ReadOnly)) {
  if (speed_file.size() != 0) {
    while (!out.atEnd()) {
    //nacitaj cely subor po riadkoch
      lines.append(out.readLine()); 
    }
    out.flush();
    speed_file.close();
    //uloz posledny riadok
    lastLine = lines[lines.size() - 1]; 
    if (dateString.compare(lastLine.mid(lastLine.indexOf("->") + 2, -1)) == 0) {
      //prepíšeme pôvodný záznam o rýchlosti
    }
  \end{lstlisting}

and this is the result

enter image description here

share|improve this question

migrated from stackoverflow.com Apr 25 '12 at 16:51

This question came from our site for professional and enthusiast programmers.

add comment

1 Answer 1

up vote 4 down vote accepted

Use breaklines=true:

\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[
    language=C++,
    frame=single,
    tabsize=2,
    showspaces=false,
    showstringspaces=false,
    keywordstyle=\color{blue},
    morekeywords={QStringList,QDate,QString,QIODevice},
    commentstyle=\color{CadetBlue},
    caption={Zistenie, či sme v daný deň, už záznam o rýchlosti uložili},
    breaklines=true
]
QStringList lines;
//ziskaj aktualny datum
QDate date = QDate::currentDate(); 
//preved ho na retazec
QString dateString = date.toString("dd.MM."); 
if (speed_file.open(QIODevice::ReadOnly)) {
  if (speed_file.size() != 0) {
    while (!out.atEnd()) {
    //nacitaj cely subor po riadkoch
      lines.append(out.readLine()); 
    }
    out.flush();
    speed_file.close();
    //uloz posledny riadok
    lastLine = lines[lines.size() - 1]; 
    if (dateString.compare(lastLine.mid(lastLine.indexOf("->") + 2, -1)) == 0) {
      //prepíšeme pôvodný záznam o rýchlosti
    }
  \end{lstlisting}
\end{document}

enter image description here

share|improve this answer
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.