latex -\newenvironment 带有一个带有可选标题的 tcolorbox

标签 latex math-mode

我想创建一个特殊的环境,将数学模式包含在 tcolorbox 中。 tcolorbox 标题分配必须是可选的,但总的来说,我对进行可选的 tcolorbox 选项分配感兴趣。我正在尝试:

\documentclass{article}
\usepackage{tikz,lipsum,lmodern}
\usepackage[most]{tcolorbox}

\newtcolorbox{eqbox}[1]
{
colback=gray!10,
arc=0pt,
boxrule=0pt,
title=#1 % I would like to make this (one of these in general) assignment optional depending on #1, #2...
}

 \newenvironment{boxenv}[1][]{
    \begin{eqbox}[#1]
    \[
 }{
   \]
   \end{eqbox}
}


\begin{document}



\begin{boxenv}[Optional box title]
a+b+c+d
\end{boxenv}

\begin{boxenv}[]
a+b+c+d
\end{boxenv}

\end{document}

我得到的结果是: enter image description here

我想要得到的结果是: enter image description here

最佳答案

\newtcolorbox{eqbox}[1][]{} 中缺少空默认值,否则这将被视为强制参数。

\documentclass{article}
\usepackage{tikz,lipsum,lmodern}
\usepackage[most]{tcolorbox}

\newtcolorbox{eqbox}[1][]
{
colback=gray!10,
arc=0pt,
boxrule=0pt,
title=#1 % I would like to make this (one of these in general) assignment optional depending on #1, #2...
}

 \newenvironment{boxenv}[1][]{
    \begin{eqbox}[#1]
    \[
 }{
   \]
   \end{eqbox}
}


\begin{document}



\begin{boxenv}[Optional box title]
a+b+c+d
\end{boxenv}

\begin{boxenv}[]
a+b+c+d
\end{boxenv}

\end{document}

enter image description here

(如果您需要更灵活地使用可选和强制参数,请在 tcolorbox 文档中搜索 \DeclareTColorBox )

关于latex -\newenvironment 带有一个带有可选标题的 tcolorbox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71630378/

相关文章:

latex - 如何更改 tex 数学模式下的默认背景颜色?

vim - 在vim中编辑 latex : how to change text to math mode

latex - LaTeX 文件的 VIM 自动缩进错误

latex - 如何在 LaTeX 的数学模式下显示插入符号 (^)?

r - pdf、docx、html 输出中的 bookdown 中数学方程编号一致

latex - XeTeX - 检测何时需要重新运行

latex - 如何在 LaTeX 中使方程跨越整页/整行?

LaTeX\cite 给出一个 [?]

matlab - "pdfLatex has stopped working"Matlab调用时提示