latex align外加边框
时间: 2025-01-29 14:39:34 浏览: 70
### 实现带有边框的 `align` 环境
为了给 `align` 环境添加边框,可以利用 `fancybox` 或者更现代的 `tcolorbox` 宏包来创建带边框的效果。下面展示一种基于 `tcolorbox` 的解决方案。
#### 使用 `tcolorbox` 创建带边框的 `align`
首先,在文档导言区加载必要的宏包:
```latex
\usepackage{amsmath}
\usepackage[most]{tcolorbox}
```
接着定义一个新的命令用于快速应用这种样式:
```latex
% 自定义一个有边框的 align 环境
\newtcbox{\myborder}{nobeforeafter, math upper, tcbox raise base,
enhanced, colframe=blue!50!black,colback=yellow!10!white, boxrule=0.8pt}
\tcbset{
myformula/.style={
arc=0mm,
outer arc=0mm,
boxsep=0mm,
top=2mm,
bottom=2mm,
left=2mm,
right=2mm,
boxrule=0.4pt,
colframe=red,
colback=white
}
}
```
最后在正文中按照如下方式调用自定义环境包裹住原来的 `align*` :
```latex
\begin{equation}
\myborder{
\begin{aligned}
E &= mc^2 \\
F &= ma
\end{aligned}}
\end{equation}
```
或者对于不编号的情况可以直接使用 `\tcboxedenvironment` 命令配合之前设置好的风格参数:
```latex
\tcboxedenvironment{align*}{
nobeforeafter,
myformula
}
\begin{document}
Some text before the equation.
\begin{align*}
H(x) &= \int_{-\infty}^{+\infty}\hat{f}(\xi)\,e^{2\pi i\xi x}\,\mathrm{d}\xi\\
& = \sum_n a_ne^{inx}.
\end{align*}
More text after it.
\end{document}
```
这种方法不仅能够为公式添加美观的边框效果,而且还可以灵活调整颜色、线条粗细等属性[^2]。
阅读全文
相关推荐













