我有一个 R 代码print("hello")
。但是它将 1 行代码打印成 2 行。如何解决这个问题。提前谢谢大家。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass[10pt,english,8pt]{beamer}
\usepackage{listings}
\usepackage{xcolor}
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\lstdefinestyle{mystyle}{
backgroundcolor=\color{backcolour},
commentstyle=\color{codegreen},
keywordstyle=\color{magenta},
numberstyle=\tiny\color{codegray},
stringstyle=\color{codepurple},
basicstyle=\ttfamily\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2
}
\lstset{style=mystyle}
\begin{document}
\begin{frame}[fragile]{NAME}
\begin{lstlisting}[language=R]
print("hello")
\end{lstlisting}
\vskip0pt
\end{frame}
\end{document}
答案1
逐字结构,如lstlisting
读取所有内容,直到\end{lstlisting}
。因此,如果我们写
\begin{frame}[fragile]{NAME}
\begin{lstlisting}[language=R]
print("hello")
\end{lstlisting}
\vskip0pt
\end{frame}
那么从左边缘到的空格\end{lstlisting}
也将被读取,并在输出中产生额外的行。
因此使用
\begin{frame}[fragile]{NAME}
\begin{lstlisting}[language=R]
print("hello")
\end{lstlisting}
\end{frame}