My subfloat command is standard and simple:
\documentclass[12pt]{article}
\usepackage{graphicx,subfig,caption}
\begin{document}
\begin{figure}[h!]
\centering
\subfloat[illegitimate]{\includegraphics[width=4.5cm]{QR.eps}}
\qquad
\subfloat[legitimate]{\includegraphics[width=4.5cm]{anti02.eps}}
\caption{QR code}
\end{figure}
\end{document}
And I end up getting something like this, with the captions shifted away to the right:
p i c t u r e 1 p i c t u r e 2
(a) illegitimate (b) legitimate
Why are the captions shifted so far away instead of staying under the pictures? The pictures are of equal and appropriate sizes and there're plenty of space to move around!
Edit: I checked out the log file, which seems to say something's wrong with the picture anti02. What could be wrong, please?
LaTeX Warning: Label `' multiply defined.
) ABD: EveryShipout initializing macros
(E:\CTEX\MiKTeX\tex\latex\amsfonts\umsa.fd)
(E:\CTEX\MiKTeX\tex\latex\amsfonts\umsb.fd) [1] [2]
(E:\CTEX\MiKTeX\tex\latex\base\omscmr.fd) [3] [4] [5] [6] <QR.eps>
Underfull \hbox (badness 10000) in paragraph at lines 291--291
[]
Overfull \hbox (233.31259pt too wide) in paragraph at lines 291--291
[]
<anti02.eps>
Underfull \hbox (badness 10000) in paragraph at lines 293--293
[][]
Overfull \hbox (233.31259pt too wide) in paragraph at lines 293--293
[]
[7] [8] [9] [10] [11] [12] ("C:\Users\eric\Desktop\number guessing——test.aux"
)
2nd Edit: I removed this command:
\setcaptionwidth{5in}
in preamble and it worked right. But why?
Best Answer
If I modify your MWE so it starts with
as I don't have your eps files I get the following
which shows that it works. If you get the same, then remove the
draft
again and try outside of the figure, just in normal textIf the box does not surround the figure, it means that the bounding box in the file is incorrect and so the dimensions of the image are not as they appear. if that is the case you can fix the eps file or supply a corrected bounding box using the
bb= 1 2 3 4
key in the optional argument to\includegraphics
using the correct values not 1 2 3 4!