
내 tex 파일에는 다음 코드가 있습니다. 결과적으로 목록 번호는 증가하는 색인으로 번호가 매겨집니다. 이런 일이 발생하지 않도록 하는 방법이 있나요? (스크린샷 참조: 두 번째 슬라이드에도 "목록 1: 기능"이 표시되어야 합니다)
\documentclass{beamer}
\usetheme{Goettingen}
%\usecolortheme{whale}
\setbeamertemplate{frametitle continuation}[from second] % (cont.) from second slide
\setbeamertemplate{bibliography item}{[\theenumiv]} % numbers instead of silly pictures
\setbeamertemplate{footline}[frame number]
\beamertemplatenavigationsymbolsempty % remove navigationbar
\usepackage[font=bf,skip=\baselineskip]{caption}
\captionsetup[lstlisting]{font={footnotesize}}
\usepackage{color}
\definecolor{light-gray}{gray}{0.85}
\definecolor{darkgreen}{rgb}{0.0, 0.5, 0.0} % for green colour in code
\usepackage{listings}
\usepackage[T1]{fontenc}
\lstset{
basicstyle=\tiny,
escapeinside={<@}{@>},
numbers=left,
language=C,
morekeywords={throw, assert},
frame=single,
captionpos=b,
commentstyle=\color{darkgreen}}
\begin{document}
\begin{frame}[fragile,containsverbatim]{Example}
\begin{lstlisting}[caption={Function}]
functionA(x){
a = functionB(x)
return a
}
functionB(x){
b = <@\only<1>{GLOBAL\_VAR}\only<2>{\textcolor{darkgreen}{GLOBAL\_VAR}}@>
b++
return b
}
\end{lstlisting}
\end{frame}
\end{document}
답변1
당신에게 필요한 것은
\resetcounteronoverlays{lstlisting}
오버레이를 사용할 때 카운터가 증가하는 것을 방지합니다. 전체 코드:
\documentclass{beamer}
\usetheme{Goettingen}
%\usecolortheme{whale}
\setbeamertemplate{frametitle continuation}[from second] % (cont.) from second slide
\setbeamertemplate{bibliography item}{[\theenumiv]} % numbers instead of silly pictures
\setbeamertemplate{footline}[frame number]
\beamertemplatenavigationsymbolsempty % remove navigationbar
\usepackage[font=bf,skip=\baselineskip]{caption}
\captionsetup[lstlisting]{font={footnotesize}}
\usepackage{color}
\definecolor{light-gray}{gray}{0.85}
\definecolor{darkgreen}{rgb}{0.0, 0.5, 0.0} % for green colour in code
\usepackage{listings}
\usepackage[T1]{fontenc}
\lstset{
basicstyle=\tiny,
escapeinside={<@}{@>},
numbers=left,
language=C,
morekeywords={throw, assert},
frame=single,
captionpos=b,
commentstyle=\color{darkgreen}}
\resetcounteronoverlays{lstlisting}
\begin{document}
\begin{frame}[fragile,containsverbatim]{Example}
\begin{lstlisting}[caption={Function}]
functionA(x){
a = functionB(x)
return a
}
functionB(x){
b = <@\only<1>{GLOBAL\_VAR}\only<2>{\textcolor{darkgreen}{GLOBAL\_VAR}}@>
b++
return b
}
\end{lstlisting}
\end{frame}
\end{document}
결과: