LaTeX表格tabular背景色添加技巧 [转]

摘要:
我们所用的宏包为colortbl,这个宏包可以设置表格中数据、文本、行、列、单元格前景和背景以及边框的颜色,从而得到彩色表格。同时需要array和color两个宏包的支持。宏包提供了一组着色命令,经常用到是列着色命令,其格式为:\columncolor[色系]{色名}[左伸出][右伸出]。常用色系有三原色rgb灰度gray和四色cmyk三种;被预定义的色名有68个,详见color宏包介绍中所附的色标;左右伸出的长度单位可用pt。

我们所用的宏包为colortbl,这个宏包可以设置表格中数据、文本、行、列、单元格前景和背景以及边框的颜色,从而得到彩色表格。同时需要 array 和 color 两个宏包的支持。 宏包提供了一组着色命令,经常用到是列着色命令,其格式为:

\columncolor[色系]{色名}[左伸出][右伸出]。

常用色系有三原色 rgb 灰度 gray和四色cmyk三种;被预定义的色名有68个,详见 color 宏包介绍中所附的色标;左右伸出的长度单位可用 pt。

colortbl的主要命令

命令

作用

\columncolor

让整个字段着色

\rowcolor

整个横列着色

\arrayrulecolor{颜色}

指定线条的颜色

\doublerulesepcolor{颜色}

指定双线内间隔的颜色

在这里,\columncolor\rowcolor 的参数是一样的,他们的共同语法是:

\columncolor[颜色模型]{颜色}[左伸出长度][右伸出长度]

我们现在就来看个实例,这里头有些例子,包括:灰阶横条、部份字段着色、整个表格在着色背景及单一个表格内方框着色:

LaTeX技巧421:LaTeX表格tabular背景色添加技巧
LaTeX技巧421:LaTeX表格tabular背景色添加技巧
LaTeX技巧421:LaTeX表格tabular背景色添加技巧
LaTeX技巧421:LaTeX表格tabular背景色添加技巧
LaTeX技巧421:LaTeX表格tabular背景色添加技巧
LaTeX技巧421:LaTeX表格tabular背景色添加技巧
示例代码如下:

\documentclass[12pt]{article}
\usepackage{textcomp,booktabs}
\usepackage[usenames,dvipsnames]{color}
\usepackage{colortbl}
\definecolor{mygray}{gray}{.9}
\definecolor{mypink}{rgb}{.99,.91,.95}
\definecolor{mycyan}{cmyk}{.3,0,0,0}
\parindent=0pt
\parskip=3ex
\begin{document}
\centering
\section*{SPECIFIC HEATS (20 \textcelsius\ AND 1 ATM)}
\begin{tabular}{>{\sf }lll}

%
\toprule
& \multicolumn{2}{c}{\bf Specific Heats} \\
\cmidrule{2-3}
& $c$ (J/kg$\cdot$K) & $C$ (J/mol$\cdot$K) \\
\midrule
Aluminum & 900 & 24.3 \\
\rowcolor{mygray}
Copper & 385 & 24.4 \\
Gold & 130 & 25.6 \\
\rowcolor{mygray}
Steel/Iron & 450 & 25.0 \\
Lead & 130 & 26.8 \\
\rowcolor{mygray}
Mercury & 140 & 28.0 \\
Water & 4190 & 75.4 \\
\rowcolor{mygray}
Ice ($-$10 \textcelsius) & 2100 & 38 \\
\bottomrule
\end{tabular}
\vspace{8ex} %
\section*{SPECIFIC HEATS (20 \textcelsius\ AND 1 ATM)}
\begin{tabular}{>{\columncolor{mypink}\sf }lll@{}}
\toprule
\rowcolor{white}
& \multicolumn{2}{c}{\bf Specific Heats} \\
\cmidrule{2-3}
\rowcolor{white}
& $c$ (J/kg$\cdot$K) & $C$ (J/mol$\cdot$K) \\
\midrule
Aluminum & 900 & 24.3 \\
Copper & 385 & 24.4 \\
Gold & 130 & 25.6 \\
Steel/Iron & 450 & 25.0 \\
Lead & 130 & 26.8 \\
Mercury & 140 & 28.0 \\
Water & 4190 & 75.4 \\
Ice ($-$10 \textcelsius) & 2100 & 38 \\
\bottomrule
\end{tabular}
\section*{SPECIFIC HEATS (20 \textcelsius\ AND 1 ATM)}
\fboxsep=12pt
\colorbox{mypink}{
\begin{tabular}{@{}>{\sf }lll@{}}
\toprule
& \multicolumn{2}{c}{\bf Specific Heats} \\
\cmidrule{2-3}
& $c$ (J/kg$\cdot$K) & $C$ (J/mol$\cdot$K) \\
\midrule
Aluminum & 900 & 24.3 \\
Copper & 385 & 24.4 \\
Gold & 130 & 25.6 \\
Steel/Iron & 450 & 25.0 \\
Lead & 130 & 26.8 \\
Mercury & 140 & 28.0 \\
Water & 4190 & 75.4 \\
Ice ($-$10 \textcelsius) & 2100 & 38 \\
\bottomrule
\end{tabular}}
\vspace{8ex} %
\section*{SPECIFIC HEATS (20 \textcelsius\ AND 1 ATM)}
\begin{tabular}{@{}>{\sf }lll@{}}
\toprule
& \multicolumn{2}{c}{\bf Specific Heats} \\
\cmidrule{2-3}
& $c$ (J/kg$\cdot$K) & $C$ (J/mol$\cdot$K) \\
\midrule
Aluminum & 900 & 24.3 \\
Copper & 385 & 24.4 \\
Gold & 130 & 25.6 \\
Steel/Iron & 450 & 25.0 \\
Lead & 130 & 26.8 \\
Mercury & 140 & 28.0 \\
Water & \multicolumn{1}{>{\columncolor{mycyan}}l}{4190} & 75.4 \\
Ice ($-$10 \textcelsius) & 2100 & 38 \\
\bottomrule
\end{tabular}
\setlength{\extrarowheight}{2mm}
\begin{tabular}{|l|c|c|c|c|c|c|c|}
\hline
Sydney & OG4G &Thu Oct 10 &Mon Oct 21 or 28 &11 or 18 days &999\\
\rowcolor[gray]{0.5}
& &Thu Oct 17 &Mon Oct 21 or 28 & 4 or 11 days &999\\
&OG7A &Sun Oct 13 &Mon Oct 21 or 28 & 8 or 15 days &999\\
\rowcolor[gray]{0.5}
& &Sun Oct 20 &Mon Oct 28 & 8 days &999\\
\hline
\end{tabular}
\setlength{\extrarowheight}{2mm}
\setlength{\tabcolsep}{2mm}
\begin{tabular}{|l|%
>{\columncolor{yellow}}c|c|>{\columncolor{yellow}}c|c|%
>{\columncolor{red}\bfseries}c<{\textsc{GBP}}|}
\hline
\multicolumn{3}{>{\columncolor{red}}l}{\color{white}\textsf{LONDON}}
&\multicolumn{3}{>{\columncolor{red}}r}{\color{white}\textsf{Price}}
\\[1pt]
\hline
Sydney & OG4G &Thu Oct 10 &Mon Oct 21 or 28 &11 or 18 days &999\\
& &Thu Oct 17 &Mon Oct 21 or 28 & 4 or 11 days &999\\
& OG7A &Sun Oct 13 &Mon Oct 21 or 28 & 8 or 15 days &999\\
& &Sun Oct 20 &Mon Oct 28 & 8 days &999\\
\hline
\end{tabular}
\setlength{\arrayrulewidth}{2pt}
\arrayrulecolor{green}
\begin{tabular}{|l|c|r|}
\arrayrulecolor{black}\hline
United Kingdom & London & Thames\\
\arrayrulecolor{blue}\hline
France & Paris & Seine \\
\arrayrulecolor{black}\cline{1-1}
\arrayrulecolor{red}\cline{2-3}
Russia & Moscow & Moskva \\ \hline
\end{tabular}
\end{document}

