5

I use IEEE double column template and inside it I add a C++ code. I expect the code to be bounded within a single column however it infringes to the next column. How to fix this code?

I would avoid any solution affecting all lstlisting inside the latex file. I prefer to fix the code inline.

\begin{lstlisting}[linewidth=\columnwidth,language=C++]
out= in + dnx1 + dnx2 + dnx3 + dnx4 + dnx5 + dnx6 + dnx7 + dnx8 + dnx9 + dnx10;
\end{lstlisting}

latex lstlisting double column

2
  • 1
    breaklines=true,
    – user11232
    Apr 8, 2015 at 5:21
  • @HarishKumar fantastic. Solved my problem.
    – ar2015
    Apr 8, 2015 at 5:24

1 Answer 1

3

You have to add breaklines=true as the option. Further you may define

\lstset{basicstyle=\small\ttfamily,columns=fullflexible}

to add some difference.

\documentclass{IEEEtran}
\usepackage{listings}
\usepackage{lipsum}
\lstset{basicstyle=\small\ttfamily,columns=fullflexible}
\begin{document}
  \lipsum[1-2]
  \begin{lstlisting}[linewidth=\columnwidth,breaklines=true,language=C++]
out= in + dnx1 + dnx2 + dnx3 + dnx4 + dnx5 + dnx6 + dnx7 + dnx8 + dnx9 + dnx10;
\end{lstlisting}
\lipsum[4]
\end{document}

enter image description here

You must log in to answer this question.

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