我正在创建一个beamer
包含一些代码的演示文稿,我想在listings
环境中添加一些垂直间距。
我尝试使用phantom
系列命令,但由于它处于listings
环境中phantom
,因此命令无法被解释。
我的问题是:如何在我的listings
环境中添加一些垂直间距(例如 3 厘米)?
平均能量损失
\documentclass[table,dvipsnames]{beamer}
%%% Basic packages
\usepackage{amsmath}
\usepackage{pgfpages}
\usepackage{pgfplots}
\usepackage{graphicx}
\usepackage{picture}
\usepackage{filecontents}
\usepackage{multicol}
\usepackage{ragged2e}
\usepackage{listingsutf8}
\lstset{
language=python,
inputencoding=utf8/latin1,
extendedchars=true,
keywordstyle=\bfseries\ttfamily\color{blue},
identifierstyle=\ttfamily,
commentstyle=\color{gray},
stringstyle=\ttfamily\color{green!50!black},
showstringspaces=false,
basicstyle=\footnotesize\ttfamily,
tabsize=2,
breaklines=true,
extendedchars=true,
xleftmargin=1cm,
xrightmargin=1cm,
backgroundcolor=\color{white!80!black},
literate=%
{é}{{\'{e}}}1
{è}{{\`{e}}}1
{ê}{{\^{e}}}1
{ë}{{\¨{e}}}1
{û}{{\^{u}}}1
{ù}{{\`{u}}}1
{â}{{\^{a}}}1
{à}{{\`{a}}}1
{î}{{\^{i}}}1
{ô}{{\^{o}}}1
{ç}{{\c{c}}}1
}
\title[Test listings]{Test listings}
\subtitle{ }
\author{ }
\institute{ }
\date{ }
\begin{document}
\begin{frame}[fragile]
\frametitle{test}
\begin{lstlisting}
if (1<2):
print('python')
\vphantom{vertical spacing}
if (2<3):
print('yay')
\end{lstlisting}
\end{frame}
\end{document}
答案1
您可以退出乳胶序列来添加一些空间,但不幸的是,这也会中断背景着色。
\documentclass[table,dvipsnames]{beamer}
%%% Basic packages
\usepackage{amsmath}
\usepackage{pgfpages}
\usepackage{pgfplots}
%\usepackage{graphicx}
\usepackage{picture}
\usepackage{filecontents}
%\usepackage{multicol}
\usepackage{ragged2e}
\usepackage{listings}
\usepackage{listingsutf8}
\lstset{
language=python,
inputencoding=utf8/latin1,
extendedchars=true,
keywordstyle=\bfseries\ttfamily\color{blue},
identifierstyle=\ttfamily,
commentstyle=\color{gray},
stringstyle=\ttfamily\color{green!50!black},
showstringspaces=false,
basicstyle=\footnotesize\ttfamily,
tabsize=2,
breaklines=true,
extendedchars=true,
xleftmargin=1cm,
xrightmargin=1cm,
escapeinside={(*@}{@*)},
backgroundcolor=\color{white!80!black},
literate=%
{é}{{\'{e}}}1
{è}{{\`{e}}}1
{ê}{{\^{e}}}1
{ë}{{\¨{e}}}1
{û}{{\^{u}}}1
{ù}{{\`{u}}}1
{â}{{\^{a}}}1
{à}{{\`{a}}}1
{î}{{\^{i}}}1
{ô}{{\^{o}}}1
{ç}{{\c{c}}}1
}
\title[Test listings]{Test listings}
\subtitle{ }
\author{ }
\institute{ }
\date{ }
\begin{document}
\begin{frame}[fragile]
\frametitle{test}
\begin{lstlisting}
if (1<2):
print('python')
(*@\vspace*{3cm}@*)
if (2<3):
print('yay')
\end{lstlisting}
\end{frame}
\end{document}