我有一些奇怪的输出,而不是“空格”,它在 LaTeX 中显示为未知符号

我有一些奇怪的输出,而不是“空格”,它在 LaTeX 中显示为未知符号

我正在使用列表在 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}

在此处输入图片描述

相关内容