I am trying to present some Python-code in LaTeX using listings and \lstinputlisting
, but I have some problems with using backgroundcolor
in \lstset
. I can't really describe it, so I have included a picture:
The gray block comes from backgroundcolor
in \lstset
. As you can see it doesn't completely cover the code, and there's some extra gray text that says "bbrreeaakklliinneess" in between the lines. The gray text can be highlighted and copied, even if I change the color to white. If I remove backgroundcolor
from \lstset
the text goes away, but then the background is white. The code I used to define \lstset
is as follows:
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\definecolor{mygray}{rgb}{0.9,0.9,0.9}
\definecolor{LightGray}{gray}{0.95}
\lstset{frame=tb,
language=Python,
aboveskip=3mm,
belowskip=3mm,
showstringspaces=false,
columns=flexible,
basicstyle={\small\ttfamily},
numbers=none,
numberstyle=\tiny\color{gray},
keywordstyle=\color{blue},
commentstyle=\color{dkgreen},
stringstyle=\color{mauve},
backgroundcolor=\color{mygray}
breaklines=true,
breakatwhitespace=true,
tabsize=3
}
Is there any way I can fix this?
Best Answer
Just do not use the following three options for
\lstset
:So with the following complete MWE (package
filecontents
is used to get a compiling MWE with TeX code and python code):you get the result: