You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用tcolorbox修改公式默认颜色样式及定理边框个性化设置

解决tcolorbox定理与公式边框的自定义问题

一、为不同定理单独设置边框颜色(无需全局重定义)

利用tcolorbox的\newtcbtheorem命令,在每个定理的定义选项中直接指定边框参数即可:

首先确保导言区加载必要的包:

\usepackage{tcolorbox}
\tcbuselibrary{theorems} % 适配AMS风格定理结构

然后分别定义三种不同边框的定理:

% 1. 绿色边框定理
\newtcbtheorem{greenthm}{定理}{colframe=green, boxrule=1pt}{thm}

% 2. 黑色边框定理
\newtcbtheorem{blackthm}{定理}{colframe=black, boxrule=1pt}{thm}

% 3. 无边框定理
\newtcbtheorem{noframethm}{定理}{noboxrule, colframe=white}{thm}

使用示例:

\begin{greenthm}{勾股定理}{pythagoras}
直角三角形两直角边的平方和等于斜边的平方:
\[a^2 + b^2 = c^2\]
\end{greenthm}

\begin{blackthm}{均值不等式}{mean}
对非负实数 \(x,y\),有:
\[\frac{x+y}{2} \geq \sqrt{xy}\]
\end{blackthm}

\begin{noframethm}{空集性质}{emptyset}
空集是任意集合的子集:
\[\emptyset \subseteq S\]
\end{noframethm}

二、修改/移除公式的边框样式

如果你的公式是通过tcolorbox的\tcboxmath命令加框的,直接在命令内追加选项即可:

  • 将公式边框改为绿色:
\tcboxmath[colframe=green]{a^2 + b^2 = c^2}
  • 移除公式边框:
\tcboxmath[noboxrule, colframe=white]{a^2 + b^2 = c^2}

如果是定理环境默认给所有公式加了边框,可在定理定义时覆盖公式的框样式:

\newtcbtheorem{customthm}{定理}{
  colframe=blue,
  math upper={\tcboxmath[colframe=green]{##1}} % 自定义定理内公式的边框
}{thm}

核心参数说明

  • colframe=<颜色>:设置边框颜色,支持颜色名称、混色表达式(如red!30!green)
  • boxrule=<数值>:调整边框厚度,单位为pt
  • noboxrule:快速移除边框(效果等同于boxrule=0pt)

内容的提问来源于stack exchange,提问作者Dan317

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 20:35:08