在 LaTeX Beamer 中,我尝试进行\itemsep
全局设置。
我已经尝试了以下操作,但是没有效果:
\documentclass[14pt]{beamer}
\setbeamertemplate{itemize/enumerate body begin}{\setlength{\itemsep}{5ex}}
\begin{document}
\begin{frame}
\begin{itemize}
% \setlength{\itemsep}{5ex} % this would work locally..
\item Test1
\item Test2
\item Test3
\end{itemize}
\end{frame}
\end{document}
我究竟做错了什么?
编辑:
如果可能的话,我更喜欢一种允许为主体、子主体、子子主体等定义不同间距的解决方案。
答案1
您的代码无法运行,因为itemize/enumerate \beameritemnestingprefix body begin
模板已被使用前内部\list
使用的itemize
。
您可以修补\itemize
(原始定义在beamerbaselocalstructure.sty
):
\documentclass[14pt]{beamer}
\usepackage{xpatch}
\xpatchcmd{\itemize}
{\def\makelabel}
{\setlength{\itemsep}{5ex}\def\makelabel}
{}
{}
\begin{document}
\begin{frame}
\begin{itemize}
\item Test1
\item Test2
\item Test3
\end{itemize}
\end{frame}
\end{document}
由于\itemize
的定义beamer
具有可选参数,因此使用etoolbox
可能\patchcmd
会产生不良结果。包\xpatchcmd
中的xpatch
旨在处理这些情况。
更新
在评论中,有人要求能够独立控制三个允许的嵌套级别的分离;这也可以通过使用条件轻松完成\@itemdepth
:
\documentclass{beamer}
\usepackage{xpatch}
\xpatchcmd{\itemize}
{\def\makelabel}
{\ifnum\@itemdepth=1\relax
\setlength\itemsep{3ex}% separation for first level
\else
\ifnum\@itemdepth=2\relax
\setlength\itemsep{2ex}% separation for second level
\else
\ifnum\@itemdepth=3\relax
\setlength\itemsep{0.5ex}% separation for third level
\fi\fi\fi\def\makelabel
}
{}
{}
\begin{document}
\begin{frame}
\begin{itemize}
\item First item.
\begin{itemize}
\item First subitem.
\item Second subitem.
\begin{itemize}
\item First subsubitem.
\item Second subsubitem.
\item Third subsubitem.
\end{itemize}
\item Third subitem.
\end{itemize}
\item Second item.
\item Third item.
\end{itemize}
\end{frame}
\end{document}
答案2
作为补充Gonzalo Medina 的回答,我用的是这个:
\documentclass{beamer}
\usepackage{xpatch}
\makeatletter
\newcommand{\my@beamer@setsep}{%
\ifnum\@itemdepth=1\relax
\setlength\itemsep{\my@beamer@itemsepi}% separation for first level
\else
\ifnum\@itemdepth=2\relax
\setlength\itemsep{\my@beamer@itemsepii}% separation for second level
\else
\ifnum\@itemdepth=3\relax
\setlength\itemsep{\my@beamer@itemsepiii}% separation for third level
\fi\fi\fi}
\newlength{\my@beamer@itemsepi}\setlength{\my@beamer@itemsepi}{3ex}
\newlength{\my@beamer@itemsepii}\setlength{\my@beamer@itemsepii}{1.5ex}
\newlength{\my@beamer@itemsepiii}\setlength{\my@beamer@itemsepiii}{1.5ex}
\newcommand\setlistsep[3]{%
\setlength{\my@beamer@itemsepi}{#1}%
\setlength{\my@beamer@itemsepii}{#2}%
\setlength{\my@beamer@itemsepiii}{#3}%
}
\xpatchcmd{\itemize}
{\def\makelabel}
{\my@beamer@setsep\def\makelabel}
{}
{}
\xpatchcmd{\beamer@enum@}
{\def\makelabel}
{\my@beamer@setsep\def\makelabel}
{}
{}
\makeatother
\begin{document}
\begin{frame}
\begin{columns}[onlytextwidth, T]
\begin{column}{.48\linewidth}
% First column
\begin{itemize}
\item First item.
\begin{itemize}
\item First subitem.
\item Second subitem.
\begin{itemize}
\item First subsubitem.
\item Second subsubitem.
\item Third subsubitem.
\end{itemize}
\item Third subitem.
\end{itemize}
\item Second item.
\item Third item.
\end{itemize}
\end{column}%
\hfill%
\begin{column}{.48\linewidth}
% second column
\begin{enumerate}
\item First item.
\begin{enumerate}
\item First subitem.
\item Second subitem.
\begin{enumerate}
\item First subsubitem.
\item Second subsubitem.
\item Third subsubitem.
\end{enumerate}
\item Third subitem.
\end{enumerate}
\item Second item.
\item Third item.
\end{enumerate}
\end{column}
\end{columns}
\end{frame}
\end{document}
这样我就可以\setlistsep{2ex}{1ex}{1ex}
在幻灯片中需要更改值的地方进行操作了。
如果您还想添加子列表中第一个项目的分隔,您可以将其更改\my@beamer@setsep
为:
\newcommand{\my@beamer@setsep}{%
\ifnum\@itemdepth=1\relax
\setlength\itemsep{\my@beamer@itemsepi}% separation for first level
\else
\ifnum\@itemdepth=2\relax
\setlength\itemsep{\my@beamer@itemsepii}% separation for second level
\setlength\topsep{\my@beamer@itemsepii}% separation for second level
\else
\ifnum\@itemdepth=3\relax
\setlength\itemsep{\my@beamer@itemsepiii}% separation for third level
\setlength\topsep{\my@beamer@itemsepiii}% separation for second level
\fi\fi\fi}
获得
...或者也许最好使用以前的 itemsep
作为topsep
:
\newcommand{\my@beamer@setsep}{%
\ifnum\@itemdepth=1\relax
\setlength\itemsep{\my@beamer@itemsepi}% separation for first level
\else
\ifnum\@itemdepth=2\relax
\setlength\itemsep{\my@beamer@itemsepii}% separation for second level
\setlength\topsep{\my@beamer@itemsepi}% separation for second level
\else
\ifnum\@itemdepth=3\relax
\setlength\itemsep{\my@beamer@itemsepiii}% separation for third level
\setlength\topsep{\my@beamer@itemsepii}% separation for second level
\fi\fi\fi}
(只是个人喜好问题)