# Make frametitle and block the same width in Beamer, attempt 2

In some of my Beamer themes I used the answer at Make frametitle and block the same width in Beamer.

However now an issue has been raised which is demonstrated by the following MWE:

\documentclass{beamer}
\setbeamertemplate{block begin}{
\begin{beamercolorbox}[wd=\textwidth, ht=0.5cm, dp=0.2cm, leftskip=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, leftskip=0.2cm]{block body}%
\ifbeamercolorempty[bg]{block body}{\vskip-.25ex}{\vskip-.75ex}\vbox{}%
}
\setbeamertemplate{block end}{
\end{beamercolorbox}
\vspace*{.25cm}
}
\setbeamertemplate{frametitle}{
\vspace*{0.3cm}
\begin{beamercolorbox}[wd=\textwidth, dp=0.3cm, ht=0.9cm, leftskip=0.2cm]{frametitle}
\usebeamerfont{frametitle}\insertframetitle%
\end{beamercolorbox}
}
\setbeamercolor{block title}{bg=yellow}
\setbeamercolor{frametitle}{bg=yellow}

\begin{document}
\begin{frame}{Block}
This is text before the block.
\begin{block}{blocktitle} some text here
\begin{itemize}
\item This is an item in the block.
\end{itemize}
This is text after the itemize.
\end{block}
This is text after the block.
\end{frame}
\end{document}


As you can see, the block title, block body and the surrounding text gets all messed up and overlapped. Please help me solve this! It is also very important that the colored box containing the frametitle and the colored box containing the block title (and the colored box containing the block body, if there's any) stays the same width.

• Note that you typically need to attribute code used from TeX.SE under the licensing terms of the site. (Unless that code is also available from the author under a different licence which doesn't require this.) You can't generally just take it and publish it under your own name. – cfr Dec 14 '14 at 0:30
• You can check this question to see if a user allows reuse under a more permissive licence. This licence (referenced by the SE's terms) covers all code posted, whether or not a user also makes it available under another licence. – cfr Dec 14 '14 at 0:37
• @cfr Does it fulfill the licensing requirements if I put a text file with attributions and license link in the repository root, or do I have to bloat my code files with it? – marczellm Dec 14 '14 at 10:21
• Sorry, I don't know. That's a legal question and so off-topic here. I tend to put it in the code, but I don't know that that is needed. (It just makes it easier for me to track e.g. if I use the same code again, I see immediately that I'm using code from a particular source.) – cfr Dec 14 '14 at 17:00

I'm pretty convinced this code has issues but it does seem to solve the immediate problem. The linked solution sets a fixed height for the block equal to that set for the block and frame titles. You don't need an itemisation to show the problem - just multiple lines of text.

\documentclass{beamer}
\setbeamertemplate{block begin}{
\vskip\baselineskip
\begin{beamercolorbox}[wd=\textwidth, ht=0.5cm, dp=0.2cm, leftskip=0.2cm]{block title}%
\usebeamerfont*{block title}%
{\rule[-0.4ex]{0mm}{2ex}\insertblocktitle}%
\end{beamercolorbox}%
{\nointerlineskip\vskip-0.5pt}%
\usebeamerfont{block body}%
\begin{beamercolorbox}[wd=\textwidth, leftskip=0.2cm]{block body}%
\vskip-.75ex\vbox{}%
}
\setbeamertemplate{block end}{
\end{beamercolorbox}
\vspace*{.25cm}
}
\setbeamertemplate{frametitle}{
\vspace*{0.3cm}
\begin{beamercolorbox}[wd=\textwidth, dp=0.3cm, ht=0.9cm, leftskip=0.2cm]{frametitle}
\usebeamerfont{frametitle}\insertframetitle%
\end{beamercolorbox}
}
\setbeamercolor{block title}{bg=yellow}
\setbeamercolor{frametitle}{bg=yellow}

\begin{document}
\begin{frame}{Block}
This is text before the block.

\begin{block}{blocktitle} some text here
\begin{itemize}
\item This is an item in the block.
\end{itemize}
This is text after the itemize.
\end{block}
This is text after the block.
\end{frame}
\end{document}