TransWikia.com

Create a simple "scheme" environment and a "List of Schemes"

TeX - LaTeX Asked on January 11, 2021

I have the majority of my thesis written and typeset. Currently, I have a List of Figures and a List of Tables.

However, now my committee tells me that I must also have a List of Schemes. In chemistry, a scheme is an environment that contains (images of) chemical structures and reactions.

Unfortunately, I have already coded my chemical structures as figures. There are a few packages, such as chemstyle and chemscheme, that appear to provide their own scheme constructs. However, I would prefer not to use them since some of those packages set their own defaults for things like chemical formulas. (For example, I see that the chemstyle package defines ie, but I already have my own definition for ie in my thesis.) I am already using the chemformula and chemmacros packages.

Is there any way I can more simply create my own Scheme environment? The only difference I need is that schemes should be captioned as "Scheme" and listed in a List of Schemes. In other words, the only difference between a figure and a scheme is in bookkeeping.

Here is my MWE, with several of the crucial packages that I’m using. One possible complication is that I use the subcaption package to create subfigures. Typically I have only one image per figure/scheme, but I create sub references using phantomsubcaption from the subcaption package. Also, I am using the tocloft package to adjust spacings in the lists of figures and tables, and that could potentially complicate things further.

Finally, it would be nice if I could use the new "scheme" environment with the cleveref package, since I use the cref command from that package a lot to refer to figures, tables, etc.

documentclass[oneside,11pt]{book}

