tcolorbox 宏包是 Thomas F. Sturm 开发的一个用于绘制彩色文本框的宏包。tcolorbox 底层基于pgf,功能也是十分强大。
一个月前,有群友在群里问到如何制作下面这样的蓝色边框,于是这里借着实现这一边框的时机,简单讲讲 tcolorbox 的用法。
概述:安装与调用和大多数宏包一样,tcolorbox 被 MiKTeX 和 TeX Live 都收录其中。因此,通常情况,你只需要用相应的宏包管理器安装就好。
使用起来,也很简单。和其他宏包一样,你需要在导言区,使用 \usepackage 命令调用这个宏包。
\usepackage{tcolorbox}你可以在调用宏包时,用可选参数指明需要加载哪些程序库;也可以在调用 tcolorbox 之后,显式地使用 \tcbuselibrary 来调用 tcolorbox 提供的丰富程序库。比如,下面的代码调用了 skins, breakable, theorems 三个程序库。
\usepackage{tcolorbox} \tcbuselibrary{skins, breakable, theorems}每个程序库,都对应着一个 tcbXXX.code.tex 文件。实际上,使用 \tcbuselibrary 命令,就是调用了一个个这样的文件。以下是常见可用的 tcolorbox 程序库:
- skins: 调用 tikz 宏包,提供丰富的文本框样式;
- vignette: 提供一些装饰性的样式;
- raster: 用以调整若干 tcolorbox 的排布样式
- listings/listingsutf8/minted: 用以和对应的宏包联用,实现好看的代码清单
- theorems: 用以生成定理类环境
- breakable: 实现自动分页的文本框
- magazine: 实现类似杂志的分段文本
- fitting: 实现字体大小和文本框大小的自适应
tcolorbox 宏包提供了与宏包同名的环境,是整个宏包的基础环境,用于生成段落间的文本框。与之对应,宏包还提供了 \tcbox 命令,用于生成行内的文本框。
- \begin{tcolorbox}[options]
-
- environment content
-
- \end{tcolorbox}
-
-
- \tcbox[options]{box content}tcolorbox 环境和 \tcbox 命令都可以接收一组选项,用来控制文本框的样式。我们来看看下面的代码,及其相应的效果。\documentclass{article}
-
- \usepackage{tcolorbox}
-
- \usepackage{colortbl}
-
- \usepackage{geometry}
-
- \geometry{margin = 1in}
-
- \begin{document}
-
- \begin{tcolorbox}
-
- This is my first \textbf{tcolorbox}.
-
- \end{tcolorbox}
-
-
- \begin{tcolorbox}
-
- This is another \textbf{tcolorbox}.
-
- \tcblower
-
- Here, you see the lower part of the box.
-
- \end{tcolorbox}
-
-
- \begin{tcolorbox}[title = {I Love Sophia}]
-
- This is a \textbf{tcolorbox} with title.
-
- \tcblower
-
- Here, you see the lower part of the box.
-
- \end{tcolorbox}
-
-
- \tcbset{colframe = blue!50!black, colback = white,
-
- colupper = red!50!black, fonttitle = \bfseries,
-
- nobeforeafter, center title}
-
-
- Text \tcbox[tcbox raise base]{Hello World}\hfill
-
- %
-
- \tcbox[left = 0mm, right = 0mm, top = 0mm, bottom = 0mm, boxsep = 0mm,
-
- toptitle = 0.5mm, bottomtitle = 0.5mm, title = {My table}]
-
- {\arrayrulecolor{blue!50!black}
-
- \renewcommand{\arraystretch}{1.2}%
-
- \begin{tabular}{r|c|l}
-
- One & Two & Three \\
-
- \hline\hline
-
- Men & Mice & Lions \\\hline
-
- Upper & Middle & Lower
-
- \end{tabular}}\hfill
-
- %
-
- \tcbox[colback=blue!85!black,
-
- left = 0mm, right = 0mm, top = 0mm, bottom = 0mm,
-
- boxsep = 1mm, arc = 0mm, boxrule = 0.5pt, title = {My picture}]
-
- {\includegraphics[width = 5cm]{example-image}}
-
-
- \end{document}


雷达卡



京公网安备 11010802022788号







