[Tex/LaTex] How to indent a block in a beamertemplate

beamerblockindentationtemplates

I would like to design a beamer template in which the blocks are indented, i.e. their left outer margin is increased. How do I do this?

The width of the block can be set using

\addtobeamertemplate{block begin}{%
  \setlength{\textwidth}{0.8\textwidth}%
}

The only solutions I found use columns which will not work here (i.e. within addtobeamertemplate). At least I think there should be an easier way?

Minimal not-working example:

\documentclass{beamer}

\usetheme{Antibes}

\begin{document}

\frame{
\setlength{\textwidth}{0.8\textwidth}% effectively increases right outer margin
% command to indent goes here: it would need to be something that I can use in addtobeamertemplate
\begin{block}{}
  Indent me! 
\end{block}
}

\end{document}

Best Answer

Solution

\newlength{\blockleftindent}
\newlength{\blockrightindent}
\setlength\blockleftindent{10ex}
\setlength\blockrightindent{20ex}
\newlength{\blockwidth}
\setbeamertemplate{block begin}{
  \setlength\blockwidth{\linewidth}
  \addtolength\blockwidth{-\blockleftindent}
  \addtolength\blockwidth{-\blockrightindent}
  \par\vskip\medskipamount%
  \hspace*{\blockleftindent}%
  \begin{beamercolorbox}[colsep*=.75ex,wd=\blockwidth]{block title}
    \usebeamerfont*{block title}\insertblocktitle%
  \end{beamercolorbox}%
  {\parskip0pt\par}%
  \ifbeamercolorempty[bg]{block title}
  {}
  {\ifbeamercolorempty[bg]{block body}{}{\nointerlineskip\vskip-0.5pt}}%
  \usebeamerfont{block body}%
  \hspace*{\blockleftindent}%
  \begin{beamercolorbox}[colsep*=.75ex,wd=\blockwidth,vmode]{block body}%
    \ifbeamercolorempty[bg]{block body}{\vskip-.25ex}{\vskip-.75ex}\vbox{}%
}

Instead of using \hspace you could set \leftskip=\blockleftindent as suggested in the solution by @Herbert.

Explanation

The problem is that you cannot achieve that using \addtobeamertemplate: if you look at how the template is defined in beamerinnerthemedefault.sty

\defbeamertemplate*{block begin}{default}
{
  \par\vskip\medskipamount%
  \begin{beamercolorbox}[colsep*=.75ex]{block title}
    \usebeamerfont*{block title}\insertblocktitle%
  \end{beamercolorbox}%
  {\parskip0pt\par}%
  \ifbeamercolorempty[bg]{block title}
  {}
  {\ifbeamercolorempty[bg]{block body}{}{\nointerlineskip\vskip-0.5pt}}%
  \usebeamerfont{block body}%
  \begin{beamercolorbox}[colsep*=.75ex,vmode]{block body}%
    \ifbeamercolorempty[bg]{block body}{\vskip-.25ex}{\vskip-.75ex}\vbox{}%
}

you see that if you add code at the beginning, you are acting just before a \par is issued. So, unless you want to use black magic to have your code swallow the \par, you have to copy over the definition and change it according to your needs with \setbeamertemplate. Here I achieve the indentation simply by putting some \hspace before the two beamercolorboxes that contain the title and the contents. Other means to add that horizontal space may be used.

The alternative with \leftskip could be implemented using \addtobeamertemplate since the new \leftskip value would be used later when creating the beamerboxes. However to change the indentation on the right you need to modify the wd key of the beamer box environment, which requires again to use \setbeamertemplate.