\caption可以为表格提供标题,默认是有序号的。
1. 标题相对于表格的位置
第一种方法,使用\captionsetup命令。例如:
\captionsetup[table]{position=above}
其中position的值有三种:top(caption命令出现的位置),above(上),below(下),bottom(下)和auto(默认)。这个命令效果等同于将position作为option来调用caption包(其他caption包的调用选项见下文)。
第二种方法:\caption命令写在tabular前面则标题会出现在表格上方,若写在tabular后面则标题会出现在表格下方。如下面代码\caption写在tabular之前,因此打印出来的表格标题出现在表格上方。
\begin{table}
\caption{a table of scores}
\begin{tabular}{|l|l|l|l|}
Any & 112 & 123 & 132 \\
Zhang & 324& 345 & 345 \\
David & 123 & 34 & 45 \\
Araminta & 133 & 33 & 35 \\
\end{tabular}
\end{table}
若将\caption放在后面则会出现如下效果:
2. 去掉标题的序号
若在此基础上加星号改成\caption*{}则可以去掉序号“表1”,如下所示:
也即使用代码:
\begin{table}
\begin{tabular}{|l|l|l|l|}
Any & 112 & 123 & 132 \\
Zhang & 324& 345 & 345 \\
David & 123 & 34 & 45 \\
Araminta & 133 & 33 & 35 \\
\end{tabular}
\caption*{a table of scores}
\end{table}
3. 修改标题序号的名称
若要将表序号从“表1”修改成“tab1”等类似形式,则可通过自定义命令实现。例如,若要将表格标号改为“星星n”,则在整个环境最前面增加如下定义:
\renewcommand{\tablename}{星星}
4. 标题序号重新开始计数
在需要重新计数的地方使用如下代码,则可从此从0开始计数。
\setcounter{table}{0}
5. 标题格式设置
\usepackage[<options>]{caption}
a. caption包的调用及常见选项
使用caption包,如上所示,其中方括号里面的内容为选项。选项可用于设定caption命令的功能范围,可使用的选项包括下面的几种:
normal 默认模式,提供常用的几种标题;
hang 和 isu, 提供悬挂缩进的标题;
center 提供居中标题;
centerlast 提供最后一行居中的标题;
nooneline 取消标题为一行时居中的默认效果;
scriptsize,..., Large 提供不同字号的标题;
up, it, sl, sc, md, bf, rm, sf, tt 提供标题内容的字形特性;
ruled 提供float包的浮块。
b. 其他性质
\captionfont和\captionlabelfont提供上述性质之外的其他字体字号性质。\caption需要在每个标题之前使用,\captionlabelfont需要在标题标签前使用。例如:
{\captionfont{\captionlabelfont<label>:}<caption>}
\captionmargin提供满足左右页边距的标题,例如:
\setlength{\captionmargin}{10pt}
\abovecaptionskip和\belowcaptionskip分别表示标题上下的空白,二者默认值分别为10pt和0pt。
6. \captionsetup命令
\captionsetup[table]{labelfont=bf,textfont=it}
上述命令可以为table也即表格环境内部的标题提供具体的设置,在{}括号内可以设定各种性质。例如这个例子当中,labelfont是为序号部分设定字体,textfont则作用于标题。分别是黑体和斜体,打印出来的标题字体如下图所示:
7. 标题格式自定义
a. 我们可以通过如下代码格式来完成标题性质的自定义:
\DeclareCaptionFormat{<name>}{<code using #1, #2 and #3>}
系统会自动使用#1,#2,#3分别替代序号内容、分隔符和标题文本。
b. 类似地,如下代码可用于自定义标题序号部分的性质:
\DeclareCaptionLabelFormat{<name>}{<code using #1 and #2>}
系统会自动使用#1,#2来代替序号的文字部分和数字部分。例如:
\DeclareCaptionLabelFormat{bf-parens}{(\textbf{#2})}
\captionsetup{labelformat=bf-parens,labelsep=quad}
c. 我们也可以用代码定义自己的标题用分隔符:
\DeclareCaptionLabelSeparator{<name>}{<code>}
例如,我们可以定义如下分隔符:
\DeclareCaptionLabelSeparator{colon}{: }
d. 我们可以定义对齐方式如下:
\DeclareCaptionJustification{<name>}{<code>}
例如,我们可以定义标题的左右对齐方式如下:
\DeclareCaptionJustification{raggedright}{\raggedright}
e. 定义字号如下:
\DeclareCaptionFont{<name>}{<code>}
例如:
\DeclareCaptionFont{small}{\small}
f. 通过使用color包,我们可以定义标题颜色,例如:
\usepackage{color}
\DeclareCaptionFont{red}{\color{red}}
\DeclareCaptionFont{green}{\color{green}}
\DeclareCaptionFont{blue}{\color{blue}}
\captionsetup{labelfont={blue,bf},textfont=green}
8. 标题风格自定义
\DeclareCaptionStyle{<name>}[<additional options>]{<options>}
其中additional options只能使用那些在一行之内可以实现的性质。并且,这些性质不能被 singlelinecheck=off作用。例如:
\DeclareCaptionStyle{mystyle}[margin=5mm,justification=centering]{font=footnotesize,labelfont=sc,margin={10mm,0mm}}
\captionsetup{style=mystyle}
9. 实例
未完待续。。。