我正在嘗試創建一個新環境,更具體地說,使用\newtcolorbox[]{}{}{}
.我的目的是創造一個將\begin{tcolorbox}[] \end{tcolorbox}
和結合在一起的環境\begin{equation} \end{equation}
,以使其更易於使用。我想創建一個名為answer
tcolorbox 包中具有以下功能的環境:
\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}