LaTeX表格tabular背景色添加技巧
2014-03-02 00:00
1906 查看
摘要: LaTeX表格tabular背景色添加技巧
我们所用的宏包为colortbl,这个宏包可以设置表格中数据、文本、行、列、单元格前景和背景以及边框的颜色,从而得到彩色表格。同时需要 array 和 color 两个宏包的支持。 宏包提供了一组着色命令,经常用到是列着色命令,其格式为:
\columncolor[色系]{色名}[左伸出][右伸出]。
常用色系有三原色 rgb 灰度 gray 和四色cmyk三种;被预定义的色名有68个,详见 color 宏包介绍中所附的色标;左右伸出的长度单位可用 pt。
colortbl 的主要命令
在这里,\columncolor 和 \rowcolor 的参数是一样的,他们的共同语法是:
\columncolor[颜色模型]{颜色}[左伸出长度][右伸出长度]
我们现在就来看个实例,这里头有些例子,包括:灰阶横条、部份字段着色、整个表格在着色背景及单一个表格内方框着色:
示例代码如下:
\documentclass[16px]{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=0
\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=16px
\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}}
\\[1px]
\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}{3px}
\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}
我们所用的宏包为colortbl,这个宏包可以设置表格中数据、文本、行、列、单元格前景和背景以及边框的颜色,从而得到彩色表格。同时需要 array 和 color 两个宏包的支持。 宏包提供了一组着色命令,经常用到是列着色命令,其格式为:
\columncolor[色系]{色名}[左伸出][右伸出]。
常用色系有三原色 rgb 灰度 gray 和四色cmyk三种;被预定义的色名有68个,详见 color 宏包介绍中所附的色标;左右伸出的长度单位可用 pt。
colortbl 的主要命令
命令 | 作用 |
\columncolor | 让整个字段着色 |
\rowcolor | 整个横列着色 |
\arrayrulecolor{颜色} | 指定线条的颜色 |
\doublerulesepcolor{颜色} | 指定双线内间隔的颜色 |
\columncolor[颜色模型]{颜色}[左伸出长度][右伸出长度]
我们现在就来看个实例,这里头有些例子,包括:灰阶横条、部份字段着色、整个表格在着色背景及单一个表格内方框着色:
示例代码如下:
\documentclass[16px]{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=0
\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=16px
\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}}
\\[1px]
\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}{3px}
\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}
相关文章推荐
- LaTeX表格tabular背景色添加技巧 [转]
- LaTeX技巧005:改变文字的前景色和背景色
- LaTeX技巧374:如何在指定列宽的表格里实现文字居中
- LaTeX技巧572:如何给表格项添加注释?
- latex 表格“tabular”跨多行笔记
- LaTeX技巧572:如何给表格项添加注释?
- LaTeX技巧6:Excel2LaTeX表格处理软件图解教程
- {Latex}{Tabular}文本超出表格自动换行
- LaTex技巧二:如何搭配出好看的表格?
- latex表格线的颜色设置(边框添加颜色)
- LaTeX技巧015:设置表格的宽度和高度
- 给表格隔行添加背景色
- Latex 表格图片公式跨双栏显示并使标题居中以及表格图片注释技巧
- SSRS 实用技巧 ---- 为表格添加展开/折叠操作(明细报表)
- latex表格线的颜色设置(边框添加颜色)
- LaTex使用技巧1:添加参考文献、PDF图片
- latex如何给表格添加注释
- LaTex使用技巧2:添加中文支持
- LaTex技巧(五):如何在图形的右方插入统计表格呢?
- Latex 表格技巧 - 合并单元格