3

I have a problem when using lstlisting in twocolumn document. At my university I have to make reports in twocolumn documents. My teacher send me pre done .tex file with this code in it:

\documentclass[a4paper, 10pt, twocolumn]{article}
\setlength{\columnsep}{5mm}
\usepackage{anysize}
\marginsize{1cm}{1cm}{1cm}{1cm}
\usepackage{polski}
\usepackage[cp1250]{inputenc}
%\usepackage[framed, numbered]{mcode}
\usepackage{listings}
\usepackage{graphicx}
\usepackage[usenames,dvipsnames]{color}
\usepackage{marvosym} %dla symbolu euro
\usepackage{array}
\usepackage[section] {placeins}
\renewcommand{\baselinestretch}{1.15} %interlinia

But when I use lstlisting function, text from 1st column overlaps 2nd column, and I have to manually wrap too long lines to make it clear. Is it any better way of dealing with such a thing? I'm new to LaTeX, so please be as precise as possible. :) Sorry for my english, I'm not a native english speaker.

2

Use the breaklines=true option:

\documentclass[a4paper, 10pt, twocolumn]{article}
\usepackage{listings}
\usepackage{lipsum}

\lstset{breaklines=true}

\begin{document}

\lipsum[4]
\begin{lstlisting}
test listing test listing test listing test listing test listing test listing test listing test listing test listing test listing test listing
\end{lstlisting}
\lipsum[4]

\end{document}

enter image description here

1
  • Thank you very much. :) Now It is pleasure to write reports. – Krzywusek Jan 31 '14 at 15:00

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.