【Latex边框环境】tcolorbox环境美化典例简洁代码

核心思路:先用 \newtheorem 定义普通环境,再用\tcolorboxenvironment 美化,既保留了原有编号、引用功能,又实现了美观的盒子效果。分为有编号标题的边框,和无编号标题的自定义边框。典例简洁代码如下

% 中文文章类(自动处理中文排版、字号、标题等)
\documentclass{ctexart}   
% amsmath:数学公式增强;amsthm:定义定理类环境
\usepackage{amsmath, amsthm}   
% 彩色盒子宏包,many 选项加载所有辅助库
\usepackage[many]{tcolorbox}           

% 新建 theorem 环境,标题“定理”,按节编号
\newtheorem{theorem}{定理}[section] 
%新建 definition 环境,标题“定义”,按节编号
\newtheorem{definition}{定义}[section]
% 新建 example 环境,标题“例”,按节编号
\newtheorem{example}{}[section]
% 新建 remark 环境,标题“注”,按节编号 
\newtheorem{remark}{}[section] 

% 给 theorem环境套上tcolorbox外观
% 下面definition/example/remark类似,只是边框颜色不同
\tcolorboxenvironment{theorem}{       
	boxrule=1pt,  %边框粗细 1colback=white,  %背景白色
	colframe=blue!75!black, %边框蓝色(混75%蓝+25% 黑)
	fonttitle=\bfseries, %环境标题(如“定理 1.1”)加粗
	breakable  %允许跨页断开
}

\tcolorboxenvironment{definition}{
	boxrule=1pt,
	colback=white,
	colframe=green!50!black,  %边框绿色(50% 绿+50% 黑)
	fonttitle=\bfseries,
	breakable
}
\tcolorboxenvironment{example}{
	boxrule=1pt,
	colback=white,
	colframe=orange!75!black,  %边框橙色
	fonttitle=\bfseries,
	breakable
}
\tcolorboxenvironment{remark}{
	boxrule=1pt,
	colback=white,
	colframe=gray!75!black, %边框灰色
	fonttitle=\bfseries,
	breakable
}

%下面自定义4个无标题无编号的纯边框
\newtcolorbox{mytheorem}{
	boxrule=1pt,
	colback=white,
	colframe=blue!75!black,
	breakable
}
\newtcolorbox{mydefinition}{
	boxrule=1pt,
	colback=white,
	colframe=green!50!black,
	breakable
}
\newtcolorbox{myexample}{
	boxrule=1pt,
	colback=white,
	colframe=orange!75!black,
	breakable
}
\newtcolorbox{myremark}{
	boxrule=1pt,
	colback=white,
	colframe=gray!75!black,
	breakable
}

\begin{document}
	\section{示例}
	有标题编号的边框
	\begin{theorem}[费马大定理]
		对于整数 $n>2$,方程 $x^n + y^n = z^n$ 没有正整数解。
	\end{theorem}
	
	\begin{definition}[可导性]
		设函数 $f$ 在点 $x_0$ 的某邻域内有定义,若极限
		\[
		\lim_{h\to 0}\frac{f(x_0+h)-f(x_0)}{h}
		\]
		存在,则称 $f$ 在 $x_0$ 处可导。
	\end{definition}
	
	\begin{example}
		函数 $f(x)=|x|$ 在 $x=0$ 处连续但不可导。
	\end{example}
	
	\begin{remark}
		上面的例子说明连续不一定可导。分页测试
		上面的例子说明连续不一定可导。测试
		上面的例子说明连续不一定可导。测试\\
		上面的例子说明连续不一定可导。测试\\
		上面的例子说明连续不一定可导。测试\\
		上面的例子说明连续不一定可导。测试
		上面的例子说明连续不一定可导。测试
		上面的例子说明连续不一定可导。测试\\
		上面的例子说明连续不一定可导。测试\\
		上面的例子说明连续不一定可导。测试\\
		上面的例子说明连续不一定可导。测试\\
		上面的例子说明连续不一定可导。测试
		上面的例子说明连续不一定可导。分页测试
		上面的例子说明连续不一定可导。测试
		上面的例子说明连续不一定可导。测试\\
		上面的例子说明连续不一定可导。测试\\
		上面的例子说明连续不一定可导。测试\\
		上面的例子说明连续不一定可导。测试
		上面的例子说明连续不一定可导。测试
		上面的例子说明连续不一定可导。测试\\
		上面的例子说明连续不一定可导。测试\\
		上面的例子说明连续不一定可导。测试\\
		上面的例子说明连续不一定可导。测试\\
		上面的例子说明连续不一定可导。测试
		上面的例子说明连续不一定可导。分页测试
		上面的例子说明连续不一定可导。测试
		上面的例子说明连续不一定可导。测试\\
		上面的例子说明连续不一定可导。测试\\
		上面的例子说明连续不一定可导。测试\\
		上面的例子说明连续不一定可导。测试
		上面的例子说明连续不一定可导。测试
		上面的例子说明连续不一定可导。测试\\
		上面的例子说明连续不一定可导。测试\\
		上面的例子说明连续不一定可导。测试\\
		上面的例子说明连续不一定可导。测试\\
		上面的例子说明连续不一定可导。测试
		\begin{align*}
			f(x)=\displaystyle\frac{\ln x}{x}
		\end{align*}
	\end{remark}
	
	无标题编号的自定义纯边框 
		\begin{mytheorem}
			对于整数 $n>2$,方程 $x^n + y^n = z^n$ 没有正整数解。
		\end{mytheorem}
		
		\begin{mydefinition}
			设函数 $f$ 在点 $x_0$ 的某邻域内有定义,若极限 $\lim_{h\to 0}\frac{f(x_0+h)-f(x_0)}{h}$ 存在,则称 $f$ 在 $x_0$ 处可导。
		\end{mydefinition}
		
		\begin{myexample}
			函数 $f(x)=|x|$ 在 $x=0$ 处连续但不可导。
		\end{myexample}
		
		\begin{myremark}
			上面的例子说明连续不一定可导。
		\end{myremark}
	
\end{document}

运行效果如下
在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值