# Align subfigures vertically

It is easy using subfigure environment to place some figures side by side. How could we do it one on the top of the other one without messing with the alignment? Using linebreak (\\) instead of \; for instance seems not to derive the desired result.

Example

\documentclass[a4paper,11pt]{article}
\usepackage{fullpage}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage[hypcap=false]{caption}
\usepackage{subcaption}
\usepackage{chemfig}

% Title Page
\title{a}

\begin{document}
\maketitle

\begin{figure}
\begin{subfigure}[b]{\textwidth}
\centering
\chemfig{C(=[:0]O)(=[:180]O)}\;
\chemfig{H-[::37.775,2]O-[::-75.55,2]H}\;
\caption{Chemical Database}
\label{fig:database}
\end{subfigure}\newline
%~ %add desired spacing between images, e. g. ~, \quad, \qquad etc.
%(or a blank line to force the subfigure onto a new line)
\begin{subfigure}[b]{0.3\textwidth}
\centering
\chemfig{C(-[:90]H)(-[:270]H)(=[:0]C(=[:0]C(-[:90]H)(-[:270]H)))}
\caption{Query formula}
\end{subfigure}
\caption{Query}\label{fig:query}
\end{figure}

\end{document}


The desired result would be to have the first pair of formulas above the other while both figures are aligned to the center.

-

## 1 Answer

You say that the MWE doesn't give the desired formatting but you do not say what layout you want.

You have one full width figure and one 30%-width figure. It might have been simpler to have them both full width but assuming that you want them that size, but want the smaller one centred, then perhaps:

\begin{figure}\centering
\begin{subfigure}[b]{\textwidth}
\centering
\chemfig{C(=[:0]O)(=[:180]O)}\;
\chemfig{H-[::37.775,2]O-[::-75.55,2]H}\;
\caption{Chemical Database}
\label{fig:database}
\end{subfigure}\\[10em]
%~ %add desired spacing between images, e. g. ~, \quad, \qquad etc.
%(or a blank line to force the subfigure onto a new line)
\begin{subfigure}[b]{0.3\textwidth}
\centering
\chemfig{C(-[:90]H)(-[:270]H)(=[:0]C(=[:0]C(-[:90]H)(-[:270]H)))}
\caption{Query formula}
\end{subfigure}
\caption{Query}\label{fig:query}
\end{figure}

-
Thanks. It was a bad question. Your answer helped find the issue in my question and solve my problem. Centering at the beginning seems to help. Removing the the weird 30%-width and converting it to 100% also resolves the issue. Thanks a lot! –  Dimitris Leventeas May 17 '12 at 18:00