2

The chemmacros package offers the scheme module which creates a figure-like environment Scheme and also creates a List of Schemes which can be produced by simply issuing \listofschemes. Fantastic!

Now, I would like to have subschemes, just like the subfigure environment does for figures. How would I achieve that? And also, I would like to have the subscheme captions shown in the List of Schemes (i.e., its depth should be adjusted to show not just main captions, but also first-level subcaptions). Without affecting the other "List of ...", of course.

2

To achieve subschemes, we could make use of the \DeclareCaptionSubType command of the subcaption package (see section 5 in its manual).

We should thus define a new float scheme using newfloat's \DeclareFloatingEnvironment, and then we can \DeclareCaptionSubType{scheme} which will give us the subscheme environment, just like we wanted.

\usepackage{chemmacros}
\usechemmodule{scheme}
\usepackage{newfloat}
\DeclareFloatingEnvironment[
   fileext=los,
   listname={List of Schemes},
   name=Scheme,
   placement=tbp,
   within=none % don't reset numbering
]{scheme}
\DeclareCaptionSubType{scheme}

This should allow you to do something like this in your document:

\begin{scheme}[tb]
\centering
\begin{subscheme}{0.5\textwidth}
   % your chemical structure
   \caption{Your subcaption.}
   \label{sch:subscheme-1}
\end{subscheme}%
\begin{subscheme}{0.5\textwidth}
   \centering
   % another chemical structure
   \caption{Your other subcaption.}
   \label{sch:subscheme-2}
\end{subscheme}
\caption{Structures.}
\label{sch:structures}
\end{scheme}

Cool! I should also note that the chemmacros manual was very helpful, stating among other things (paraphrased):

The scheme module defines a floating environment \begin{scheme} only if no environment scheme exists at the end of the preamble. (Section 7.9)

So we can define our own scheme environment (as above) without otherwise interfering with the chemmacros scheme module. Now that we have subschemes, the List of Schemes probably looks a little boring (it does to me), because the captions of the actual chemical structures are in the subcaptions.

This was a little trickier to achieve, but in short, you have to set list=true in the subcaption package arguments, as well as \setcounter{losdepth}{2} (assuming you set fileext=los in \DeclareFloatingEnvironment) somewhere before \listofschemes.

Here's a complete MWE that shows a document with a subscheme, a subfigure, List of Schemes exposing subcaption, and a List of figures.

\documentclass[a4paper]{article}

\usepackage[english]{babel}
% my original document happened to use lualatex
\usepackage[utf8]{luainputenc}
\usepackage{fontspec}

\usepackage{graphicx}
\usepackage[%
   % the following two lines are not required
   margin=0pt,font+=small,labelformat=parens,%
   labelsep=space,justification=centering,skip=6pt,%
   % list=true must be used *in combination with* \setcounter{\Zdepth}{2}
   list=true%
]{subcaption}

% not loading tocloft gives "no counter lofdepth defined"
% titles makes tocloft surrender control of the TOC title font, spacing, etc.to the document's default behaviour (otherwise tocloft uses its own settings)
\usepackage[titles]{tocloft}

\usepackage{chemmacros}
\usechemmodule{scheme}
\usepackage{newfloat}
\DeclareFloatingEnvironment[
   fileext=los,
   listname={List of Schemes},
   name=Scheme,
   placement=tbp,
   within=none % other options are within={section,chapter}
]{scheme}
\DeclareCaptionSubType{scheme}
\usepackage{chemfig}
% print atoms in sans-serif instead of serif, looks better
\renewcommand*\printatom[1]{\ensuremath{\mathsf{#1}}}

\usepackage{hyperref}

\begin{document}

\setcounter{losdepth}{2}
\setcounter{lofdepth}{1} % not strictly necessary, depth=1 is default

\tableofcontents
\listofschemes
\listoffigures

\section{Chemistry}

\subsection{Dyes}

\begin{scheme}[tb]
\centering
\begin{subscheme}{0.5\textwidth}
   \centering
   % define invisible bond (for use between the charged species)
   \definesubmol\nobond{-[,1.2,,,draw=none]}
   \footnotesize\chemfig[atom sep=2.0em]{[7]H_3C-N(-[6]CH_3)-[:30]*6(=-(*6(=\chembelow{S}{\scriptscriptstyle\oplus}(!\nobond\chemabove{Cl}{\scriptscriptstyle\ominus})-(*6(-=(-N(-[1]CH_3)-[6]CH_3)-=-=))--N=-))--=-)}
   \caption[Methylene blue]{Methylene blue.}
   \label{sch:MB-structure}
\end{subscheme}\,%
\begin{subscheme}{0.5\textwidth}
   \centering\footnotesize
   \chemfig[atom sep=2.0em]{([:-30]*6((-=^[::+60]-[::+60]=^[::+60]-[::+60])=-(-OH)=(-N=[::60]N-*6(=(-OH)-=(-S(=[::+90]O)(=[::-90]O)(-O^\ominus\,Na^\oplus))-*6(-=(-NO_2)-=--)=-))-=-))}
   \caption[Eriochrome black T]{Eriochrome black T.}
   \label{sch:EBT-structure}
\end{subscheme}
\caption[MB and EBT dyes]{MB and EBT.}
\label{sch:MB-EBT-structures}
\end{scheme}

\begin{figure}[tbh]
\centering
\begin{subfigure}[b]{0.5\linewidth}
\centering
\includegraphics[width=0.97\textwidth]{example-image-a}
\caption{}
\label{fig:031-005}
\end{subfigure}%
\begin{subfigure}[b]{0.5\linewidth}
\centering
\includegraphics[width=0.97\textwidth]{example-image-b}
\caption{}
\label{fig:031-014}
\end{subfigure}
\caption[Photographs of cell]{Nice photographs.}
\label{fig:031}
\end{figure}

\end{document}

Compiled PDF of code chunk above

Environment: TeXLive 2020, chemmacros v5.11, newfloat v1.1l, caption v1.3.

In figuring out this behaviour, I had a lot of help from the chemmacros, subcaption and newfloat package manuals, and also from other questions (not always closely related):

New figure environment
Defining a new type of floating environment
How to edit scheme numbering in a list of schemes?
How to change the display of subfigures in List of Figures?
\listoffigures does not work with \subfig
Modify \listofschemes output to match memoir class
\setcounter{tocdepth}

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.