37

enter image description here

I am trying to align caption to the left but its coming centered. Please see the figure. The code is

\begin{figure}[!t]
\includegraphics[scale=0.22]{Figure 1.pdf}
\caption{The caption is coming to the center. It should be aligned to the left. }
\label{Figure 1}
\end{figure}

The previously mentioned solutions were tried. But they didn't work. How can I left-align a caption?

Any solution for the above problem.

A full MWE:

\documentclass[%
 aip,
 amsmath,amssymb,
]{revtex4-1}
\draft

\usepackage{graphicx}
\usepackage{dcolumn}
\usepackage{bm}
\usepackage{times}
\DeclareGraphicsExtensions{.pdf,.jpeg,.jpg, .png, .eps, .tiff}
\usepackage{epstopdf}
\usepackage{lipsum}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{array}
\usepackage{natbib}
\usepackage{color}
\usepackage{grffile}
\usepackage{caption}
\usepackage{boxhandler}
\usepackage{float}
\begin{document}

\begin{figure}[!t]
\centering
\includegraphics[scale=0.5]{Figure 3.pdf}
\caption{}   
\label{Figure 4}
\end{figure}
\end{document}
user87834
  • 763

3 Answers3

42

You should add the following instruction to the preamble, after loading the caption package:

\captionsetup{justification=raggedright,singlelinecheck=false}

If you want "hanging indentation" of multiline captions, you should add the option

format=hang

to the argument of \captionsetup.

A full MWE (with all packages not relevant for the issue at hand removed from the preamble):

enter image description here

\documentclass[aip,amsmath,amssymb,draft]{revtex4-1}
%%% \draft % this instruction is deprecated -- use 'draft' option instead

\usepackage[demo]{graphicx} % remove 'demo' option in real document
\usepackage{times}
\usepackage{caption}
\captionsetup{justification   = raggedright,
              singlelinecheck = false}
\begin{document}
\setcounter{figure}{2}  % just for this example

\begin{figure}[!t]
\includegraphics[width=\textwidth]{Figure3.pdf}
\caption{The caption is now no longer centered. Instead, it is left-aligned, which is also known as ``ragged-right''.}   
\label{fig:3}
\end{figure}

\end{document}
Mico
  • 506,678
  • caption is not recommended to be used with this class. Remove caption package and the captions are left aligned. Why OP loaded caption is not clear to me. Similarly \draft is obsolete over draft option. –  Oct 27 '15 at 06:40
  • @HarishKumar - Without the caption package, the captions will be fully justified only if they're longer than one line. Single-line captions will still be centered. – Mico Oct 27 '15 at 06:58
  • But caption is not compatible with revtex4-1, hence it will break something some where. –  Oct 27 '15 at 06:58
  • caption package is used for the working of \captionof in some of the figures. – user87834 Oct 27 '15 at 07:02
  • @HarishKumar - I can find no warning messages in the log file related to an incompatibility between the revtex4-1 class and the caption package. – Mico Oct 27 '15 at 07:03
  • @HarishKumar -- Really strange indeed. Could this be due to you (apparently) MikTeX 2.9 whereas I use TeXlive 2015? – Mico Oct 27 '15 at 07:20
  • @Mico: I have no clue. May be other people can check too. –  Oct 27 '15 at 07:27
  • @HarishKumar - My bad! The reason I wasn't getting the warning message was that I had commented out the caption-related directives! After reinstating the instructions, the warning does show up in the log file. That said, I honestly can't tell if the warning message is generated out of an overabundance of caution or because there are some real incompatibilities. For sure, the user guide of the caption package does not appear to mention problems with the revtex4-1 class. – Mico Oct 27 '15 at 08:43
  • The caption package just detects an incompatibility caused by an unknown version of \@makecaption, so this is a rather dump mechanism. Is this is a minor or major issue? No-one knows unless he/she takes a closer look at the sources, to see what exactly is happening, and what features of the revtex document class will be overwritten by loading the caption package. –  Oct 27 '15 at 09:23
  • what if figure is not textwidth? This solutions aligns with textwidth it seems but not with figure. – snoram Sep 14 '18 at 11:46
  • 1
    @snoram - Instead of width=\textwidth, one can of course set width=0.8\textwidth -- or any other width fraction less than 1. (For reasons that are hopefully obvious, one shouldn't make the figure wider than \textwidth.) If you choose a width factor less than 1, you should probably also supply the instruction \centering, in order to center the image file horizontally. – Mico Sep 14 '18 at 13:19
  • How do I change the colon in "Fig. 3: " to a period? – Rendicahya Oct 23 '19 at 07:48
  • 1
    @Rendicahya - Assuming your document loads the caption package, the way to to change from Figure 3: to Figure 3. is to specify the package option labelsep=period. If you use \captionsetup, just add labelsep=period to the list of comma-separated arguments of the \captionsetup. – Mico Oct 23 '19 at 14:18
  • This changes the format of the caption that is come from cls , is it possible to keep the font type and size unchanged? – alper Dec 08 '22 at 03:02
  • @alper - The entire purpose of using the caption package is to modify the format of captions selectively. However, unless one specifies options to the contrary, employing the caption package should not cause a change in font shape or size employed in captions. Which document class do you employ? – Mico Dec 08 '22 at 08:17
  • @Mico I was using \documentclass{ieeeccess} its template (https://ieeeaccess.ieee.org/wp-content/uploads/2022/01/LaTeX.zip) ; they use textbf{} and left-alignment for all table and figure captions. I just wanted to apply textbf{} to all figure and table captions but while keeping the original style such as Figure text color is blue ; note that I can as new question related to this – alper Dec 08 '22 at 10:35
  • @alper - Thanks. Yes, please go ahead and ask a new, self-contained question. – Mico Dec 08 '22 at 10:36
  • @Mico Thank you, hope it is clear: https://tex.stackexchange.com/q/667828/127048 – alper Dec 08 '22 at 11:23
2

The caption package is not recommended, as it interferes with the caption formatting of revtex. The boxhandler package doesn't seem to have this drawback.

A few comments about your code: ther's a warning in the .log file to inform that the draft command is obsolete and should be replaced with the draft option for the document class. The times package is also obsolete, and should be replaced with mathptmx or, better, newtxtext, newtxmath, which uses TeX Gyre Termes, a more complete clone of Times.

\documentclass[%
 aip,
 amsmath,amssymb,
]{revtex4-1}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{dcolumn}
\usepackage{bm}
\usepackage{newtxtext, newtxmath}
\DeclareGraphicsExtensions{.pdf,.jpeg,.jpg, .png, .eps, .tiff}
\usepackage{epstopdf}
\usepackage{lipsum}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{array}
\usepackage{natbib}
\usepackage{xcolor}
\usepackage{grffile}
\usepackage{boxhandler}
\usepackage{float}

\begin{document}

\bxfigure{\textit{Piero di Cosimo}, The Death of Procris (1495)}{\includegraphics[scale=0.4]{Piero_di_Cosimo_1}}

\end{document} 

enter image description here

Bernard
  • 271,350
2

I know this is a bit old, but I came across this after having a similar problem and found a simple solution that isn't mentioned for those who are just looking to use \captionof for figures (like in minipages as I was using).

The caption package has the wording in their docs: And if you are just interested in using the command \captionof, loading of the very small capt-of package is usually sufficient.

Changing \usepackage{caption} to \usepackage{capt-of} worked for me. Because capt-of is small, it doesn't interfere with other revtek captioning like full line usage -the caption uses the full line on both left and right side.

Mensch
  • 65,388
brian_ds
  • 143