Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
    
Maybe not an answer, but putting the tikz picture in a centred environment solves the problem. –  masmys Mar 9 at 13:55

1 Answer 1

up vote 4 down vote accepted

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}
share|improve this answer
    
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. –  Manuel Kuehner Mar 9 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 at 15:04
    
@ManuelKuehner Why are you centering? The blocks are centered by default. –  percusse Mar 9 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 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 at 15:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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