# [Tex/LaTex] How to center a pgfplot?

horizontal alignmentpgfplots

I am trying to center a graph made with pgfplots with \centering. If I put \centering within a group to limit its scope, the graph does not get centered. If I don't limit the scope of \centering, then everything gets centered.

\documentclass{minimal}
\usepackage{pgfplots}

\begin{document}
This text should not be centered, but the graph should be.

% \begingroup
\centering
\begin{tikzpicture}
\begin{axis}
\addplot coordinates { (0, 0) (1, 1)};
\end{axis}
\end{tikzpicture}
% \endgroup

This text should not be centered.
\end{document}


There is nothing special about tikzpicture here you would see the same with

{\centering X}


\centering works by setting the paragraph parameters, so if you close the group before the paragraph ends then nothing happens. You can use

{\centering
X

}


To centre an X (or a tikzpicture). Or more naturally use

\begin{center}
X
\end{center}


which also adds some vertical space.