Make frametitle and block the same width in Beamer

2,533

In the traditional definition of the beamer blocks there is more space around the actual text. To get blocks of the same width as the one in the headline template, the beamercolorboxes of which the beamer blocks consist, where redefined with the settings [wd=\textwidth, ht=0.5cm, dp=0.2cm] taken from the headline template.

\documentclass[t]{beamer}

\setbeamercolor{frametitle}{fg=white, bg=blue}
\setbeamercolor{block body}{fg=white, bg=red}
\setbeamercolor{block title}{fg=white, bg=green}
\setbeamertemplate{frametitle}{%
\begin{beamercolorbox}[wd=\textwidth, ht=0.5cm, dp=0.2cm]{frametitle}
\usebeamerfont{frametitle}\insertframetitle
\end{beamercolorbox}
}
\begin{document}


\setbeamertemplate{block begin}{
    \begin{beamercolorbox}[wd=\textwidth, ht=0.5cm, dp=0.2cm]{block title}%
    \usebeamerfont*{block title}%
        {\rule[-0.4ex]{0mm}{2ex}\insertblocktitle}%
            \end{beamercolorbox}%
    {\ifbeamercolorempty[bg]{block body}{}{\nointerlineskip\vskip-0.5pt}}%
    \usebeamerfont{block body}%
    \begin{beamercolorbox}[wd=\textwidth, ht=0.5cm, dp=0.2cm]{block body}%
        \ifbeamercolorempty[bg]{block body}{\vskip-.25ex}{\vskip-.75ex}\vbox{}%
    }
    \setbeamertemplate{block end}{
    \end{beamercolorbox}
    \vspace*{.25cm}
}

\begin{frame}{This is the frame title}
\begin{block}{Block title}
This is the block content
\end{block}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus
elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur
dictum gravida mauris. 
\end{frame}

\end{document}

enter image description here

Share:
2,533

Related videos on Youtube

marczellm
Author by

marczellm

Updated on June 03, 2020

Comments

  • marczellm
    marczellm over 3 years

    Consider this MWE:

    \documentclass[t]{beamer}
    \setbeamercolor{frametitle}{fg=white, bg=blue}
    \setbeamercolor{block body}{fg=white, bg=red}
    \setbeamercolor{block title}{fg=white, bg=green}
    \setbeamertemplate{frametitle}{%
    \begin{beamercolorbox}[wd=\textwidth, ht=0.5cm, dp=0.2cm]{frametitle}
    \usebeamerfont{frametitle}\insertframetitle
    \end{beamercolorbox}
    }
    \begin{document}
    
    \begin{frame}{This is the frame title}
    \begin{block}{Block title}
    This is the block content
    \end{block}
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus
    elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur
    dictum gravida mauris. 
    \end{frame}
    
    \end{document}
    

    Which yields:

    beamer frame

    I can make the colorbox containing the frametitle the same width as the normal text by setting the width of the beamercolorbox to \textwidth. How can I make all colored blocks be the same width?

  • cfr
    cfr almost 9 years
    This works only if the block content does not run to multiple lines. That is, it forces the height of the block content to be equal to the height of the frame and block titles. While that works OK for those cases (provided the titles fit on a single line), it doesn't work well for typical block content. See tex.stackexchange.com/questions/217814/….