# How to modify itemize in beamer with conditional spacing between items depending on nested sublists?

I would like to modify the itemize command of the beamer package so that it adds some amount of vertical space before each item for which the previous item contains a nested sublist. Here is an example:

\documentclass{beamer}
\mode<presentation>
\begin{document}
\begin{frame}{}

\begin{itemize}
\item 1
\begin{itemize}
\item 1.1
\item 1.2
\end{itemize}
\item 2
\begin{itemize}
\item 2.1
\begin{itemize}
\item 2.1.1
\item 2.1.2
\end{itemize}
\item 2.2
\end{itemize}
\item 3
\begin{itemize}
\item 3.1
\begin{itemize}
\item 3.1.1
\end{itemize}
\end{itemize}
\end{itemize}

\end{frame}
\end{document}


I would like the list in the example to be typeset like this:

1
1.1
1.2
<-- space here
2
2.1
2.1.1
2.1.2
<-- space here
2.2
<-- space here
3
3.1
3.1.1


An important requirement is that there should be no space after the entire environment. The following small "algorithm" should clarify what I'm trying to achieve:

• Maintain a variable lastItemLevel, initially set to 0.
• When starting an item, if the current item's level is smaller than lastItemLevel, add some vertical space; and, in any case, reset lastItemLevel to the current item's level.

Unfortunately, I don't understand the internals of LaTeX and beamer sufficiently well to implement this idea.

• Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 Sep 19 '14 at 16:04

Before and after:

The only thing you have to know is \@itemdepth, the (TeX)counter storing the current level. By the way, if you have so many itemize's, would you like to use easylist with beamer?

\documentclass[handout,draft]{beamer}
\begin{document}
\begin{frame}
\begin{itemize}
\item 1
\item 2
\begin{itemize}
\item 2.1
\item 2.2
\end{itemize}
\item 3
\begin{itemize}
\item 3.1
\begin{itemize}
\item 3.1.1
\item 3.1.2
\end{itemize}
\end{itemize}
\item 4
\end{itemize}
outside itemize
\end{frame}
\makeatletter
\newcount\lastItemLevel\lastItemLevel1
\let\olditem\item
\def\item{%
\ifnum\@itemdepth<\lastItemLevel\vspace*{1em}\fi%
\global\lastItemLevel\@itemdepth%
\olditem}
\makeatother
\begin{frame}
\begin{itemize}
\item 1
\item 2
\begin{itemize}
\item 2.1
\item 2.2
\end{itemize}
\item 3
\begin{itemize}
\item 3.1
\begin{itemize}
\item 3.1.1
\item 3.1.2
\end{itemize}
\end{itemize}
\item 4
\end{itemize}
outside itemize
\end{frame}
\end{document}