Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question

3 Answers 3

Indent is 0.1 and the new textwidth is 0.9 of the old one.

\documentclass{beamer}
\usetheme{Antibes}
\setbeamertemplate{block begin}{%
  \par\vskip\medskipamount\leftskip=0.1\textwidth%
  \begin{beamercolorbox}[colsep*=.75ex,wd=0.9\textwidth]{block title}
    \usebeamerfont*{block title}\insertblocktitle%
  \end{beamercolorbox}%
  {\parskip0pt\par}%
  \ifbeamercolorempty[bg]{block title}
  {}
  {\ifbeamercolorempty[bg]{block body}{}{\nointerlineskip\vskip-0.5pt}}%
  \leftskip=0.1\textwidth\usebeamerfont{block body}%
  \begin{beamercolorbox}[colsep*=.75ex,vmode,wd=0.9\textwidth]{block body}%
    \ifbeamercolorempty[bg]{block body}{\vskip-.25ex}{\vskip-.75ex}\vbox{}%
}

\begin{document}

\frame{%
foo
\begin{block}{}
  Indent me! 
\end{block}%
}

\end{document}

enter image description here

share|improve this 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.

share|improve this answer
    
Perhaps add functionality to set the right indent of the box as well... –  Werner Dec 19 '13 at 19:33
    
@Werner I added right/left indentation. Similar results can be obtained with \rightskip and \leftskip as suggested by @Herbert –  Bordaigorl Dec 19 '13 at 19:47
    
Actually setting \addtobeamertemplate{block begin}{ \setlength{\textwidth}{0.5\textwidth} \leftskip=10ex } works, I might add it as a separate answer –  Bordaigorl Dec 19 '13 at 20:04

Using \leftskip and \textwidth one can manipulate the spacing without resorting to redefining the template

\addtobeamertemplate{block begin}{%
  \setlength{\textwidth}{.5\textwidth}% HERE YOU SET THE DESIRED WIDTH OF THE BLOCK
  \leftskip=10ex% HERE YOU SET THE DESIRED LEFT MARGIN
  \addtolength{\textwidth}{-\leftskip}%
}

leading to a more concise solution than the one I proposed in the other answer. Instead of \setlength you could also use

\addtolength{\textwidth}{-<rightindent>}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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