为什么清单之间的源代码缩进和编号是错误的?

为什么清单之间的源代码缩进和编号是错误的?

这是我的代码和输出。我们可以看到内循环的数量和缩进是错误的。

\documentclass{beamer}
\mode<presentation>
{
  \usetheme{CambridgeUS}
  \usecolortheme{dolphin}
  \usecolortheme{rose}
  \setbeamerfont*{title}{shape=\itshape, family=\rmfamily}
  \setbeamercovered{transparent}
}
\usepackage{listings}
\usepackage{color}
\lstset{
  language=C,
  basicstyle=\footnotesize\ttfamily, 
  numbers=left,
  numberstyle=\footnotesize,
  stepnumber=1,
  numbersep=5pt,
  showspaces=false,
  showstringspaces=false,
  showtabs=false,
  frame=single,
  captionpos=b,
  breaklines=true,
  breakatwhitespace=false,
  escapeinside={\%*}{*)}
}
\begin{document}
\begin{frame}[fragile]
  \frametitle{Loop-unrolled, register-blocked code}
  \begin{lstlisting}
  void sparse_mvm_bcsr_2x3(int M, int n,
    const double* Aval, const int* Aind, const int* Aptr,
    const double* x, double* y) 
  {
    int I;
    for(I = 0; I < M; I++, y += 2) {
      register double y0 = y[0], y1 = y[1];
      int jj;
      for(jj = Aptr[I]; jj < Aptr[I + 1]; jj++, Aval += 6) 
      {
    int j = Aind[jj];
    register double x0 = x[j], x1 = x[j + 1], x2 = x[j + 2];
    y0 += Aval[0] * x0; y1 += Aval[3] * x0;
    y0 += Aval[1] * x1; y1 += Aval[4] * x1;
    y0 += Aval[2] * x2; y1 += Aval[5] * x2;
      }
      y[0] = y0; y[1] = y1;
    }
  }
  \end{lstlisting}
\end{frame}
\end{document}

在此处输入图片描述

答案1

要解决隐藏数字的问题,请将以下选项添加到您的\lstset

  framexleftmargin=-10pt,
  numbersep=-2pt,

梅威瑟:

\documentclass{beamer}
\mode<presentation>
{
  \usetheme{CambridgeUS}
  \usecolortheme{dolphin}
  \usecolortheme{rose}
  \setbeamerfont*{title}{shape=\itshape, family=\rmfamily}
  \setbeamercovered{transparent}
}
\usepackage{listings}
\usepackage{color}
\lstset{
  language=C,
  basicstyle=\footnotesize\ttfamily,
  numbers=left,
  numberstyle=\footnotesize,
  stepnumber=1,
  numbersep=5pt,
  showspaces=false,
  showstringspaces=false,
  showtabs=false,
  frame=single,
  framexleftmargin=-10pt,
  numbersep=-2pt,
  captionpos=b,
  breaklines=true,
  breakatwhitespace=false,
  escapeinside={\%*}{*)}
}
\begin{document}
\begin{frame}[fragile]
  \frametitle{Loop-unrolled, register-blocked code}
  \begin{lstlisting}
  void sparse_mvm_bcsr_2x3(int M, int n,
    const double* Aval, const int* Aind, const int* Aptr,
    const double* x, double* y)
  {
    int I;
    for(I = 0; I < M; I++, y += 2) {
      register double y0 = y[0], y1 = y[1];
      int jj;
      for(jj = Aptr[I]; jj < Aptr[I + 1]; jj++, Aval += 6)
      {
    int j = Aind[jj];
    register double x0 = x[j], x1 = x[j + 1], x2 = x[j + 2];
    y0 += Aval[0] * x0; y1 += Aval[3] * x0;
    y0 += Aval[1] * x1; y1 += Aval[4] * x1;
    y0 += Aval[2] * x2; y1 += Aval[5] * x2;
      }
      y[0] = y0; y[1] = y1;
    }
  }
  \end{lstlisting}
\end{frame}
\end{document} 

输出:

在此处输入图片描述

相关内容