LaTeX Beamer: Define \itemsep globally
Yout code won't work because the itemize/enumerate \beameritemnestingprefix body begin
template is used before the \list
internally used by itemize
.
You can patch \itemize
(original definition in 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}
Since \itemize
as defined by beamer
has an optional argument, using etoolbox
's \patchcmd
might produce undesired results. The \xpatchcmd
from the xpatch
package was designed to deal with these cases.
Update
In comments, it has been requested to be able to independently control the separation for the three allowed nesting levels; this can also be easily done using a conditional on \@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}
As an addition to Gonzalo Medina's answer, I use this:
\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}
so that I can then do \setlistsep{2ex}{1ex}{1ex}
in the slide where I need to change the values.
If you want also to add to the separation of the first item in a sublist, you can change the \my@beamer@setsep
to:
\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}
to obtain
...or maybe it's better to use the previous itemsep
as 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}
(just a matter of taste)