我正在使用列表在 LaTeX 中编写代码 c++...但我有一些奇怪的输出,而不是“空白”,它出现未知符号,这是列表的代码:
\defverbatim[colored]\lstI{
\begin{lstlisting}[language=C++,basicstyle=\ttfamily\scriptsize,keywordstyle=\color{blue}\ttfamily,stringstyle=\color{red}\ttfamily,commentstyle=\color{green}\ttfamily,breaklines=true]
fprintf(gnuplot,"set term postscript\n");
fprintf(gnuplot,"set output \"kmeans_graphs.ps\" \n");
fprintf(gnuplot,"plot 'nomExt.txt' lt 3 linecolor rgb \"red\", 'init_center.dat' lt 7 linecolor rgb \"blue\"\n");
fprintf(gnuplot,"plot 'nomExt.txt' lt 3 linecolor rgb \"red\", 'center_progress.dat' lt 7 linecolor rgb \"yellow\"\n");
fprintf(gnuplot,"plot 'nomExt.txt' lt 3 linecolor rgb \"red\", 'final_center.dat' lt 7 linecolor rgb \"green\"\n");
fprintf(gnuplot,"set term x11\n set out\n");
fprintf(gnuplot,"plot 'nomExt.txt' lt 3 linecolor rgb \"red\", 'final_center.dat' lt 7 linecolor rgb \"green\"\n");
cout<<"\tsaving all plots in the file directory with kmeans_graphs.ps name..."<<endl;
cout<<"\tdisplaying final center for the data set..."<<endl;
\end{lstlisting}
}
\begin{frame}{partie 3 du code}{Extrait main.cpp}
\lstI
\end{frame}
输出如下:
fprintf ( gnuplot , " set ␣ term ␣ postscript \ n " ) ;
fprintf ( gnuplot , " set ␣ output ␣ \" kmeans_graphs . ps \" ␣ \ n " ) ;
fprintf ( gnuplot , " plot ␣ ’ nomExt . txt ’␣ lt ␣ 3 ␣ linecolor ␣ rgb ␣ \" red
\" , ␣ ’ init_center . dat ’␣ lt ␣ 7 ␣ linecolor ␣ rgb ␣ \" blue \"\ n " ) ;
fprintf ( gnuplot , " plot ␣ ’ nomExt . txt ’␣ lt ␣ 3 ␣ linecolor ␣ rgb ␣ \" red
\" , ␣ ’ ce n te r_ pr o gr es s . dat ’␣ lt ␣ 7 ␣ linecolor ␣ rgb ␣ \" yellow \"\
n");
fprintf ( gnuplot , " plot ␣ ’ nomExt . txt ’␣ lt ␣ 3 ␣ linecolor ␣ rgb ␣ \" red
\" , ␣ ’ final_center . dat ’␣ lt ␣ 7 ␣ linecolor ␣ rgb ␣ \" green \"\ n " ) ;
fprintf ( gnuplot , " set ␣ term ␣ x11 \ n ␣ set ␣ out \ n " ) ;
fprintf ( gnuplot , " plot ␣ ’ nomExt . txt ’␣ lt ␣ 3 ␣ linecolor ␣ rgb ␣ \" red
\" , ␣ ’ final_center . dat ’␣ lt ␣ 7 ␣ linecolor ␣ rgb ␣ \" green \"\ n " ) ;
cout < < " \ tsaving ␣ all ␣ plots ␣ in ␣ the ␣ file ␣ directory ␣ with
␣ kmeans_graphs . ps ␣ name ... " << endl ;
cout < < " \ tdisplaying ␣ final ␣ center ␣ for ␣ the ␣ data ␣ set ...
" << endl ;
答案1
选项showspaces=false
和 showstringspaces=false
必须指定到列表或作为全局选项。
\documentclass{beamer}
\usepackage{listings}%
\begin{document}
\lstset{showspaces=false,showstringspaces=false}%
\defverbatim[colored]\lstI{%
\begin{lstlisting}[language=C++,basicstyle=\ttfamily\scriptsize,keywordstyle=\color{blue}\ttfamily,stringstyle=\color{red}\ttfamily,commentstyle=\color{green}\ttfamily,breaklines=true]
fprintf(gnuplot,"set term postscript\n");
fprintf(gnuplot,"set output \"kmeans_graphs.ps\" \n");
fprintf(gnuplot,"plot 'nomExt.txt' lt 3 linecolor rgb \"red\", 'init_center.dat' lt 7 linecolor rgb \"blue\"\n");
fprintf(gnuplot,"plot 'nomExt.txt' lt 3 linecolor rgb \"red\", 'center_progress.dat' lt 7 linecolor rgb \"yellow\"\n");
fprintf(gnuplot,"plot 'nomExt.txt' lt 3 linecolor rgb \"red\", 'final_center.dat' lt 7 linecolor rgb \"green\"\n");
fprintf(gnuplot,"set term x11\n set out\n");
fprintf(gnuplot,"plot 'nomExt.txt' lt 3 linecolor rgb \"red\", 'final_center.dat' lt 7 linecolor rgb \"green\"\n");
cout<<"\tsaving all plots in the file directory with kmeans_graphs.ps name..."<<endl;
cout<<"\tdisplaying final center for the data set..."<<endl;
\end{lstlisting}
}
\begin{frame}{partie 3 du code}{Extrait main.cpp}
\lstI%
\end{frame}
\end{document}