3

SOLVED - see edit 2:

I am trying to place two figures side by side in a single-column document. I have attempted several suggestions I found online (the subfig package, the minipage environment, just putting two \includegraphics next to each other with no blank lines in between...). However, all of them seem to fail, and I get the two figures just one on top of the other. My latest attempt is just copied and pasted from an answer to a similar question on this forum, and still does not work:

\documentclass[]{aastex631}
\graphicspath{{./}}
\begin{document}
Some text here
\begin{figure}[ht]
\centering
\begin{minipage}[b]{.5\linewidth}
\centering
\includegraphics[width=\linewidth]{free_forward.pdf}
\end{minipage}\hfill
\begin{minipage}[b]{.5\linewidth}
\centering
\includegraphics[width=\linewidth]{ace_forward.pdf}
\end{minipage}
\end{figure}
\end{document}

What is it I am doing wrong? I am using Overleaf.

EDIT: Added the needed lines to make the code compilable.

EDIT 2: Apparently the problem is in the documentclass, which for some reason does not support the "usual" ways of placing subfigures side by side. Instead, this worked:

\documentclass[]{aastex631}
\graphicspath{{./}{figures/}}
\begin{document}
Some text here

\begin{figure}[ht]
\centering
\gridline{\fig{free_forward.pdf}{0.5\textwidth}{(a)}
          \fig{ace_forward.pdf}{0.5\textwidth}{(b)}
          }
\end{figure}
\end{document}

Apologies for asking an unnecessary question, and for the lack of clarity in it (it's my first question here), and thank you to those who commented!

8
  • 1
    Welcome to TeX SX! Could you please post a compilable code, starting with \documentclass and ending with \end{document}?
    – Bernard
    Sep 5, 2021 at 18:14
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Sep 5, 2021 at 18:15
  • @Bernard, thank you for the suggestion, just edited my post accordingly
    – lpc
    Sep 5, 2021 at 18:20
  • It seems the problem is my documentclass, as it works if I just use "article" instead. So I guess my question now is, where in the cls file can I look for the lines that are generating the issue?
    – lpc
    Sep 5, 2021 at 18:28
  • Where do you expect us to find the xxx-forward.pdf files? Also, where is the aastex631.cls ? I can't compile your document so can't directly help. However, if you narrow the figures perhaps all will be well. Sep 5, 2021 at 18:31

2 Answers 2

8

This is a bug in the aastex class.

You have two minpages each .5\linewidth wide so they should fit on a line, however if you use \showoutput you can see that there is an inter-word space between them so they do not fit and you get a linebreak at the space.

this is due to a missing % in the class file so an end of line is causing an extra space to be added to the ends of environments.

Line 577 of version 6.3.1.f as distributed with texlive 2021 should have a % where marked

\def\end#1{%
% execute code before \end{environment}
\IfUnDef{BeforeEnd#1}\else\csname BeforeEnd#1\endcsname\fi%
% close this environment
\EndEnvironment{#1}%%%%%%%!!!!
% and execute code after \begin{environment}
\IfUnDef{AfterEnd#1}\else\csname AfterEnd#1\endcsname\fi%
}

The % after the \fi conversely are doing nothing.

The same problem occurs with the line

\SaveBegEnd{#1}

6 lines earlier

3

You do not give TeX enough space on the current line to put both your figures side by side. Just change 0.5\linewidth for 0.49\linewidth.

P.S. Since the problem is caused by the bug in the class, as shown by David, a simpler workaround is the change of \hfill to \unskip\hfill (\unskip kills the bogus space)

6
  • I wonder if it would work in \linewidth were evenly divisible by 2. (1pt=64K sp) Sep 6, 2021 at 16:24
  • @JohnKormylo no it;s a space (found it now:-) Sep 6, 2021 at 18:48
  • There should be enough space (even though they would be touching) but a bug in the class puts a word-space after each minipage. Sep 6, 2021 at 19:12
  • @DavidCarlisle, you are right, of course. However, fixing the bug in the class from the user point of view is not an advisable idea: it may trigger unintended consequences elsewhere. It is better to work around the bug. Even better is to work around the bug and report the bug to the maintainer :)
    – Boris
    Sep 6, 2021 at 20:20
  • @Boris I reported the bug (github link at the top) actually when I initially made the comment here I thought it was the usual user error of adding a space in the document \end{minipage}<newline>\begin{minipage} but noticed later the OP had \hfill there so no % after \end{minipage} needed so I deleted the initial comment and went searching in the class:-) Sep 6, 2021 at 20:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .