![空间条目如何](https://linux22.com/image/290388/%E7%A9%BA%E9%97%B4%E6%9D%A1%E7%9B%AE%E5%A6%82%E4%BD%95.png)
如何将每个项目之间的间距设置为 2ex、子项目之间的间距设置为 1ex、项目与其子项目之间的间距设置为 1ex、子项目与下一个项目之间的间距设置为 2ex?
我尝试按照以下方式进行:
\documentclass{beamer}
\makeatletter
\def\@listii{\leftmargin\leftmarginii
\topsep 1ex
\parsep 0\p@ \@plus\p@
\itemsep \parsep}
\makeatother
\begin{document}
\begin{frame}
\begin{itemize}
\item Here are two interesting things:
\begin{itemize}
\item Here are two interesting things:
\item Here are two interesting things:
\end{itemize}
\item Here are two interesting things:
\item Here are two interesting things:
\end{itemize}
\end{frame}
\end{document}
提前致谢!
答案1
一个选项重新定义\itemize
(如 中所定义),根据 的值beamerbaselocalstructure.sty
有条件地设置(新代码由、表示):\itemsep
\@itemdepth
% start change
% end change
\documentclass{beamer}
\makeatletter
\renewcommand{\itemize}[1][]{%
\beamer@ifempty{#1}{}{\def\beamer@defaultospec{#1}}%
\ifnum \@itemdepth >2\relax\@toodeep\else
\advance\@itemdepth\@ne
\beamer@computepref\@itemdepth% sets \beameritemnestingprefix
\usebeamerfont{itemize/enumerate \beameritemnestingprefix body}%
\usebeamercolor[fg]{itemize/enumerate \beameritemnestingprefix body}%
\usebeamertemplate{itemize/enumerate \beameritemnestingprefix body begin}%
\list
{\usebeamertemplate{itemize \beameritemnestingprefix item}}
{\def\makelabel##1{%
{%
\hss\llap{{%
\usebeamerfont*{itemize \beameritemnestingprefix item}%
\usebeamercolor[fg]{itemize \beameritemnestingprefix item}##1}}%
}%
}%
% start change
\ifnum\@itemdepth=1\relax
\setlength\itemsep{2ex}
\else
\ifnum\@itemdepth=2\relax
\setlength\itemsep{1ex}
\fi\fi%
% end change
}
\fi%
\beamer@cramped%
\raggedright%
\beamer@firstlineitemizeunskip%
}
\makeatother
\begin{document}
\begin{frame}
\begin{itemize}
\item Here are two interesting things:
\begin{itemize}
\item Here are two interesting things:
\item Here are two interesting things:
\item Here are two interesting things:
\end{itemize}
\item Here are two interesting things:
\item Here are two interesting things:
\end{itemize}
\end{frame}
\end{document}
借助xpatch
我们可以修补\itemize
并且代码可以简化一些:
\documentclass{beamer}
\usepackage{xpatch}
\xpatchcmd{\itemize}
{\def\makelabel}
{\ifnum\@itemdepth=1\relax
\setlength\itemsep{2ex}
\else
\ifnum\@itemdepth=2\relax
\setlength\itemsep{1ex}
\fi\fi\def\makelabel
}
{}
{}
\begin{document}
\begin{frame}
\begin{itemize}
\item Here are two interesting things:
\begin{itemize}
\item Here are two interesting things:
\item Here are two interesting things:
\item Here are two interesting things:
\end{itemize}
\item Here are two interesting things:
\item Here are two interesting things:
\end{itemize}
\end{frame}
\end{document}