4

I'm facing a problem with the block environment in beamer. Adding a tikzpicture seems to offset the following block slightly to the right. What is causing that behaviour and how can I prevent it?

\documentclass{beamer}
\usetheme{Berlin}

\usepackage{tikz}

\begin{document}

% as expected

\begin{frame}{Test}
\begin{block}{centered}
Test
\end{block}

\centering

\begin{tikzpicture}
\node [] (box){%
    dsdsadsad
};
\end{tikzpicture}%

\begin{block}{not properly centered}
Test
\end{block}

\end{frame}

\end{document}

enter image description here

  • Maybe not an answer, but putting the tikz picture in a centred environment solves the problem. – mas Mar 9 '14 at 13:55
4

The \centering declaration, not the \tikzpicture environment, is to blame for this undesirable horizontal offset you report; if you comment the tikzpicture out but leave \centering in, your second block gets gets offset to the right as well.

Edit: see percusse's comment and disregard my earlier divagations. Simply use a center environment instead of an unscoped \centering (which messes things up), here.

screenshot of output

\documentclass{beamer}
\usetheme{Berlin}

\usepackage{tikz}

\begin{document}

\begin{frame}{Smoking the culprit (\texttt{\string\centering}) out\ldots}
\begin{block}{centered}
Test
\end{block}

\centering           %<---- this causes the horizontal offset...

%\begin{tikzpicture} %<--- not the tikzpicture
%\node [] (box){%
%    dsdsadsad
%};
%\end{tikzpicture}%

\begin{block}{not properly centered}
Test
\end{block}
\end{frame}

\begin{frame}{Using a \texttt{center} environment instead}
\begin{block}{centered}
  Test
\end{block}

\begin{center}
    \begin{tikzpicture}
    \node [] (box){%
        dsdsadsad
    };
    \end{tikzpicture}%
\end{center}

\begin{block}{not properly centered}
  Test
\end{block}
\end{frame}

\end{document}
  • Thanks. I learned that \centering is better than the center environment because the center environment includes additional white space. See ftp.dante.de/tex-archive/info/l2tabu/english/l2tabuen.pdf (Section 3.1). Ahhh... I see there is a difference between the center and centering environment. – Dr. Manuel Kuehner Mar 9 '14 at 15:03
  • 1
    @ManuelKuehner The \centering macro is appropriate in many cases, but in beamer, if you need to center something horizontally, a centering environment seems preferable to both \centering or a center environment. – jubobs Mar 9 '14 at 15:04
  • @ManuelKuehner Why are you centering? The blocks are centered by default. – percusse Mar 9 '14 at 15:41
  • @percusse I think Manuel wants to center the tikzpicture. I've just realised that centering doesn't do that... – jubobs Mar 9 '14 at 15:55
  • 1
    Aah, OK sorry. I have a headerless and transparent block for such stuff. It keeps things scoped automatically and might be a safer approach than leaving \centering unscoped – percusse Mar 9 '14 at 15:58

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.