# Why does this \centering command not center a figure?

When using \centering this way, I get everything centered, text and figure:

\documentclass[varwidth=true,border=5pt]{standalone}
\usepackage{color}
\usepackage{tikz}

\newenvironment{nscenter}
{\parskip=0pt\par\nopagebreak\centering}
{\par\noindent\ignorespacesafterend}
\begin{document}
\centering
Generations lived here alone. Strangers this is our home! Strangers, this is our home! Welcome strangers, stay as our friends. The beauty of our land never ends.
\newline
\newline
\begin{tikzpicture}
\filldraw[orange] (-1.2, 0) circle  (5pt);
\filldraw[blue]   ( 2  , 0) circle  (2pt);
\draw             ( 0  , 0) ellipse (2 and 1);
\end{tikzpicture}
\end{document}


But this does not center anything:

\documentclass[varwidth=true,border=5pt]{standalone}
\usepackage{color}
\usepackage{tikz}

\newenvironment{nscenter}
{\parskip=0pt\par\nopagebreak\centering}
{\par\noindent\ignorespacesafterend}
\begin{document}
Generations lived here alone. Strangers this is our home! Strangers, this is our home! Welcome strangers, stay as our friends. The beauty of our land never ends.    \newline
\newline
\begin{tikzpicture}
\centering
\filldraw[orange] (-1.2, 0) circle  (5pt);
\filldraw[blue]   ( 2  , 0) circle  (2pt);
\draw             ( 0  , 0) ellipse (2 and 1);
\end{tikzpicture}
\end{document}


The use of domain \begin{center}...\end{center} did not work either. Have gone through the other questions: scaling, \par, frames, etc., ...nothing.

Update: I try to center the figure with respect to the rest of the text in the simplest way possible (minimal latex writing and packages imported).

Note: Text on the document updated, just to show that the text means a width larger than the image.

• Why would you expect that a \centering inside a tikzpicture centers the diagram? Apr 5 '17 at 17:48
• I've seen it used this way somewhere, but may be it wasn't a good idea... Apr 5 '17 at 17:52
• Here it is just ignored. What exactly are you trying to center and in relation to what? Apr 5 '17 at 17:55
• Unable to reproduce problem, using pdflatex. When the varwidth option is used, the drawing (which is largest) is automatically ccentered, whether or not you specify centering. When varwidth is not use, nothing is centered, in either case.
– user103221
Apr 5 '17 at 17:55
• @daleif I try to center the figure with respect to the rest of the text in the simplest way possible (minimal latex writing and packages imported). Apr 5 '17 at 17:57

The most natural way to centre something is the center environment

\documentclass{article}
\usepackage{tikz}
\begin{document}

\hrule

\begin{center}
\begin{tikzpicture}
\filldraw[orange] (-1.2, 0) circle  (5pt);
\filldraw[blue]   ( 2  , 0) circle  (2pt);
\draw             ( 0  , 0) ellipse (2 and 1);
\end{tikzpicture}
\end{center}

\hrule

\end{document}


Or with standalone:

\documentclass[varwidth=true,border=5pt]{standalone}
\usepackage{color}
\usepackage{tikz}

\begin{document}
This is our home
\newline% bad use makes underfull box
\newline % bad use makes underfull box

\begin{center}
\begin{tikzpicture}
\filldraw[orange] (-1.2, 0) circle  (5pt);
\filldraw[blue]   ( 2  , 0) circle  (2pt);
\draw             ( 0  , 0) ellipse (2 and 1);
\end{tikzpicture}
\end{center}
\end{document}


or with standalone and the longer text in the edited question

• For some extrange reason, that solution is not working if I just add the \begin{center}...\end{center} environment to the text in the question (2nd one) and delete the \centering command. Apr 5 '17 at 18:54
• @nightcod3r well obviously it can not work in standalone as you are there you are making the page as wide as the picture so there is nothing to centre. Apr 5 '17 at 19:11
• Could you please update the figure with the new text in the question? Just to show that it means a wider page. Apr 5 '17 at 19:21
• I'm trying to figure it out... cause this is not what I get. The file is rendered with this command: texfot --quiet --interactive pdflatex -shell-escape file.tex > /dev/null 2>&1 && \  Apr 5 '17 at 19:35
• @nightcod3r I have no idea what texfot is, the above is made with an up to date texlive 2016 pdflatex. Apr 5 '17 at 20:10