[Tex/LaTex] Variable itemize indentation on Beamer slides

beamerindentationitemizelists

I'm not sure if what I want is possible at all, but asking doesn't hurt…

I've adjusted the itemize environment so that the item text is aligned with the text outside the environment. This might look strange, but since I never use itemized and non-itemized text on the same slide, it's not a problem.

A problem arises if I use itemize inside a block environment. In this case, the bullets are positioned outside of the box — which is definitely not what I want.

Can I somehow distinguish between itemize environments inside a block and the ones outside a block and set the \leftmargini accordingly?

\documentclass{beamer}
\usetheme{default}
\usecolortheme{crane}
\setbeamertemplate{itemize/enumerate body begin}{\setlength{\leftmargini}{0pt}}
\begin{document}
  \begin{frame}
    This is a text.
    \begin{itemize}
      \item This is an item.
      \item This is another item
      \begin{itemize}
        \item with a subitem
        \item and another subitem
      \end{itemize}
    \end{itemize} 
    \begin{alertblock}{Just A Block}
      This is a text in a block.
      \begin{itemize}
        \item This is an item in a block.
        \item Another item.
      \end{itemize}
    \end{alertblock}
  \end{frame}
\end{document}

example

Best Answer

Does the following do what you want? My solution redefines the alertblock environment so that \leftmargini be reset to its original value at the beginning of the environment; outside of an alertblock's scope, \leftmargini reverts to its global value. You can of course adapt the method to other environments, if you want.

\documentclass{beamer}
\usetheme{default}
\usecolortheme{crane}

\newlength\origleftmargini
\setlength\origleftmargini\leftmargini
\setbeamertemplate{itemize/enumerate body begin}{\setlength{\leftmargini}{0pt}}

\let\oldalertblock\alertblock
\let\oldendalertblock\endalertblock
\def\alertblock{\begingroup \setbeamertemplate{itemize/enumerate body begin}{\setlength{\leftmargini}{\origleftmargini}} \oldalertblock}
\def\endalertblock{\oldendalertblock \endgroup}

\begin{document}
  \begin{frame}
    This is a text.
    \begin{itemize}
      \item This is an item.
      \item This is another item
      \begin{itemize}
        \item with a subitem
        \item and another subitem
      \end{itemize}
    \end{itemize} 
    \begin{alertblock}{Just A Block}
    %\setbeamertemplate{itemize/enumerate body begin}{\setlength{\leftmargini}{\origleftmargini}}
      This is a text in a block.
      \begin{itemize}
        \item This is an item in a block.
        \item Another item.
      \end{itemize}
    \end{alertblock}
    \begin{itemize}
      \item This is an item.
      \item This is another item
      \begin{itemize}
        \item with a subitem
        \item and another subitem
      \end{itemize}
    \end{itemize}
  \end{frame}
\end{document}

enter image description here