3

I'm using the chemfig package for some structural diagrams I'm preparing for a lab report, and I need to align five structural diagrams (with their own name captions) in a 2x3 column-and-row format. To this end, I chose to use chemfig within multiple subfigure environments, all within a figure.

I used this question as well as this one to begin to understand how to do the horizontal and vertical alignment within a figure environment, but I'm running into the issue where the figure environment "forgets" the row alignment after the first row.

The MWE is as follows:

\documentclass{article}

\usepackage{baskervald}
\usepackage{graphicx}
\usepackage{chemfig}
\usepackage{subcaption}

\begin{document}

\begin{figure*}[h]
    \centering
    \begin{subfigure}[b]{0.5\textwidth}
        \centering
        \scalebox{0.67}{
            \chemfig{HO-[:30]*6(-=-(-\chemabove{N}{H}-[::-60](=[::-60]O)-)=-=)}
        }
        \caption{Acetaminophen}
    \end{subfigure}%
    ~
    \begin{subfigure}[b]{0.5\textwidth}
        \centering
        \scalebox{0.67}{
            \chemfig{*6(-=-(-O-[::-60](=[::-60]O)-[::+60])=(-(=[::+60])-[::-60]OH)-=)}
        }
        \caption{Aspirin}
    \end{subfigure}%
    \\
    \begin{subfigure}[b]{0.5\textwidth}
        \centering
        \scalebox{0.67}{
            \chemfig{*6((=O)-N(-CH_3)-*5(-N=-N(-CH_3)-=)--(=O)-N(-H_3C)-)}
        }
        \caption{Caffeine}
    \end{subfigure}
    ~   
    \begin{subfigure}[b]{0.5\textwidth}
        \centering
        \scalebox{0.67}{
            \chemfig{H_3C-[::30](-[:90]CH_3)-[::-60]-[::60]*6(-=-(-(-[::60]CH_3)-[::-60](=[::-60]O)-OH)=-=)}
        }
        \caption{Ibuprofen}
    \end{subfigure}%
    \\
    \begin{subfigure}[b]{0.5\textwidth}
        \centering
        \scalebox{0.67}{
            \chemfig{*6(-=-(-OH)=(-(=[::60]O)-[::-60]NH_2)-=)}
        }
        \caption{Salicylamide}
    \end{subfigure}%
    \caption{Chemical structures of the analgesics being analyzed.}
\end{figure*}

\end{document}

This results in the following output:

MWE output

Here, I need figures (a) and (b) to be aligned horizontally, as they are, with (c) and (d) aligned similarly beneath them, and (e) centered between the two (as it currently is) beneath that.

I've tried two routes to remedy this, neither of which have had any success in remedying the issue:

  • Blocking each row in braces, then using \\ to separate rows
  • Placing each row within its own subfigure environment.
2

How about using a tabular for that?

\documentclass{article}
\usepackage{baskervald}
\usepackage{chemfig}
\usepackage{subcaption}

\begin{document}

\begin{figure*}[h]
\centering
  \begin{tabular}{@{}c@{}@{}c@{}}
    \begin{subfigure}[b]{0.45\textwidth}
        \centering
        \scalebox{0.67}{
            \chemfig{HO-[:30]*6(-=-(-\chemabove{N}{H}-[::-60](=[::-60]O)-)=-=)}
        }
        \caption{Acetaminophen}
    \end{subfigure}
    &
    \begin{subfigure}[b]{0.45\textwidth}
        \centering
        \scalebox{0.67}{
            \chemfig{*6(-=-(-O-[::-60](=[::-60]O)-[::+60])=(-(=[::+60])-[::-60]OH)-=)}
        }
        \caption{Aspirin}
    \end{subfigure}%
    \\
    \begin{subfigure}[b]{0.45\textwidth}
        \centering
        \scalebox{0.67}{
            \chemfig{*6((=O)-N(-CH_3)-*5(-N=-N(-CH_3)-=)--(=O)-N(-H_3C)-)}
        }
        \caption{Caffeine}
    \end{subfigure}
    &   
    \begin{subfigure}[b]{0.45\textwidth}
        \centering
        \scalebox{0.67}{
            \chemfig{H_3C-[::30](-[:90]CH_3)-[::-60]-[::60]*6(-=-(-(-[::60]CH_3)-[::-60](=[::-60]O)-OH)=-=)}
        }
        \caption{Ibuprofen}
    \end{subfigure}%
    \\
    \multicolumn{2}{c}{\begin{subfigure}[b]{0.45\textwidth}
        \centering
        \scalebox{0.67}{
            \chemfig{*6(-=-(-OH)=(-(=[::60]O)-[::-60]NH_2)-=)}
        }
        \caption{Salicylamide}
    \end{subfigure}%
    }
  \end{tabular} 
\caption{Chemical structures of the analgesics being analyzed.}
\end{figure*}

\end{document}

enter image description here

  • This worked wonderfully! I had considered a tabular approach, but I think I got too engrained in the subfigure way of doing things and didn't think of this. – ecfedele Jan 18 at 6:13

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.