3

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 …

Looking forward to your answers :)


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}

        \setbeamertemplate{blocks}[rounded][shadow=false]

        \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:enter image description here


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
1

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
\def\ReadFSize{%
\setlength{\myFSize}{\f@size pt}
\setlength{\myFontSize}{0.5\myFSize}}
\makeatother

\newcounter{emptyLabelCounter}

\newenvironment{myRBlock}[2]{\def\X{#2}\begin{block}{#1}\ifx\X\empty\stepcounter{emptyLabelCounter}\label{labelEmpty:\X}\else\label{#2}\fi\ReadFSize\vskip-\myFontSize\par}{\end{block}\vskip-\myFontSize}
\newenvironment{myTcolorbox}[2][]{\ReadFSize\par\begin{tcolorbox}[#1]\ifx\X\empty\stepcounter{emptyLabelCounter}\label{labelEmpty:\X}\else\label{#2}\fi\vskip-0.6\myFontSize}{\end{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}

        \setbeamertemplate{blocks}[rounded][shadow=true]

        \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.

enter image description here

  • 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
  • 1
    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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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