使用 chemformula 包中的 cleveref 进行交叉引用反应

使用 chemformula 包中的 cleveref 进行交叉引用反应

我想交叉引用化学反应并写下我正在使用的化学反应

\usepackage{chemformula}

引用我正在使用

\usepackage{cleveref}

我想使用 交叉引用反应\cref{label}。我该怎么做?

平均能量损失

\documentclass[a4paper,oneside,12pt,openright]{book}
\usepackage{amsmath,amssymb} %for typing the mathematical equations and symbols
\usepackage[utf8]{inputenc} % input encoding
\usepackage{csquotes} %for using quotes command:\hyphenquote
\usepackage[T1]{fontenc} % font encoding
\usepackage{etoolbox,ragged2e,siunitx,mathtools}
\usepackage{indentfirst} % paragraphs
\usepackage[paper=a4paper,left=22mm, top=22mm, right=15mm, bottom=22mm]{geometry} %paper geometry  total={170mm, 257mm}
\usepackage{graphicx} %for figure
\usepackage{array} % for matrices
\usepackage{pgfplots} % for plots
\usepackage{caption} %names of figures and tables
\captionsetup[figure]{list=yes}
\captionsetup[table]{format=plain,labelformat=simple,labelsep=period}%
\usepackage[list=true,listformat=simple]{subcaption}
\pgfplotsset{width=10cm, compat=1.9}
\usepackage{color} %colors in document
\usepackage{xcolor} 
\usepackage[english]{babel}% base language and spacing
\frenchspacing
\renewcommand{\baselinestretch}{1.2}
\usepackage{mathrsfs}
\usepackage{chemformula}
\usepackage{cleveref}
\begin{document}
I want to cross refer following reaction

\ch{2H2+ O2 -> 2H2O}

As per above \cref{label} water is formed.

\end{document}

答案1

我定义了一个reaction 环境,它有自己的计数器:

\documentclass[a4paper,oneside,12pt,openright]{book}
\usepackage{amsmath,amssymb} %for typing the mathematical equations and symbols
\usepackage[utf8]{inputenc} % input encoding
\usepackage{csquotes} %for using quotes command:\hyphenquote
\usepackage[T1]{fontenc} % font encoding
\usepackage{etoolbox, ragged2e, siunitx, mathtools}
\usepackage{indentfirst} % paragraphs
\usepackage[paper=a4paper,left=22mm, top=22mm, right=15mm, bottom=22mm]{geometry} %paper geometry total={170mm, 257mm}
\usepackage{graphicx} %for figure
\usepackage{array} % for matrices
\usepackage{pgfplots} % for plots
\usepackage{caption} %names of figures and tables
\captionsetup[figure]{list=yes}
\captionsetup[table]{format=plain,labelformat=simple,labelsep=period}%
\usepackage[list=true,listformat=simple]{subcaption}
\pgfplotsset{width=10cm, compat=1.9}
\usepackage{xcolor}
\usepackage[english]{babel}% base language and spacing
\frenchspacing
\renewcommand{\baselinestretch}{1.2}
\usepackage{mathrsfs}
\usepackage{chemformula}
\usepackage{cleveref}
\newcounter{reaction}
\setcounter{reaction}{0}
\newenvironment{reaction}[1][]{\refstepcounter{reaction}\label{#1}\equation}{\tag{\arabic{reaction}}\endequation}
\crefname{reaction}{reaction}{reactions}
\Crefname{reaction}{Reaction}{Reactions}

\begin{document}

I want to cross refer following reaction
\begin{reaction}[label] \ch{2 H2 + O2 -> 2 H2O} \end{reaction}

As per above \cref{label}, water is formed.

\end{document}

在此处输入图片描述

答案2

我会使用chemmacros它的reactions模块。它chemformula默认使用并可cleveref开箱即用:

\documentclass{article}

\usepackage{chemmacros}
\chemsetup{
  modules = {reactions} ,
  formula = chemformula % not necessary: this is the default 
}
\usepackage{cleveref}

\begin{document}

\begin{reactions}
  2 H2 + O2 &-> 2 H2O "\label{rxn:water}" \\
  CH4 + 2 O2 &-> CO2 + 2 H2O "\label{rxn:methane}"
\end{reactions}

In \cref{rxn:water} water is formed. \Cref{rxn:methane} shows the combustion
of methane.

\end{document}

在此处输入图片描述

也可以轻松进行定制:

\documentclass{article}

\usepackage{chemmacros}% uses chemformula as default
\chemsetup{
  modules = {reactions} ,
  reactions/tag-open  = ( ,
  reactions/tag-close = )
}
\renewcommand*\thereaction{\Roman{reaction}}

\usepackage{cleveref}

\begin{document}

\begin{reactions}
  2 H2 + O2 &-> 2 H2O "\label{rxn:water}" \\
  CH4 + 2 O2 &-> CO2 + 2 H2O "\label{rxn:methane}"
\end{reactions}

In \cref{rxn:water} water is formed. \Cref{rxn:methane} shows the combustion
of methane.

\end{document}

在此处输入图片描述

答案3

这是您要找的吗?另外,您的等式中需要一些空格(例如,H2+应转换为H2 +)。我还删除了 MWE 中的许多行,使其更简洁一些。

\documentclass[a4paper,oneside,12pt,openright]{book}

\usepackage{chemformula}
\usepackage{cleveref}
\begin{document}
    \begin{align}
    \ch{2 H2 + O2 &-> 2 H2O}  \label{water}  \\
    \ch{CH4 + 2 O2 &-> CO2 + 2 H2O} \label{methanecombustion}
    \end{align}


    As per above \cref{water} water is formed. And here is some \cref{methanecombustion} methane combustion.

\end{document}

在此处输入图片描述

相关内容