# Beamer: Using \label for blocks adds vertical space

When adding a \label to a block in the beamer class, additional vertical space is inserted before the content.

This doesn't happen with the default block template, but setting using the rounded template introduces the space.

As far as I can see, a pgfpicture is used for the rounded blocks and afaik, also the tcolorbox package uses pgfpicter. Indeed, also for tcolorboxes, the vertical space is added. So my guess is, it has something to do with that.

How can I avoid this behaviour?

A simple but not very clean workaround would be to add a negative \vspace but I'd rather understand the origin of this …

MWE:

\documentclass[9pt]{beamer}

\setbeamercolor{block body}{bg=red!5}
\setbeamercolor{block title}{fg=black,bg=red!40}

\usepackage{tcolorbox}

\begin{document}
\begin{frame}
\begin{block}{Regular block}\label{thm:1}
I have a label.
\end{block}
\begin{block}{Regular block}
I don't have a label.
\end{block}

\begin{block}{Round block}\label{thm:2}%
I have a label.
\end{block}
\begin{block}{Round block}
I don't have a label.
\end{block}

\begin{tcolorbox}[title={tcolorbox}]\label{thm:3}
I have a label.
\end{tcolorbox}
\begin{tcolorbox}[title={tcolorbox}]
I don't have a label.
\end{tcolorbox}
\end{frame}
\end{document}


Produces:

Update: As suggested by @koleygr, I opened an issue in the beamer repo on GitHub.

• See the tcolobox manual, it has a whole section about labels and references – daleif Jul 28 at 17:00
• @daleif ... I think you didn't read the problem ... (Sorry if I am wrong... I will delete this comment in 5 mins) – koleygr Jul 28 at 17:12
• @koleygr I did read the question. And is referring to the manual as tcolorbox has its own build in handling of labels, you just have to pass is as a key option, not at the start of the env – daleif Jul 28 at 17:14
• ok @daleif... Thanks for your answer ...b ut it refers to blocks too without tcolorbox and the problem seems specific to beamer but tcolorbox can be used outside of it without this problem... (Just explained myself) – koleygr Jul 28 at 17:20
• Thanks for the hint @daleif. Indeed, I added the tcolorbox example mainly to support my guees that the issue is within pgfpicture – Hirsch Jul 28 at 17:47

Here is a Fix by redefining the environments:

\documentclass[9pt]{beamer}
\setbeamercolor{block body}{bg=red!5}
\setbeamercolor{block title}{fg=black,bg=red!40}

\usepackage{tcolorbox}
\newlength\myFSize
\newlength\myFontSize
\makeatletter
\setlength{\myFSize}{\f@size pt}
\setlength{\myFontSize}{0.5\myFSize}}
\makeatother

\newcounter{emptyLabelCounter}

\begin{document}
\begin{frame}
\begin{block}{Regular block}\label{thm:1}%
I have a label.
\end{block}
\begin{block}{Regular block}
I don't have a label.
\end{block}

\begin{myRBlock}{Round block}{thm:2}
I have a label.
\end{myRBlock}
\Large
\begin{myRBlock}{Round block}{}
I don't have a label.
\end{myRBlock}

\begin{myTcolorbox}[title={tcolorbox}]{thm:3}%
I have a label.
\end{myTcolorbox}
\begin{myTcolorbox}[title={tcolorbox}]{}
I don't have a label.
\end{myTcolorbox}
\end{frame}
\end{document}


PS: I added a label argument to each definition and an auto-label if empty.

• Thanks for the convenient fix! Do you know why there is a need for it? – Hirsch Jul 28 at 17:50
• @Hirsch ... Sorry ... it is just a Fix without reading the manual of tcolorbox at all (I don't use it). Possibly it is a bug of beamer's block as far as I understood and we could report it to the authors. – koleygr Jul 28 at 18:08
• No problem, thanks for the effort! I'll open an issue on GitHub. – Hirsch Jul 28 at 20:15
• Nice ... Then add the solution here and accept it as the real answer. – koleygr Jul 28 at 20:53