添加彩色圆角文本框

本文涉及宏包
基础代码
\documentclass{article}
\usepackage[most]{tcolorbox}
\tcbuselibrary{breakable}
\begin{document}
\begin{tcolorbox}[`colback`=gray!10,
colframe=black,
width=14cm,
arc=2mm, auto outer arc,
title={Letter},breakable,]
This is a test.
\end{tcolorbox}
\end{document}
效果

colback
设置文本区的颜色填充
colframe
设置框线的颜色
width
设置文本框的宽度
arc
设置圆角的大小
breakable
表示框可跨页,需要在导言区添加\ref\tcbuselibrary{breakable}
引入breakable库
- [ ] 内设置的每条后面加逗号 ,
- 颜色调整和正文区颜色设置同理,可参考 LaTex颜色使用
跨页
使用breakable
的跨页效果

若想去掉两页之间的黑边框线,使用enhanced jigsaw
,并在导言区添加\tcbuselibrary{skins}
% 引入 skins 库
\documentclass{article}
\usepackage{lipsum}
\usepackage{hyperref}
\usepackage[most]{tcolorbox}
\tcbuselibrary{breakable} % 引入 breakable 库
\tcbuselibrary{skins} % 引入 skins 库
\begin{document}
\begin{tcolorbox}[colback=gray!10,%gray background
colframe=black,% black frame colour
width=14cm,% Use 5cm total width,
arc=2mm, auto outer arc,
title={Letter},breakable,enhanced jigsaw,
before upper={\parindent15pt\noindent}, ]
\lipsum
\end{tcolorbox}
\end{document}

缩进
- tcolorbox 内文本默认是不缩进的,若想文字缩进2字符,可在设置区加入
before upper={\parindent15pt\noindent},
未缩进代码
\begin{tcolorbox}[colback=gray!10,%gray background
colframe=black,% black frame colour
width=14cm,% Use 5cm total width,
arc=2mm, auto outer arc,
title={Letter},breakable,]
This is a test. This is a test. This is a test. This is a test.This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.This is a test. This is a test.
\end{tcolorbox}
效果

添加缩进后
\begin{tcolorbox}[colback=gray!10,%gray background
colframe=black,% black frame colour
width=14cm,% Use 5cm total width,
arc=2mm, auto outer arc,
title={Letter},breakable,
before upper={\parindent15pt\noindent}, ]
This is a test. This is a test. This is a test. This is a test.This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.This is a test. This is a test.
\end{tcolorbox}

