Certain Words invisible in lstlisting

614 views Asked by At

I am using LaTeX and lstlisting to display some code examples but I now have the problem that certain words are disappearing.

\begin{lstlisting}[caption={Berechnen des F-Scores der Features für die Gangphasen des linken Beines.},label=lst:FScore, language=Python] selector = SelectKBest(f_classif, k=3)
selector.fit(df[["AccX", "AccY", "AccZ", "GyroX", "GyroZ", "GyroY", "MagX", "MagY", "MagZ"]], df["PhaseLeft"])
scores = selector.scores_\end{lstlisting}

gives me invisible words. Does anyone know why? Obviously the "" are the Problem but ' ' causes the same.

Minimal example

\documentclass[11pt,a4paper,openright,twoside,ngerman]{article}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{listings}
\usepackage{courier}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\begin{document}
\lstset{
basicstyle=\footnotesize\ttfamily, % Default font
aboveskip=7pt,
float=tbp,
basicstyle=\footnotesize,
numbers=left,
stepnumber=1,
showstringspaces=false,
tabsize=1,
breaklines=true,
breakatwhitespace=false,    
captionpos=b,
xleftmargin=17pt,
framexleftmargin=17pt,
framexrightmargin=5pt,
framexbottommargin=4pt,
stringstyle=\color{white}\ttfamily, % Color of strings
showspaces=false,
showtabs=false, 
}
\lstloadlanguages{ 
 Python
}
\section{Test}
\begin{lstlisting}[caption={Berechnen des F-Scores der Features für die Gangphasen des linken Beines.},label=lst:FScore, language=Python]
selector = SelectKBest(f_classif, k=3)
selector.fit(df[["AccX", "AccY", "AccZ", "GyroX", "GyroZ", "GyroY", "MagX", "MagY", "MagZ"]], df["PhaseLeft"])
scores = selector.scores_
\end{lstlisting}
\end{document}
1

There are 1 answers

1
samcarter_is_at_topanswers.xyz On BEST ANSWER

You explicitly tell your code to print strings in white. If you choose any other colour, you'll see them:

\documentclass[11pt,a4paper,openright,twoside,ngerman]{article}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{listings}
\usepackage{courier}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\begin{document}
\lstset{
basicstyle=\footnotesize\ttfamily, % Default font
aboveskip=7pt,
float=tbp,
basicstyle=\footnotesize,
numbers=left,
stepnumber=1,
showstringspaces=false,
tabsize=1,
breaklines=true,
breakatwhitespace=false,    
captionpos=b,
xleftmargin=17pt,
framexleftmargin=17pt,
framexrightmargin=5pt,
framexbottommargin=4pt,
stringstyle=\color{red}\ttfamily, % Color of strings
showspaces=false,
showtabs=false, 
}
\lstloadlanguages{ 
 Python
}
\section{Test}
\begin{lstlisting}[caption={Berechnen des F-Scores der Features für die Gangphasen des linken Beines.},label=lst:FScore, language=Python]
selector = SelectKBest(f_classif, k=3)
selector.fit(df[["AccX", "AccY", "AccZ", "GyroX", "GyroZ", "GyroY", "MagX", "MagY", "MagZ"]], df["PhaseLeft"])
scores = selector.scores_
\end{lstlisting}
\end{document}

enter image description here