4

If I remove the tikzpicture in the following MWE, the block moves upward.

\documentclass{beamer}
\usepackage{tikz}
\begin{document}
    \begin{frame}[t]{Title}
        \begin{tikzpicture}[overlay]
            \draw (5pt,5pt) circle (10pt);
        \end{tikzpicture}
        \begin{block}{Theorem}
            text
        \end{block}
    \end{frame}
\end{document}

How is this possible?

Does the tikzpicture introduce some space?

If I use a resizebox around the tikzpicture I get a division by zero, so it does have size zero, but still it moves the block. How is this possible?

In this specific case I can just move the tikzpicture below the block, but how can I remove the extra space added in general?

1 Answer 1

3

It is not the tikzpicture directly, it is leaving vertical mode that shifts the block. That includes a tikzpicture, or even an \mbox{}.

\documentclass{beamer}
\usepackage{tikz}
\begin{document}
    \begin{frame}[t]{Title}
%        \begin{tikzpicture}[overlay]
%            \draw (5pt,5pt) circle (10pt);
%        \end{tikzpicture}%
        \leavevmode%
        \begin{block}{Theorem}
            text
        \end{block}
    \end{frame}
\end{document}

enter image description here

For comparison, here it is without leaving vertical mode:

enter image description here

One solution to keep the block in vertical mode is to place it in a \vbox:

\documentclass{beamer}
\usepackage{tikz}
\begin{document}
    \begin{frame}[t]{Title}
        \begin{tikzpicture}[overlay]
            \draw (5pt,5pt) circle (10pt);
        \end{tikzpicture}%
        \vbox{\begin{block}{Theorem}
            text
        \end{block}}
    \end{frame}
\end{document}

enter image description here

Perhaps better is to put the tikzpicture as the first thing inside of the block:

\documentclass{beamer}
\usepackage{tikz}
\begin{document}
    \begin{frame}[t]{Title}
        \begin{block}{Theorem}
          \begin{tikzpicture}[overlay]
              \draw (5pt,5pt) circle (10pt);
          \end{tikzpicture}%
            text
        \end{block}%
    \end{frame}
\end{document}

enter image description here

5
  • Thank you! Do you know how to prevent tikzpicture from leaving vertical mode?
    – Carucel
    Commented Jul 3, 2017 at 20:42
  • @Carucel Please see edit. Commented Jul 3, 2017 at 20:44
  • I hope this is not too much of a perky question, but do you happen to know a solution that only involves the tikzpicture? The tikzpicture is actually included in a command of me like \insertglobalcircle and I would like to be able to use this command without changing the rest of the frame.
    – Carucel
    Commented Jul 3, 2017 at 20:50
  • @Carucel You could put the original tikzpicture as the first thing inside of the block. Does that violate your requirement? Commented Jul 3, 2017 at 20:54
  • 1
    I would really like to be able to place the tikzpicture anywhere. I ended up doing \ifvmode\vspace*{-1.2em}\else\fi before the tikzpicture, which was not able without your help. Thank you!
    – Carucel
    Commented Jul 3, 2017 at 21:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .