problem with chemical structure numbering
The best of the chemical numbering packages is chemnum
, which is newer than chemcompounds
(my previous pick-of-the-packages), bpchem
and compoundcntr
(which is very awkward to use). With chemnum
, each compound is labelled using the \cmpd
macro. This creates numerical references, but allows us to subdivide using .
to generate letters. I would combined with mhchem
for the formula parts:
\documentclass{article}
\usepackage{booktabs,chemnum}
\usepackage[version=3]{mhchem}
\begin{document}
\begin{table}
\centering
\caption{Benzene derivatives}
\label{tbl:compounds}
\begin{tabular}{lll}
\toprule
Compounds & R$^1$ & R$^2$ \\
\midrule
Toluene (\cmpd{Ph.Me}) & \ce{CH3} & \ce{H} \\
Ethyl benzene (\cmpd{Ph.Et}) & \ce{C2H5} & \ce{H} \\
Chlorobenzene (\cmpd{Ph.Cl}) & \ce{Cl} & \ce{H} \\
\emph{o}-Chlorotoluene (\cmpd{o-Tol.Cl}) & \ce{CH3} & \ce{Cl} \\
\bottomrule
\end{tabular}
\end{table}
In Table~\ref{tbl:compounds}, compounds~\cmpd{Ph.Me} and~\cmpd{Ph.Et}
are useful, whereas compounds~\cmpd{Ph.Cl} and~\cmpd{o-Tol.Cl}
are harmful.
\end{document}
Notice that I've gone with the standard approach that chemical numbers are bold, which can be set using a package option.
Here is one approach to a compound numbering scheme (taken from a duplicate post on LaTeX User's Group):
\documentclass{article}
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{xparse}% http://ctan.org/pkg/xparse
\newcounter{compoundcntr} \newcounter{subcompoundcntr}[compoundcntr]
\renewcommand{\thesubcompoundcntr}{\thecompoundcntr\alph{subcompoundcntr}}
\NewDocumentCommand{\compound}{s o m}{%
\IfBooleanTF{#1}
{% \compound*[<label>]{<name>}
\IfNoValueTF{#2}
{#3}% \compound{<name>}
{\stepcounter{compoundcntr}\refstepcounter{subcompoundcntr}#3, \thesubcompoundcntr\label{#2}}% \compound[<label>]{<name>}
}
{% \compound[<label>]{<name>}
\ifnum\value{compoundcntr}=0\stepcounter{compoundcntr}\fi% Can use \compound[<label>]{<name>} to start first compound
\IfNoValueTF{#2}
{#3}% \compound*{<name>}
{\refstepcounter{subcompoundcntr}#3, \thesubcompoundcntr\label{#2}}% \compound*[<label>]{<name>}
}
}
\begin{document}
\begin{table}[t]
\centering
\begin{tabular}{lll}
\toprule
Compound & R$^1$ & R$^2$ \\
\midrule
\compound*[toluene]{Toluene} & CH3 & H \\
\compound[ethylbenzene]{Ethyl benzene} & C2H5 & H \\
\compound[chlorobenzene]{Chlorobenzene} & Cl & H \\
\compound*[o-chlorotoluene]{o-chlorotoluene} & CH3 & Cl \\
\bottomrule
\end{tabular}
\caption{Some compounds} \label{tbl:compounds}
\end{table}
In Table~\ref{tbl:compounds}, compound~\ref{toluene} and~\ref{ethylbenzene} are useful, whereas compound~\ref{chlorobenzene} and~\ref{o-chlorotoluene} are harmful.
\end{document}
The main command is \compound*[<label>]{<name>}
. If you specify the starred version (\compound*[<label>]{<name>}
), a new "main compound" is created (incrementing the first number). The unstarred version (\compound[<label>]{<name>}
) does not increment the "main compound" counter, but increments the "sub compound" counter. If you specify a <label>
(yes, this is optional), it prints the compound number. Otherwise, it doesn't. Whatever you specify in <name>
(a mandatory argument) is printed as the name.
In summary, the available commands are
\compound*[<label>]{<name>}
= new "main compound" with compound number\compound*{<name>}
= new "main compound" without compound number\compound[<label>]{<name>}
= new "sub compound" with compound number\compound{<name>}
= new "sub compound" without compound number
Effectively \compound*{<name>}
and \compound{<name>}
are the same. You reference the compounds by using \ref{<label>}
, as usual, as seen in the example. Modifications to label representation and command usage is also possible. Care has been taken to allow starting the first compound with \compound
instead of \compound*
.
If your interested in a single compound numbering scheme, the construction of \compound
is much simpler. Here's a view on one such construction:
\documentclass{article}
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{xparse}% http://ctan.org/pkg/xparse
\newcounter{compoundcntr}
\renewcommand{\thecompoundcntr}{\arabic{compoundcntr}}
\NewDocumentCommand{\compound}{s o m}{%
\IfBooleanTF{#1}
{% \compound*[<label>]{<name>}
#3%
}
{% \compound[<label>]{<name>}
\refstepcounter{compoundcntr}% Increment compound counter for correct referencing
#3, \thecompoundcntr
\IfNoValueTF{#2}
{}% \compound{<name>}
{\label{#2}}% \compound[<label>]{<name>}
}
}
\begin{document}
\begin{table}[t]
\centering
\begin{tabular}{lll}
\toprule
Compound & R$^1$ & R$^2$ \\
\midrule
\compound[toluene]{Toluene} & CH3 & H \\
\compound[ethylbenzene]{Ethyl benzene} & C2H5 & H \\
\compound[chlorobenzene]{Chlorobenzene} & Cl & H \\
\compound[o-chlorotoluene]{o-chlorotoluene} & CH3 & Cl \\
\bottomrule
\end{tabular}
\caption{Some compounds} \label{tbl:compounds}
\end{table}
In Table~\ref{tbl:compounds}, compound~\ref{toluene} and~\ref{ethylbenzene} are useful, whereas compound~\ref{chlorobenzene} and~\ref{o-chlorotoluene} are harmful.
\end{document}
Using \compound*[<label>]{<name>}
doesn't make much sense, since <label>
is disregarded.