1

I'm trying to (automatically) center an itemize in a Beamer presentation.

The problem is, that all solutions I've found either

  • use varwidth with enumitem (which works a charm but not in beamer),
  • use a table (which would cost me the exact overlay syntax from itemize/enumerate/description, which I'd prefer to keep, as the environment will be used by others) or
  • manually size a minipage (or something similar).

So I started writing an environment that tries to calculate the width of an itemize to set a minipage to the correct width. The document below works as expected, what doesn’t work is nesting the lists.

So two questions:

  • I don’t really know where to go from here. Can the problem be fixed (e.g. by changing the order of how stuff is calculated, as a minipage in the place of the nested list works)? Or do I need another approach? If the same syntax (i.e. \begin{ul}[<+-] and \item<...> with nesting) is possible with other methods that would also be fine, I'd just like the user-facing syntax to be familiar.
  • I currently use \leftmargini in the width calculation, I don't really understand how I would detect in which “layer” I am and whether to apply \leftmarginii/\leftmarginiii.
\documentclass{beamer}

% adapted from https://tex.stackexchange.com/a/127014 \ExplSyntaxOn \NewDocumentEnvironment{measureItemize}{+b} {% % split the contents at \item \seq_set_split:Nnn \l_werner_itemize_input_seq {\item} {#1} % remove the first (empty) item \seq_pop_left:NN \l_werner_itemize_input_seq \l_tmpa_tl % measure each item \seq_map_inline:Nn \l_werner_itemize_input_seq {\measureitem{##1}} } {} \seq_new:N \l_werner_itemize_input_seq

% adapted from https://tex.stackexchange.com/a/185707 \newlength{\xitemlenx} \newlength{\xitemleny} \newcommand{\measureitem}[1]{% \settowidth{\dimen0}{#1}% \ifdim\dimen0>\xitemlenx% \xitemlenx=\dimen0 \fi \global\xitemleny\xitemlenx% }

\NewDocumentEnvironment{ul}{o+b} {% \begin{measureItemize} #2 \end{measureItemize} \bigskip \begin{minipage}{\dim_min:nn {\linewidth} {\xitemleny+\labelsep+\itemindent+\leftmargini}} \begin{itemize}[#1] #2 \end{itemize} \end{minipage} \bigskip }{} \ExplSyntaxOff

\begin{document}

\begin{frame} \centering \fbox{ \begin{ul}[<+->] \item item 1 \item item 2 is a bit longer \item item 3 % \begin{ul} % \item item 1 % \item item 2 % \item item 3 % \end{ul} \end{ul} } \end{frame}

\end{document}

enter image description here

fhred
  • 43

1 Answers1

1

Using a table does not mean you can't use overlays. You could for example adapt this answer by @CarLaTeX https://topanswers.xyz/tex?q=2000#a2242 :

\documentclass{beamer}
\makeatletter
\newcommand{\slideinframe}{\beamer@slideinframe}
\makeatother

\usepackage{tabularray} \UseTblrLibrary{counter} \UseTblrLibrary{varwidth}

\begin{document} \begin{frame} \centering \fbox{\begin{tblr}{colspec={l}, cells={cmd=\onslide<\arabic{rownum}->,preto={{\usebeamercolor[fg]{itemize item}\usebeamertemplate{itemize item}~}}}, } item 1 \ item 2 \ \end{tblr}} \end{frame} \end{document}

enter image description here

  • You are of course correct. The question was not precise enough in this regard. I would like to keep the existing syntax for itemize/enumerate/description, as this is for a template other people will use. I will edit the question accordingly. – fhred Aug 04 '23 at 18:17
  • @fhred You could try the getitems package to convert your itemize syntax into other syntaxes – samcarter_is_at_topanswers.xyz Aug 05 '23 at 14:52
  • yeah, but then I'd have to re-implement all the overlay syntax, I was hoping to re-use beamer's itemize to avoid that. – fhred Aug 05 '23 at 15:30