# my centering command does not work! why?

I am going to plot a bar histogram using the following command:

\documentclass[a4paper]{report}‎
\usepackage{pgfplots}‎
\begin{document}‎
\begin{tikzpicture}‎
\centering‎
\begin{axis}[‎
xbar,‎‎
height=4.5cm,‎
width=13cm,
bar width=0.2cm,‎
legend style={at={(0.5,-0.21)},‎
enlarge x limits={upper,value=0.25},‎
xmin=-2,xmax=110,‎
anchor=north,legend columns=-1},‎
ylabel={\ Data size}, ‎x‎label={\ Computation time(sec)},‎
symbolic y coords={1024 by 1024‎,512 by 512,256 by 256},‎
ytick=data,‎
nodes near coords,‎
nodes near coords align=horizontal,‎
]‎
\addplot coordinates {(108.3,1024 by 1024) (14.22,512 by 512) (1.7,256 by 256)‎
};‎
\addplot coordinates {(3.5,1024 by 1024) (0.85,512 by 512) (0.21,256 by 256)‎
};‎
\legend{Conventional method,Butterfly-based method}‎
\end{axis}‎
\end{tikzpicture}‎
\end{document}‎
‎


but my histogram is not at the center of my page, my table is like this:

How can I put it at the middle relative to the left and right of my page? How can I reduce the space between columns?

• you want to centre the picture so \centering should be before \begin{tikzpicture} – David Carlisle Jul 4 '15 at 19:46

\centering after \begin{tikzpicture} does nothing: use a center environment, but also use a relative width, because 13cm is most likely too big for the text width.

\documentclass[a4paper]{report}
\usepackage{pgfplots}
\begin{document}

\begin{center}
\begin{tikzpicture}
\begin{axis}[
xbar,
height=4.5cm,
width=.8\textwidth, % <------- relative width
bar width=0.2cm,
legend style={at={(0.5,-0.21)},
enlarge x limits={upper,value=0.25},
xmin=-2,xmax=110,
anchor=north,legend columns=-1},
ylabel={\ Data size},
xlabel={\ Computation time(sec)},
symbolic y coords={1024 by 1024,512 by 512,256 by 256},
ytick=data,
nodes near coords,
nodes near coords align=horizontal,
]
\addplot coordinates {(108.3,1024 by 1024) (14.22,512 by 512) (1.7,256 by 256)
};
\addplot coordinates {(3.5,1024 by 1024) (0.85,512 by 512) (0.21,256 by 256)
};
\legend{Conventional method,Butterfly-based method}
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}


If you have a figure environment around the plot, then you should type

\begin{figure}
\centering

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

\caption{The caption}\label{thelabel}

\end{figure}


For producing the picture I used the showframe package, so the boundaries of the text block are shown.

• how can I reduce the space between bars? – user3482383 Jul 4 '15 at 20:01
• @user3482383 That is a completely different question and in this site we like to keep, if possible, one question per post. If, after searching for similar questions in this site you don't find an answer for this new requirement, please feel free to open a fresh new question. – Gonzalo Medina Jul 4 '15 at 20:04