基本命令
tcolorbox宏包提供的命令,多以“tcb”开头,为“TColorBox”的缩写。
命令 |
说明 |
\tcblower |
指示开始tcolorbox的下半部分 |
\tcbset{options} |
为此命令之后的所有顶层tcolorbox设置options。(不包括包含在tcolorbox内部的tcolorbox。) |
\tcbsetforeverylayer{options} |
tcbset for every layer,为此命令之后的所有的tcolorbox设置options。 |
\tcbox{content} |
根据content的宽度建立一个无下半部分的、不可分页的tcolorbox。 |
\newtcolorbox{name}{options} |
建立一个以name作为环境名的,预设options的tcolorbox。(类比于\newenvironment) |
\renewtcolorbox{name}{options} |
更新以name作为环境名的tcolorbox,类比于\renewenvironment |
\newtcbox{name}{options} |
建立一个以name作为环境名的,预设options、无下半部分、不可分页tcolorbox。(类比于\newcommand) |
\renewtcbox{name}{options} |
更新以name作为环境名的,预设options、无下半部分、不可分页tcolorbox。(类比于\renewcommand) |
\tcolorboxenviroment{name}{options} |
基于已有的name环境,建立一个预设options的tcolorbox。 |
colorbox基本的可设置参数
tcolorbox的可设置参数庞杂繁复,主要分为以下几类:
标题相关的设置 |
说明 |
title={title} |
设置tcolorbox的标题 |
notitle |
去除tcolorbox的标题行 |
adjusted title={text} |
配合adjusted title使用,将tcolorbox的标题行的高度设置为adjusted title的高度。 |
adjusted text={text} |
配合adjusted title使用,为tcolorbox标题行设置高度。 |
squeezed title={title} |
将过长的标题压缩到一行 |
titlebox={mode} |
指定标题行内容的处理方式,mode的可选值包括visible和invisible。 |
detach title |
将tcolorbox的标题行内容脱离预定位置,并存储在 \tcbtitletext 中。格式化的标题可通过 \tcbtitle 读取。 |
attach title |
将标题行的内容恢复到原来的位置 |
attach title to upper={text} |
将text插入到格式化的标题和tcolorbox内容之间。 |
subtitle style={options} |
设置副标题的格式 |
- 上、下部分相关的,tcolorbox可以通过\tcblower被分为上下两部分:
上下部分相关参数 |
说明 |
upperbox={mode} |
上半部分内容的处理方式。(类似于titlebox、lowerbox),mode的可选值包括visible和invisible。 |
lowerbox={mode} |
下半部分内容的处理方式。(类似于titlebox、upperbox),mode的可选值包括visible和invisible。 |
saveto={filename} |
将tcolorbox的内容(也包括下半部分)保存至filename中 |
savelowerto={filename} |
将下半部分的内容保存至filename中。 |
lower separated={true |
false} |
字体相关设置 |
说明 |
fonttitle={content} |
设置在标题前的内容,可包括格式化命令 |
fontupper={content} |
设置在上半部分前的内容,可包括格式化命令 |
fontlower={content} |
设置在下半部分前的内容,可包括格式化命令 |
颜色相关设置 |
说明 |
colframe={color} |
即color of frame,设置边框的颜色 |
colback={color} |
即color of background,设置背景的颜色 |
title filled={true |
false} |
colbacktitle={color} |
即color of title background,标题的背景颜色 |
colupper={color} |
color of upper text,上半部分字体颜色 |
collower={color} |
color of lower text,下半部分字体颜色 |
coltext={color} |
同时设置上下部分的字体颜色 |
coltitle={color} |
color of title text,设置标题的字体颜色 |
- 文本排列相关的,依然分为标题、上半部分、下半部分:
文本排列相关设置 |
说明 |
halign={alignment} |
horizontal alignment,即文本的水平对齐方式(仅包括上半部分)。可选值包括justify、left、flush left、right、flush right、center和flush center。 |
halign upper={alignment} |
同halign={alignment} |
halign lower={alignment} |
设置下半部分文本的对齐方式。 |
halign title={alignment} |
设置标题的对齐方式。 |
valign={alignment} |
vertical alignment,上半部分垂直对齐方式。可选值包括top、center、bottom、scale(即拉伸或压缩文本以符合tcolorbox的高度)以及scale*(受限的scale)。 |
形状设置参数 |
说明 |
width={length} |
设置tcolorbox的宽度。 |
text width={length} |
设置上半部分文本的宽度。 |
add to width={length} |
在现有的宽度上加上length。 |
height={length} |
设置高度。 |
text height={length} |
设置上半部分文本的高度。 |
toprule={length} |
设置上边框的厚度 |
bottomrule={length} |
设置下边框的厚度 |
leftrule={length} |
设置左边框的厚度 |
rightrule={length} |
设置右边框的厚度 |
boxrule={length} |
设置边框的厚度 |
弧度相关设置 |
说明 |
arc={length} |
设置四个角的内半径。 |
circular arc |
将arc设置为内部文本的一半。 |
bean arc |
将arc设置tcolorbox高度和宽度中较小值的一半。 |
octogon arc |
嗯,一般何少用到吧,可以看看tcolorbox的说明。 |
outer arc={length} |
设置四角的外边的半径 |
角落设置 |
说明 |
sharp corners={position} |
将指定的角落设置为直角。可选值包括:northwest、northeast、southwest、southeast、north、south、east、west、downhill、uphill和all。 |
rounded corners={position} |
将指定角落设置为弧形,可选值同shrap cornes。 |
- 间距相关设置:显然间距的设置又可分为上、下、左、右,标题和文本。
间距相关设置 |
说明 |
boxsep={length} |
该值将会加到设置的上下左右间隔上。 |
left={length} |
|
lefttitle={length} |
|
leftupper={length} |
|
leftlower={length} |
|
right={length} |
|
righttitle={length} |
|
rightupper={length} |
|
rightlower={length} |
|
top={length} |
|
toptitle={length} |
|
bottom={length} |
|
bottomtitle={length} |
|
middle={length} |
设置上下部分文本与上下分割线之间的距离。 |
透明设置 |
说明 |
opacityframe={fraction} |
边框的透明程度 |
opacityback={fraction} |
上下部分背景的透明程度 |
opacitybacktitle={fraction} |
标题背景的透明程度 |
opacityfill={fraction} |
|
opacityupper={fraction} |
上半部分文本的透明程度 |
opacitylower={fraction} |
下半部分文本的透明程度 |
opacitytext={fraction} |
同时设置上下部分文本的透明程度 |
opacitytitle={fraction} |
标题文本的透明程度 |
所有评论(0)