5

I use \setlength\itemsep{\fill} to vertically stretch items in an itemize environment. This works fine if I don't have a sub-list:

enter image description here

However, if there is a sub-list, the item following the sub-list would not be stretched. As you can see in the screenshot below, the space between the first two level-1 items is smaller than the space between the last two.

enter image description here

Question

How do I fix this issue in a way that does not require setting a fixed length for \itemsep (e.g. 10pt) or manually adding \vfill before every level-1 \item?

MWE

\documentclass{beamer}
\begin{document}
\begin{frame}{Title}
  \begin{itemize}
    \setlength\itemsep{\fill}
    \item item 
    \begin{itemize}
      \item subitem 
    \end{itemize}
    \item item
    \item item
  \end{itemize}
\end{frame}
\end{document}
1

To stretch the list over the whole space I see two problems:

  • To automatically set \setlength\itemsep{\fill} for all itemizations, it can be added to the definition of \itemize

  • To add the same space between the items from the parent list and the sublist, one can use

    \ifnum \@itemdepth >1
        \vfill
    \fi%
    

    at the beginning and end of this sublist.


\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}}%
          }%
        }%
      }
  \fi%
  \setlength\itemsep{\fill}
    \ifnum \@itemdepth >1
        \vfill
    \fi%  
  \beamer@cramped%
  \raggedright%
  \beamer@firstlineitemizeunskip%
}

\def\enditemize{\ifhmode\unskip\fi\endlist%
  \usebeamertemplate{itemize/enumerate \beameritemnestingprefix body end}
  \ifnum \@itemdepth >1
        \vfil
  \fi%  
  }
\makeatother

\begin{document}
\begin{frame}{Title}
  \begin{itemize}
    \item item 
    \begin{itemize}
      \item subitem 
      \item subitem 
    \end{itemize}
    \item item
    \item item
  \end{itemize}
\end{frame}
\end{document}

enter image description here

  • Thanks for the answer. I actually don't need \vfill between subitems. I'll play with your code and see if I can modify it to my needs. Thanks again! – Herr K. May 13 '17 at 20:17
1

Following @samcarter's example, I managed to tweak the code to produce my desired output. Using \xpatchcmd from the xpatch package, I'm able to make the code a bit cleaner and less intimidating:

enter image description here

Code

\documentclass{beamer}

\usepackage{xpatch}
\xpatchcmd{\itemize}
  {\def\makelabel}
  {\ifnum\@itemdepth=1\relax
     \setlength\itemsep{\fill}% separation for first level
   \fi\def\makelabel
  }{}{}
\xpatchcmd{\enditemize}
  {\endlist}
  {\endlist\ifnum\@itemdepth<2\else\vfil\fi}{}{}

\begin{document}
\begin{frame}{Title}
  \begin{itemize}
    \item item 
    \begin{itemize}
      \item subitem 
      \begin{itemize}
        \item subsubitem
        \item subsubitem
      \end{itemize}
      \item subitem 
      \begin{itemize}
        \item subsubitem
        \item subsubitem
      \end{itemize}
    \end{itemize}
    \item item
    \item item
  \end{itemize}
\end{frame}
\end{document}
  • Reviving an old one: I'm trying to implement the same for enumerate, but just replacing "itemize" with "enumerate" in the code doesn't seem to do the trick. Any ideas? – pbaylis Jan 6 at 2:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.