144

Possible Duplicate:
Should I use center or centering for figures and tables?

What is the correct way to cause a \tikzpicture to be centered? By default it appears to be aligned with the left margin.

3 Answers3

123

When the picture doesn't need to be put in a figure (i.e. when it doesn't need a caption), I use

\begin{center}
 \begin{tikzpicture}
  ....
 \end{tikzpicture}
\end{center}
David Z
  • 12,084
  • 7
  • 48
  • 65
  • 11
    In my case the picture is too wide, so it breaks the right margin. Is there a way to make it break the left and right margins equally? – Thomas Ahle Oct 24 '13 at 14:14
121
\begin{figure}[!h]
\centering
\tikz
\end{figure}
Mica
  • 4,629
  • 2
    Hi, just want to share a sublety: I applied this solution and I got the following error: "There's no line here to end." I found the error was caused by using line-breaking (//) within an edge label. I just removed the line-breaking and all worked well. – FSp Feb 25 '15 at 15:42
  • 4
    The figure environment doesn't just center the tikzpicture, it also adds a caption and some vertical spacing, which may not be desired. – PatrickT Feb 14 '21 at 05:56
8

\hbox to \hsize{\hfil{Anything}\hfil}