1

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

  • \begin{figure}[htbp] \centering \includegraphics[width=6cm]{example-image-a} \caption{Some really long caption here.} \end{figure}? – Troy Mar 2 '17 at 16:28
  • @Troy u get the same thing, it centers the caption as well, this is not what I'm looking for – jarhead Mar 2 '17 at 16:34
  • 1
    Are you running any other packages? The caption is left aligned for me. – Troy Mar 2 '17 at 16:35
  • @Troy, I've added my preamble in the end of the question in case u find somthing – jarhead Mar 2 '17 at 17:20
  • \centering should have no affect on the \caption (which is already \textwidth wide), The \captionsetup{singlelinecheck=off} will not center short captions either. – John Kormylo Mar 2 '17 at 17:35
1

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.

  • Again, it works with [H], but not with [htbp!], so what u suggest has not solved the problem – jarhead Mar 2 '17 at 17:55
  • 1
    @jarhead - Ah, I had completely missed the part, toward the end of your posting, about not actually wanting [H] and, instead, wanting [htbp!]. The caption package is known to have some conflicts with the revtex4-1 document class. I have to suggest that you not load the caption package. If you absolutely, positively must have the text in the caption typeset in footnotesize, all would suggest you start the argument of \caption with a \footnotesize directive. – Mico Mar 2 '17 at 18:07
  • @jarhead - I've posted an addendum to "formalize" my comments. – Mico Mar 2 '17 at 19:08
  • @Mico Not really “some conflicts”: it's simply incompatible. – egreg Mar 2 '17 at 21:47
  • @egreg - Thanks -- I've edited the sentence in question. – Mico Mar 2 '17 at 21:57
0

As it turns out, revtex-4 automatically turns centering on inside floats (note: [H] is not implemented using \@float).

I also discovered a bug of sorts in caption. Specifically, the justification=justified option does nothing, and therefore will not correct previous settings.

\documentclass[12pt,a4paper]{revtex4-1}
\usepackage[draft]{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}

\setlength{\parindent}{0pt}
\renewcommand\thesection{\arabic{section}}
\renewcommand\thesubsection{\alph{subsection}}

\DeclareCaptionJustification{justified}{\leftskip=0pt \rightskip=0pt \parfillskip=0pt plus 1fil}

\captionsetup{font=footnotesize,justification=justified}

\begin{document}

\begin{figure} [htbp!]
\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}

demo

  • The justification=justified option of the caption package does work with other document classes -- but not with revtex4-1. Not clear whether that's a "bug" in the caption` package or a plain-old incompatibility with the revtex4-1 document class. – Mico Mar 2 '17 at 20:23
  • 1
    @Micro - Hence the "of sorts". Interestingly, resetting \parfillskip etc. before caption doesn't work, nor has \caption been replaced by some other macro. – John Kormylo Mar 2 '17 at 20:34
  • FWIW, my userid is "Mico", not "Micro". But then, Marco Daniel has had to get used to being called "Macro"... – Mico Mar 2 '17 at 22:01
  • @Mico - I finally figure it out: revtec4-1 modifies the definition of \parbox to center the text. – John Kormylo Mar 2 '17 at 23:14
0

The caption package is not compatible with revtex4-1:

Package caption Warning: Unsupported document class (or package) detected,
(caption)                usage of the caption package is not recommended.
See the caption package documentation for explanation.

Since the class is intended for submissions to some journals, authors should not tamper with its setting: it's the copy editors' job to make the document up for publication and your changes will just annoy them and possibly cause rejection.

In particular, besides caption, also placeins and geometry should not be loaded. If you need subfloats, the package of choice is

\usepackage[caption=false]{subfig}

Just do

\begin{figure}[htpb]
\includegraphics[width=.5\textwidth]{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}

(choose whatever value you prefer for the width, but it would be better to have a PNG without scaling, because this will insert artifacts). The figure will be automatically centered.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.