1

I am trying to center figures along their horizontal axis using the example in Sec. 5.4 of subfig, but no matter what I do, this is what I'm seeing. Even when I exaggerate the figures' widths so that there's no way they could overlap, like so:

the problem

I am using the following code and packages. The block of code was copied directly from the example in the subfig documentation.

\documentclass[12pt]{report}
\usepackage{graphicx}
\usepackage{subfig}
\graphicspath{{Figures/}}
\newsavebox{\tempbox}

\begin{document}

\begin{figure}%
  \centering
  \sbox{\tempbox}{\includegraphics[width=1in]{I_Am_A_Red_Square}}%
  \subfloat[Big figure]{\usebox{\tempbox}}%
  \qquad
  \subfloat[Small figure]{%
    \vbox to \ht\tempbox{%
      \vfil
      \includegraphics[width=0.25in]{I_Am_A_Red_Square}
      \vfil}}%
  \caption{Two more sub-floats.}
\end{figure}

\end{document}

I would have preferred to use subcaption, but it does not appear to be compatible with the template I'm required to use for my dissertation.

What can I do to fix this?

Edit: I wasn't clear about the scope of the problem. I am trying to get the figures to sit next to each other, not stack vertically. Everything I do seems to just adjust the figures' sizes, still one above the other, not side-by-side. I'll try and come up with a MWE.

Edit #2: Updated with a proper code example. This is the document generated using the above code:

Update #3

Edit #3: Updated with a more illustrative code example, one which does not use demo in graphicx. The image above has been replaced with the one using the updated code. I am trying to center the two figures on their respective horizontal axes, like this:

 ______
|      |    ___
|      |   |   |
|      |   |___|
|______|

I have also updated the post tile to clarify the "centerline" issue. I'm bad at explaining things today.

  • I apologize, I should have been clearer, and will update the post to clarify. I am trying to get the figures next to each other, not stacked vertically. Everything I do just results in them changing size, still stacked vertically. – amizener Aug 12 '16 at 15:42
  • We need something we can compile in order to reproduce the problem. Or try floatrow. – cfr Aug 12 '16 at 15:44
  • @cfr I realized that after posting. I'm working on one now. – amizener Aug 12 '16 at 15:47
  • Duly updated with a proper example. My apologies. – amizener Aug 12 '16 at 15:53
2

Is this the output you were after?

Output

enter image description here

Code

\documentclass[12pt]{report}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage{lipsum}

\begin{document}

\lipsum[1]
\begin{figure}[h]
\centering
    \subfloat[Small figure]{%
    \begin{minipage}[c][1in]{1in}
        \centering
        \includegraphics[width=.5in]{example-image-a}
    \end{minipage}}%
    \hspace{\tabcolsep}
    \subfloat[Big figure]{%
        \begin{minipage}[c][1in]{1in}
        \centering
        \includegraphics[width=1in]{example-image-b}
    \end{minipage}}
    \caption{Two more sub-floats.}
\end{figure}
\lipsum[2]
\end{document}
  • @amizener Then I don't undestand what you desire. Please explain better. I thought you wanted the two figures side-by-side. And what do you mean by you last comment here? conseals what? – Runar Aug 12 '16 at 19:17
  • I apologize, I hit enter too early and then my internet immediately went down for a few minutes. I was not intending to be rude. No, but it appears that that is because the 'demo' option in graphics hides the problem. This code does not center the two figures next to each other, which is what I am trying to do. I will update the original post with a more accurate image and code. – amizener Aug 12 '16 at 19:18
  • @amizener looks centred to me. – Runar Aug 12 '16 at 19:19
  • On the page, yes, but not with respect to their respective horizontal axes. – amizener Aug 12 '16 at 19:27
  • @amizener okey, see updated answer – Runar Aug 12 '16 at 19:37

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.