3

Having trouble getting captions in my subfigures centered. I've played around with the caption and subcaption packages a little bit and it seems like the subfigure captions are being treated like normal captions. For instance, when I add \usepackage[font=bf]{caption} to my preamble, all of the subcaptions are bolded, not just the main caption. If I add any options to \usepackage{subcaption}, they don't have any effect on anything. Here is what I'm doing right now:

\documentclass[12pt]{article}

\usepackage{mathptmx}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[margin=0.9in]{geometry}
\usepackage{gensymb}
\usepackage{subcaption}
\usepackage{adjustbox}

\begin{document}

Petroporphyrins, as shown in Figure \ref{fig:porphyrinexamples}, are constituted of four cyclically-bonded pyrroles with various aliphatic, cylcic, and aromatic moieties. The nitrogen of each pyrrole is oriented to the center of the porphyrin, which is where the nickel or vanadium, in the form of vanadium (IV) oxide, coordinates.

\begin{figure}
\begin{adjustbox}{varwidth=\textwidth,fbox,center}
  \centering
\begin{subfigure}{.45\textwidth}
  \centering
  \includegraphics[width=.5\linewidth]{Porphyrin.png}
  \caption{Unsubstituted Demetalated Porphyrin}
  \label{fig:porphyrin}
\end{subfigure}
\begin{subfigure}{.45\textwidth}
  \centering
  \includegraphics[width=.5\linewidth]{VPorphyrin.png}
  \caption{Unsubstituted Vanadyl Porphyrin}
  \label{fig:vporphyrin}
\end{subfigure}
\\
\vspace{18pt}
\begin{subfigure}{.45\textwidth}
  \centering
  \includegraphics[width=.5\linewidth]{VDPEP.png}
  \caption{Vanadyl DPEP}
  \label{fig:vdpep}
\end{subfigure}
\begin{subfigure}{.45\textwidth}
  \centering
  \includegraphics[width=.5\linewidth]{VEtio.png}
  \caption{Vanadyl Etioporphyrin}
  \label{fig:vetio}
\end{subfigure}
\\
\vspace{18pt}
\begin{subfigure}{.45\textwidth}
  \centering
  \includegraphics[width=.5\linewidth]{VBenzoEtio.png}
  \caption{Vanadyl Benzoetioporphyrin}
  \label{fig:vbenzoetio}
\end{subfigure}
\begin{subfigure}{.45\textwidth}
  \centering
  \includegraphics[width=.5\linewidth]{VTHBEtio.png}
  \caption{Vanadyl Tetrahydrobenzoetioporphyrin}
  \label{fig:vthbetio}
\end{subfigure}
\end{adjustbox}
\caption{Several Basic Petroporphyrin Configurations}
\label{fig:porphyrinexamples}
\end{figure}

\end{document}
  • The problem with the not centered subcaptions comes from the adjustbox. – Gonzalo Medina Jul 17 '14 at 14:54
5

enter image description here

The problem comes from the adjustbox; if you replace it with a minipage surrounded with an \fbox, the subcaptions are centered again:

\documentclass[12pt]{article}
\usepackage{mathptmx}
\usepackage{amsmath}
\usepackage[demo]{graphicx}
\usepackage[margin=0.9in]{geometry}
\usepackage{gensymb}
\usepackage{subcaption}
\usepackage{adjustbox}

\captionsetup[figure]{font=bf}
\captionsetup[subfigure]{font=rm}

\begin{document}

Petroporphyrins, as shown in Figure \ref{fig:porphyrinexamples}, are constituted of four cyclically-bonded pyrroles with various aliphatic, cylcic, and aromatic moieties. The nitrogen of each pyrrole is oriented to the center of the porphyrin, which is where the nickel or vanadium, in the form of vanadium (IV) oxide, coordinates.

\begin{figure}
\fbox{\begin{minipage}{\dimexpr\textwidth-2\fboxsep-2\fboxrule\relax}
\centering
\begin{subfigure}{.45\textwidth}
  \centering
  \includegraphics[width=.5\linewidth]{Porphyrin.png}
  \caption{Unsubstituted Demetalated Porphyrin}
  \label{fig:porphyrin}
\end{subfigure}%
\begin{subfigure}{.45\textwidth}
  \centering
  \includegraphics[width=.5\linewidth]{VPorphyrin.png}
  \caption{Unsubstituted Vanadyl Porphyrin}
  \label{fig:vporphyrin}
\end{subfigure}
\\
\vspace{18pt}
\begin{subfigure}{.45\textwidth}
  \centering
  \includegraphics[width=.5\linewidth]{VDPEP.png}
  \caption{Vanadyl DPEP}
  \label{fig:vdpep}
\end{subfigure}%
\begin{subfigure}{.45\textwidth}
  \centering
  \includegraphics[width=.5\linewidth]{VEtio.png}
  \caption{Vanadyl Etioporphyrin}
  \label{fig:vetio}
\end{subfigure}
\\
\vspace{18pt}
\begin{subfigure}{.45\textwidth}
  \centering
  \includegraphics[width=.5\linewidth]{VBenzoEtio.png}
  \caption{Vanadyl Benzoetioporphyrin}
  \label{fig:vbenzoetio}
\end{subfigure}%
\begin{subfigure}{.45\textwidth}
  \centering
  \includegraphics[width=.5\linewidth]{VTHBEtio.png}
  \caption{Vanadyl Tetrahydrobenzoetioporphyrin}
  \label{fig:vthbetio}
\end{subfigure}
\end{minipage}}
\caption{Several Basic Petroporphyrin Configurations}
\label{fig:porphyrinexamples}
\end{figure}

\end{document}

Regarding the second question, you can use the optional argument for \captionsetup to have different formatting foe figures and subfigures; in my example code I used

\captionsetup[figure]{font=bf}
\captionsetup[subfigure]{font=rm}

for illustration purposes.

The demo option for graphicx simply replaces actual figures with black rectangles; do not use that option in your actual document.

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.