usepackage[semibold,tt=false]{libertine}
usepackage{libertinust1math}
usepackage[font={sf,small},labelsep=quad,labelfont=sc]{caption}
usepackage[subrefformat=parens]{subcaption}
usepackage[
  expansion = false ,
  tracking = smallcaps ,
  letterspace = 40 ,
]{microtype}
usepackage{booktabs}
usepackage{acro}
acsetup{
  barriers/use, barriers/reset,
  use-id-as-short,
}
newcommand{ie}{i.e.}
newcommand{eg}{e.g.}
newcommand{cf}{cf.}
newcommand{avg}[1]{overline{#1}}
usepackage{mdframed}
usepackage[capitalize]{cleveref}
usepackage{chemformula}
setchemformula{charge-hshift=.5pt}
usepackage{chemmacros}
usepackage{graphicx}
usepackage{enumitem}
usepackage{calc}
usepackage{tabto}
usepackage[titles]{tocloft}
setlength{cftfignumwidth}{2.9em}
setlength{cfttabnumwidth}{2.9em}

begin{document}

addcontentsline{toc}{chapter}{listfigurename}
listoffigures

% phantomsection %% Remove if using hyperref
addcontentsline{toc}{chapter}{listtablename}
listoftables

chapter{First chapter}
Text in the first chapter.
Refer to cref{fig:firstfig} using cleveref package.
Refer to cref{tbl:firsttbl}.
Refer to cref{fig:multi}, cref{fig:multi:a}, and cref{fig:multi:b}.
Refer to eventual scheme, cref{scm:eventualscheme}.
Refer to eventual multi-part scheme, cref{scm:eventualmultischeme}.
% Example figure
begin{figure}[!h]
  centering
  includegraphics[width=0.02textwidth]{example-image}
  caption{Caption of figure in first chapter.}label{fig:firstfig}
end{figure}

% Example table 
begin{table}[!h]
  centering
  begin{tabular}{ll}
    toprule
    A & B
    bottomrule
  end{tabular}
  caption{Caption of table in first chapter.}label{tbl:firsttbl}
end{table}

% MULTIPART FIGURE 
begin{figure}[!h]
  centering
  begin{subfigure}{textwidth}
    centering
    includegraphics[width=0.02textwidth]{example-image}
    phantomsubcaptionlabel{fig:multi:a}
  end{subfigure}
  begin{subfigure}{0pt}
    phantomsubcaptionlabel{fig:multi:b}
  end{subfigure}
  caption{Caption of figure referring to parts subref{fig:multi:a} and subref{fig:multi:b} with subref command.}label{fig:multi}
end{figure}

% I NEED TO CHANGE THE FOLLOWING FIGURE TO A SCHEME (SINGLE-PART SCHEME)
begin{figure}[!h]
  centering
  includegraphics[width=0.02textwidth]{example-image-a}
  caption{Caption of eventual scheme.}label{scm:eventualscheme}
end{figure}

% I NEED TO CHANGE THE FOLLOWING FIGURE TO A SCHEME (MULTI-PART SCHEME, BUT ONLY WITH ONE IMAGE)
begin{figure}[!h]
  centering
  begin{subfigure}{textwidth}
    centering
    includegraphics[width=0.02textwidth]{example-image-b}
    phantomsubcaptionlabel{scm:eventualmultischeme:a}
  end{subfigure}
  begin{subfigure}{0pt}
    phantomsubcaptionlabel{scm:eventualmultischeme:a}
  end{subfigure}
  caption{Caption of eventual scheme referring to parts subref{fig:multi:a} and subref{fig:multi:b} with subref command.}label{scm:eventualmultischeme}
end{figure}

chapter{Second chapter}
Text in the second chapter.
Refer to cref{fig:secondfig}.
% Another example figure
begin{figure}[!h]
  centering
  includegraphics[width=0.02textwidth]{example-image}
  caption{Caption of figure in second chapter.}label{fig:secondfig}
end{figure}
end{document}

mwe

3 Answers

Here is how you can combine chemmacros' scheme module with subcaption and cleveref.

  • List of Schemes:

enter image description here

  • References to schemes and subschemes:

enter image description here

  • Captions of schemes:

enter image description here

documentclass[oneside,11pt]{book}

usepackage[semibold,tt=false]{libertine}
usepackage{libertinust1math}
usepackage[font={sf,small},labelsep=quad,labelfont=sc]{caption}
usepackage[subrefformat=parens]{subcaption}
usepackage[
  expansion = false ,
  tracking = smallcaps ,
  letterspace = 40 ,
]{microtype}
usepackage{booktabs}
usepackage{acro}
acsetup{
  barriers/use, barriers/reset,
  use-id-as-short,
}
newcommand{ie}{i.e.}
newcommand{eg}{e.g.}
newcommand{cf}{cf.}
newcommand{avg}[1]{overline{#1}}
usepackage{mdframed}

usepackage{chemformula}
setchemformula{charge-hshift=.5pt}
usepackage{chemmacros}
chemsetup{modules=scheme}

AtEndPreamble{DeclareCaptionSubType*{scheme}}


usepackage{graphicx}
usepackage{enumitem}
usepackage{calc}
usepackage{tabto}
usepackage[titles]{tocloft}
setlength{cftfignumwidth}{2.9em}
setlength{cfttabnumwidth}{2.9em}


usepackage[capitalize]{cleveref}
crefformat{subscheme}{schemename~#2#1#3}


begin{document}

addcontentsline{toc}{chapter}{listfigurename}
listoffigures

% phantomsection %% Remove if using hyperref
addcontentsline{toc}{chapter}{listtablename}
listoftables

addcontentsline{toc}{chapter}{listschemename}
listofschemes

chapter{First chapter}
Text in the first chapter.

Refer to cref{fig:firstfig} using cleveref package.

Refer to cref{tbl:firsttbl}.

Refer to cref{fig:multi}, cref{fig:multi:a}, and cref{fig:multi:b}.

Refer to eventual scheme, cref{scm:eventualscheme}.

Refer to eventual multi-part scheme, cref{scm:eventualmultischeme}, cref{scm:eventualmultischeme:a}, and cref{scm:eventualmultischeme:b}.


begin{figure}[!h]
  caption{Caption of figure in first chapter.}label{fig:firstfig}
end{figure}


begin{table}[!h]
  caption{Caption of table in first chapter.}label{tbl:firsttbl}
end{table}

 
begin{figure}[!h]
  begin{subfigure}{textwidth}
    phantomsubcaptionlabel{fig:multi:a}
  end{subfigure}
  begin{subfigure}{0pt}
    phantomsubcaptionlabel{fig:multi:b}
  end{subfigure}
  caption{Caption of figure referring to parts subref{fig:multi:a} and subref{fig:multi:b} with subref command.}label{fig:multi}
end{figure}


begin{scheme}[!h]
  caption{Caption of scheme.}label{scm:eventualscheme}
end{scheme}

begin{scheme}[!h]

  begin{subfigure}{textwidth}
    phantomsubcaptionlabel{scm:eventualmultischeme:a}
  end{subfigure}
  begin{subfigure}{0pt}
    phantomsubcaptionlabel{scm:eventualmultischeme:b}
  end{subfigure}
  caption{Caption of scheme referring to parts subref{fig:multi:a} and subref{fig:multi:b} with subref command.}label{scm:eventualmultischeme}
end{scheme}

chapter{Second chapter}
Text in the second chapter.
Refer to cref{fig:secondfig}.

begin{figure}[!h]
  caption{Caption of figure in second chapter.}label{fig:secondfig}
end{figure}

begin{scheme}[!h]
  caption{Caption of scheme.}label{scm:eventualscheme2}
end{scheme}

end{document}

Side note: Prior to version 5.11a (2020-11-21) chemmacros listofschemes was incompatible with the book class. (See also: corresponding bug report) If the above solution does not work for you, consider updating to version 5.11a or newer.

To keep this answer short, I have removed the MWE that used version 5.11 and in which I showed how to overcome some formatting inconsistencies between the list of schemes and the list of figures.

Correct answer by leandriis on January 11, 2021

As @leandriis noted in the comments, the chemmacros package apparently already does what you want.

Otherwise, you just have to add the lines

usepackage{newfloat}
DeclareFloatingEnvironment[fileext=los,placement={!ht},name=Scheme]{myscheme}
captionsetup[myscheme]{labelfont=bf}
crefname{myscheme}{scheme}{schemes}

to your preamble and then can use a new float type myscheme similar to figures. The list of schemes is produces with listofmyschemes.

Answered by gernot on January 11, 2021

Load the newfloat package and the scheme module for chemmacros.

You just have to set up a subscheme environment for subcaption, which has to be done at begin document.

I loaded tocbibind for adding listoffigures and listoftables to the table of contents. Your manual method is incorrect: you should at least have cleardoublepage before addcontentsline.

documentclass[oneside,11pt]{book}

usepackage[semibold,tt=false]{libertine}
usepackage{libertinust1math}
usepackage[font={sf,small},labelsep=quad,labelfont=sc]{caption}
usepackage[subrefformat=parens]{subcaption}
usepackage{newfloat}
usepackage[
  expansion = false ,
  tracking = smallcaps ,
  letterspace = 40 ,
]{microtype}
usepackage{booktabs}
usepackage{acro}
usepackage{mdframed}
usepackage{chemformula}
usepackage{chemmacros}
usepackage{graphicx}
usepackage{enumitem}
usepackage{calc}
usepackage{tabto}
usepackage[titles]{tocloft}
usepackage[nottoc]{tocbibind}
usepackage[capitalize]{cleveref} % should be last

% acro options
acsetup{
  barriers/use, barriers/reset,
  use-id-as-short,
}
% chemmacros options
usechemmodule{scheme}
% chemformula options
setchemformula{charge-hshift=.5pt}
% tocloft options
setlength{cftfignumwidth}{2.9em}
setlength{cfttabnumwidth}{2.9em}
% caption options
AtBeginDocument{DeclareCaptionSubType*[alph]{scheme}}

% personal commands
newcommand{ie}{i.e.}
newcommand{eg}{e.g.}
newcommand{cf}{cf.}
newcommand{avg}[1]{overline{#1}}

begin{document}

tableofcontents
listoffigures
listoftables
listofschemes

chapter{First chapter}

Text in the first chapter.
Refer to cref{fig:firstfig} using cleveref package.
Refer to cref{tbl:firsttbl}.
Refer to cref{fig:multi}, cref{fig:multi:a}, and cref{fig:multi:b}.
Refer to eventual scheme, cref{scm:eventualscheme}.
Refer to eventual multi-part scheme, cref{scm:eventualmultischeme}.

% Example figure
begin{figure}[!h]
  centering
  includegraphics[width=0.02textwidth]{example-image}
  caption{Caption of figure in first chapter.}label{fig:firstfig}
end{figure}

% Example table 
begin{table}[!h]
  centering
  begin{tabular}{ll}
    toprule
    A & B
    bottomrule
  end{tabular}
  caption{Caption of table in first chapter.}label{tbl:firsttbl}
end{table}

% MULTIPART FIGURE 
begin{figure}[!h]
  centering
  begin{subfigure}{0.45textwidth}
    centering
    includegraphics[width=0.02textwidth]{example-image}
    phantomsubcaptionlabel{fig:multi:a}
  end{subfigure}
  begin{subfigure}{0.45textwidth}
    includegraphics[width=0.02textwidth]{example-image}
    phantomsubcaptionlabel{fig:multi:b}
  end{subfigure}
  caption{Caption of figure referring to parts subref{fig:multi:a} and subref{fig:multi:b} with subref command.}label{fig:multi}
end{figure}

begin{scheme}[!h]
  centering
  includegraphics[width=0.02textwidth]{example-image-a}
  caption{Caption of eventual scheme.}label{scm:eventualscheme}
end{scheme}

begin{scheme}[!h]
  centering
  begin{subscheme}{0.45textwidth}
    centering
    includegraphics[width=0.02textwidth]{example-image-a}
    phantomsubcaptionlabel{scm:eventualmultischeme:a}
  end{subscheme}
  begin{subscheme}{0.45textwidth}
    includegraphics[width=0.02textwidth]{example-image-b}
    phantomsubcaptionlabel{scm:eventualmultischeme:b}
  end{subscheme}
  caption{Caption of eventual scheme referring to parts subref{fig:multi:a} and subref{fig:multi:b} with subref command.}label{scm:eventualmultischeme}
end{scheme}

chapter{Second chapter}

Text in the second chapter.
Refer to cref{fig:secondfig}.

% Another example figure
begin{figure}[!h]
  centering
  includegraphics[width=0.02textwidth]{example-image}
  caption{Caption of figure in second chapter.}label{fig:secondfig}
end{figure}

end{document}

Answered by egreg on January 11, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP