I am new to \LaTeX. I am trying to use solution give on How to remove the whitespace BEFORE itemize/enumerate? to remove vertical space before itemize environment using enumitem and beamer. But I don't get the desired result. Is there a solution to this problem?
-
2Welcome to TeX.SX! You may have a look on our starter guide. Maybe this will help: http://tex.stackexchange.com/questions/114280/how-to-reduce-vertical-space-itemize-environment-inside-table – Mario S. E. May 24 '13 at 09:43
-
In my case (beamer with some customization) I also needed in Gonzalo Medina's answer: \setlength\parskip{0pt} (I don't have enough rep to comment.) – gordon Aug 15 '23 at 14:24
2 Answers
It's not a good idea to use the enumitem package with beamer since beamer has its own ways of dealing with the standard list-like environments. Just by loading enumitem when using beamer you loose the special beamer formatting and the overlay-awareness of the list-like components.
To suppress the spacing, you can redefine itemize as implemented by beamer in the file beamerbaselocalstructure.sty. In the following example I show a possible modification, setting \topsep, \partopsep and \itemsep to 0pt (adjust these values according to your needs); the modified lines are signaled with %NEW:
\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}}
{%
\setlength\topsep{0pt}%NEW
\setlength\partopsep{0pt}%NEW
\setlength\itemsep{0pt}%NEW
\def\makelabel##1{%
{%
\hss\llap{{%
\usebeamerfont*{itemize \beameritemnestingprefix item}%
\usebeamercolor[fg]{itemize \beameritemnestingprefix item}##1}}%
}%
}%
}
\fi%
\beamer@cramped%
\raggedright%
\beamer@firstlineitemizeunskip%
}
\makeatother
\begin{document}
\begin{frame}
Some text
\begin{itemize}
\setlength\topsep{0pt}
\setlength\partopsep{0pt}
\item Item 1
\item Item 2
\item Item 3
\end{itemize}
Some text
\end{frame}
\end{document}

Just for comparison, the same list without the modifications:

- 505,128
-
-
Is there a way of doing this locally? Say I want to do this for one and only one list? – user1729 Feb 26 '14 at 12:49
-
@user1729 Sure. The redefinition can be made inside a group to keep its effect local. Comments are not the place to give code, so if you want to, feel free to open a nee question. – Gonzalo Medina Feb 26 '14 at 18:33
-
2
-
Works like a charm. I don't know much of the code, but just wonder why we need so much code to adjust the padding/margin? Also can we limit the scope to a single frame? – Gqqnbig Nov 26 '20 at 06:20
-
\setlength\topsep{0pt} inside itemize environment removed the space before, without importing enuitem package which creates conflict with beamer – younes zeboudj Mar 28 '21 at 14:14
As described in the enumitem documentation, you have two parameters to play with regarding vertical top space: topsep and partopsep.
So, for example, writing this:
\begin{enumerate}[topsep={0pt},partopsep={0pt}]
\item First item
\item Second item
\end{enumerate}
Will produce something like this:

Of course, if you want to play with the separation between items, you can do so by setting itemsep, again, as described in the enumitem documentation (available at the link mentioned above).
- 18,609