# Best way to centre figure in float [duplicate]

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

There are (at least) two ways of centering a single figure / graphic horizontally in a figure float:

1) using \begin{centering} in the float

2) using a \hfill left and right of the figure

What is the better / more robust / more LaTeX way of doing this?

-
The question you refer to does not include the \hfill option, so I do not think it is a duplicate –  Rainer Sep 12 '12 at 15:10
\begin{centering} is wrong. It's \centering. The reason why it still compiles is that \begin{foo} calls \foo and \end{foo} calls \endfoo if it exists. You might have confused it with \begin{center}, but it should not be used in floats because it is intended for normal texts and therefore adds vertical space. –  Martin Scharrer Sep 12 '12 at 15:10
Nope - I used it on purpose, because this is what I saw somehwere. –  Rainer Sep 12 '12 at 15:17
@Rainer: Well, its still wrong ;-) Please add @username (without any spaces, i.e. @MartinScharrer in my case) to your comments if you answer other comments, so that this user gets notified. The author of the Q or A where the comments are placed under is always notified. –  Martin Scharrer Sep 12 '12 at 15:27

## marked as duplicate by lockstep, Garbage Collector, Harish Kumar, percusse, cgniederSep 12 '12 at 21:46

The recommended way is

\begin{figure}
\centering\includegraphics{whatever}
\caption{A nice figure.}
\end{figure}


The center environment adds additional unnecessary space around the float.

-
So something like '\renewenvironment{figure}[1][]{ \@float{figure} \centering} {\end@float}' would be the best if it concerns all floats? –  Rainer Sep 12 '12 at 15:04
@IanThompson: no, that makes only sense when you have a \caption. without a caption a center environment is the better choice. –  Herbert Sep 12 '12 at 15:04
@Herbert --- Good point. I never even considered a float without a caption. –  Ian Thompson Sep 12 '12 at 15:05
@IanThompson I agree with Herbert: if a figure can't float, then it doesn't need a caption, because it's part of the text it's in. If it needs a caption, then it may be let to float. However this is more likely for tables than figures. –  egreg Sep 12 '12 at 15:11
looks a lot like @lockstep's answer –  cmhughes Sep 12 '12 at 15:19

As explained in Should I use center or centering for figures and tables? \centering is recommended. It's AFAIK the standard way to do it. The center environment should not be used because it adds vertical space and is not intended for images. \hfill is a low-level TeX macro, not a LaTeX macro. It can be used by experienced users to get special behavior but should only be used if required.

Note that you can also center (or right align) images easily using my adjustbox package. It allows you to add a center key to \includegraphics or even turn an image directly into a figure:

\documentclass{article}

\usepackage{mwe}% For example images only

\begin{document}

\blindtext

\begin{figure}
\centering
\includegraphics[width=.8\textwidth]{image}
\label{fig:example1}
\end{figure}
\blindtext

\begin{figure}
\includegraphics[width=.8\textwidth,center]{image}
\label{fig:example2}
\end{figure}

\blindtext