4

How to align tikzpicture outside figure environment without introducing vertical space? I'm aware of related questions, such as What is the correct way to center a \tikzpicture? and Should I use center or centering for figures and tables?. From there I notice that the following code:

\begin{center}
 \begin{tikzpicture}
  ....
 \end{tikzpicture}
\end{center}

does the center alignment of the tikzpicture as desired but it introduces unwanted vertical space. I tried to simply replace the \begin{center} \end{center} pair with \begin{centering} \end{centering}, but it doesn't work.

1 Answers1

5

\centering is not intended to be an environment.

Just use

{\centering
\begin{tikz....

 \end{tikz...}

 }

and make sure that a blank line or end of the current environment is in scope of the declaration. You probably ended \end{centering} immediately after \end{tikzpicture} which would have finished centering before the paragraph finished, with the effect that the centering was ignored as TeX only consults line breaking parameters at the end of the paragraph and applies them to the whole paragraph.

David Carlisle
  • 757,742
  • But since the tikzpicture is outside figure environment, \centering would make all things below this command aligned center as well. Is there any way to avoid this? – Indra Yudhistira Feb 22 '13 at 15:30
  • Unfortunately it doesn't work. Even a code as simple as {\centering sometexts} doesn't work. – Indra Yudhistira Feb 22 '13 at 17:24
  • have you a blank line before the } it will not work if you go {\centering sometexts} for the reasons I give in the answer. – David Carlisle Feb 22 '13 at 17:25
  • You mean {\centering sometexts } ? It doesn't work either. Sorry if I misunderstand what you mean correctly here. – Indra Yudhistira Feb 22 '13 at 17:43
  • As always you should post a complete small document from \documentclass to \end{document} if \centering works but makes the whole document centered then {\centering stuff blank-line} will center just the stuff between { and } – David Carlisle Feb 22 '13 at 18:36
  • Ah, I just realized that did only put a whitespace instead of a blank line. Now it works very well. Never thought the solution would be that simple. Thanks! – Indra Yudhistira Feb 22 '13 at 19:30
  • I just tried \par as well as \\ to substitute the blank space. Turns out that they work as well. – Indra Yudhistira Feb 22 '13 at 20:06