我正在尝试创建一个新环境,更具体地说是使用。我的目的是创建一个将和\newtcolorbox[]{}{}{}
结合在一起的环境,以使其更易于使用。我想创建一个名为的环境,该环境具有 tcolorbox 包中的以下功能:\begin{tcolorbox}[] \end{tcolorbox}
\begin{equation} \end{equation}
answer
\newtcolorbox[]{answer}{%
enhanced,
center,
breakable,
boxrule = 0pt,
frame hidden,
hbox,
colback = myblack!80,
sharp corners,
rounded corners = southeast,
rounded corners = northeast,
rounded corners = southwest,
rounded corners = northwest,
arc is angular,
arc = 3mm,
coltext = white,
math upper,
}
我可以创建一个框,将所有输入转换为数学输出,但是,我还希望能够引用这些框内的方程式,以便如果我输入:
\begin{answer}\label{eq: 1}
A random equation
\end{answer}
我可以引用这个方程,使得计数器遵循方程或对齐环境中的相同计数器吗?我尝试将其包含在初始选项中[use counter from = equation]
,但它不起作用。
答案1
您可以使用\tcbhighmath{...}
来突出显示您的公式:
\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{environ}
\NewEnviron{answer}{
\begin{equation}
\tcbhighmath[
boxrule = 0pt,
frame hidden,
colback = black!80,
sharp corners,
rounded corners = southeast,
rounded corners = northeast,
rounded corners = southwest,
rounded corners = northwest,
arc is angular,
arc = 3mm,
coltext = white,
]{\BODY}\end{equation}}
\begin{document}
\begin{answer}\label{eq:1}
A random equation
\end{answer}
A random equation in \eqref{eq:1}
\end{document}