[Tex/LaTex] Centering figure but not caption

floatsrevtex

I would like to center an image but keep the caption aligned with the margins ( not centered).
When using [H] (here precisely):

\begin{figure} [H]
\includegraphics[scale=0.8]{figures/mass.png}
\caption{The ordered and blac aldl dsjfd f eheher erhrhr erher rher h er h wer werh erher er rher erh  erh erhr erh er erherw werh rh erh  h werrfhwerhwer erioer ier ier ierw werui weriu weriufieruirehweriheih wei i i i eri uire rhh rh erh er werihwer ierh eriher ih }
\label{fig:01}
\end{figure}

I get:
enter image description here

The caption is the way I want it, but the image is to the side.

If I add the following command:

\begin{figure} [H]
\centerline{\includegraphics[scale=0.8]{figures/mass.png}}
\caption{The ordered and blac aldl dsjfd f eheher erhrhr erher rher h er h wer werh erher er rher erh  erh erhr erh er erherw werh rh erh  h werrfhwerhwer erioer ier ier ierw werui weriu weriufieruirehweriheih wei i i i eri uire rhh rh erh er werihwer ierh eriher ih }
\label{fig:01}
\end{figure}

I get a centered image and the caption where I wish:
enter image description here

However, I don't want to use [H], I want to use [h]/[ht]/[htbp!]. If I change that, for example:

\begin{figure} [htbp!]
\centerline{\includegraphics[scale=0.8]{figures/mass.png}}
\caption{The ordered and blac aldl dsjfd f eheher erhrhr erher rher h er h wer werh erher er rher erh  erh erhr erh er erherw werh rh erh  h werrfhwerhwer erioer ier ier ierw werui weriu weriufieruirehweriheih wei i i i eri uire rhh rh erh er werihwer ierh eriher ih }
\label{fig:01}
\end{figure}

I get:
enter image description here

Then the image is centered, but also the caption, and this is not what I want.

This what in my preamble:

\documentclass[12pt,a4paper]{revtex4-1}
\usepackage{graphicx}% Include figure files
\usepackage{bm}% bold math
\usepackage[usenames]{color}
\usepackage[all]{xy}
\usepackage{amsmath}
\usepackage{natbib}
\usepackage{placeins}
\usepackage{verbatim}
\usepackage[top=0.59in,bottom=0.59in,left=0.59in,right=0.59in]{geometry}
\usepackage{amssymb}
\usepackage{float}
\usepackage[nice]{nicefrac}
\usepackage{chemmacros}
\usepackage{caption}
\usepackage[font=footnotesize]{caption}
\setlength{\parindent}{0pt}
\renewcommand\thesection{\arabic{section}}
\renewcommand\thesubsection{\alph{subsection}}

please provide a simple solution.

cheers

Best Answer

Don't use \centerline -- use \centering instead.

\documentclass[12pt,a4paper,demo]{revtex4-1} % remove 'demo' option in real document
\usepackage{float,graphicx}
% removed all other packages
\begin{document} 
\begin{figure}[H]
\centering
\includegraphics[scale=0.8]{figures/mass.png}
\caption{The ordered and blac aldl dsjfd f eheher erhrhr erher rher h er h wer werh erher er rher erh  erh erhr erh er erherw werh rh erh  h werrfhwerhwer erioer ier ier ierw werui weriu weriufieruirehweriheih wei i i i eri uire rhh rh erh er werihwer ierh eriher ih }
\label{fig:01}
\end{figure}
\end{document}

Addendum, posted after the OP drew my attention to the fact that [htbp] should be used, rather than [H]. The caption package is known to be incompatible with the revtex4-1 document class. Therefore, the best suggestion I can make is that you not load the caption package at all. If the text of the caption simply has to typeset in footnote size -- and I can't think of a good reason for this, since you're presumably using the revtex4-1 document for some good reason -- you could place a \footnotesize directive at the start of the argument of the \caption instruction.

Related Question