[转] http://blog.sina.com.cn/s/blog_5e16f1770100mvrx.html

免责声明:文章转载自《LaTeX表格tabular背景色添加技巧 [转]》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇解决ubuntu下字体模糊的问题Win10阻止电脑关机时弹出正在关闭应用的方法及恢复下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

latex插入编号{itemize}和{enumerate}

{itemize}命令 {itemize}命令对文本进行简单的排列,不是采用序号,而是实心圆点符号。这个命令需要和item配合使用。作为演示,输入如下代码;编译后可以看出在每一段前都加上了实心圆点符号进行排列。 如果我们不想使用实心圆点符号进行排列的话可以在item[]的中括号里面指定需要的编号符号。例如我们使用-进行编号,改变代码如下;编译输出后可以看到...

Latex插入代码程序+边框+颜色+汇编代码 [转]

listings 是专用于代码排版的 LaTeX宏包,可对关键词、注释和字符串等使用不同的字体和颜色或颜色,也可以为代码添加边框、背景等风格。 1 基本用法 下面给出一份用于排版 C 语言 HelloWorld 程序代码的完整的 LaTeX 文档: \documentclass{article}\usepackage{listings}\begin{do...

visio画图如何插入到latex中

一、 如果是使用matlab绘制的图片,那么在图片的格式修改好之后,选择另存为,在选择.eps格式就直接存储成.eps格式的文件了。我使用的字体和label font都是20,太小的话在转换后的文章中看起来不清楚。 二、 如果是用visio画的流程图等图片,转换成.eps需要以下步骤。 1)将visio图画好之后,在‘文件’中选择‘打印’,然后在‘打印机名...

由Excel表格导出Latex代码

Latex提供了不少绘制表格的宏包(参见:http://tug.org/pracjourn/2007-1/mori/),但在latex里画表并不直观,特别是在表格比较大的时候,有时候也需要先用Excel等软件先对数据稍作处理,因而经常需要将Excel等表格转化成Latex代码。而Excel插件excel2latex就能实现这一功能。 excel2latex...

在Latex使用條列式清單itemize , enumerate , description [转]

[另] Enumerate 修改间距 http://blog.sina.com.cn/s/blog_5e16f1770100g5ox.html [另] \renewcommand\labelenumi{[\theenumi]} 调用enumerate时候编号就会添加方括号. 在latex中有三種條列式方法 itemize 、 enumerate...

[转载]Matlab有用的小工具小技巧

原文地址:Matlab有用的小工具小技巧作者:felonwan 本文随时更新,欢迎转载,注明出处,谢谢合作。 本文内容基本上都经过笔者自身使用,结合经验及思考使用Matlab作图更为方便。记录下来,一是方便自己,二也为方便网友,欢迎多留言交流。 目录: 1.使图形窗口的默认text解释器为latex 2.图形窗口最大化 3.双坐标 4.计时...