一篇文章讲明白LaTeX表格tabular背景色添加技巧【转】

简介: 一篇文章讲明白LaTeX表格tabular背景色添加技巧【转】

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

\columncolor【色系】{色名}【左伸出】【右伸出】。

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

colortbl 的主要命令

命令

作用

\columncolor

让整个字段着色

\rowcolor

整个横列着色

\arrayrulecolor{颜色}

指定线条的颜色

\doublerulesepcolor{颜色}

指定双线内间隔的颜色

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

\columncolor【颜色模型】{颜色}【左伸出长度】【右伸出长度】

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

示例代码如下:

\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)}//代码效果参考:http://www.ezhiqi.com/bx/art_1067.html

\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}//代码效果参考:http://www.ezhiqi.com/zx/art_4646.html 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}

【转】

相关文章
|
数据库
【latex】在Overleaf的IEEE会议模板中,快速插入参考文献
【latex】在Overleaf的IEEE会议模板中,快速插入参考文献
3270 1
|
算法 数据库 计算机视觉
Dataset之COCO数据集:COCO数据集的简介、下载、使用方法之详细攻略
Dataset之COCO数据集:COCO数据集的简介、下载、使用方法之详细攻略
Latex更改字体颜色以及快速生成 SCI 论文的 revised version 和 pure version
Latex更改字体颜色以及快速生成 SCI 论文的 revised version 和 pure version
Latex更改字体颜色以及快速生成 SCI 论文的 revised version 和 pure version
conda常用操作和配置镜像源
conda常用操作和配置镜像源
30486 0
CCF推荐A类会议和期刊总结:计算机体系结构/并行与分布计算/存储系统领域
中国计算机学会(CCF)2022年版推荐目录涵盖了计算机体系结构、并行与分布计算、存储系统领域的多个A类会议和期刊。本文汇总了这些顶级资源的全称、出版社、dblp网址及领域。包括《ACM计算机系统汇刊》、《ACM存储汇刊》等期刊,以及ACM PPoPP、USENIX FAST等会议,为研究人员提供了重要学术参考。
13281 64
CCF推荐A类会议和期刊总结:计算机体系结构/并行与分布计算/存储系统领域
|
11月前
|
人工智能 IDE 程序员
GitHub Copilot 免费了!程序员们的福音来了!
《GitHub Copilot 免费了!程序员们的福音来了!》 近日,GitHub 宣布其 AI 编程助手 GitHub Copilot 现在可以免费使用。曾经每月需支付 10 美元订阅费的 Copilot,现在向所有人开放免费版本,这对个人开发者、初学者和小型团队来说是个大好消息。免费版支持 GPT 和 Claude 模型,并提供每月 2000 次代码补全和 50 条聊天消息等核心功能。用户只需注册或登录 GitHub 账户,在 VS Code 中安装扩展并激活免费版即可使用。此外,Visual Studio Code 也完全免费,进一步降低了开发门槛。 除了
11759 7
GitHub Copilot 免费了!程序员们的福音来了!
|
12月前
|
并行计算 前端开发 物联网
全网首发!真·从0到1!万字长文带你入门Qwen2.5-Coder——介绍、体验、本地部署及简单微调
2024年11月12日,阿里云通义大模型团队正式开源通义千问代码模型全系列,包括6款Qwen2.5-Coder模型,每个规模包含Base和Instruct两个版本。其中32B尺寸的旗舰代码模型在多项基准评测中取得开源最佳成绩,成为全球最强开源代码模型,多项关键能力超越GPT-4o。Qwen2.5-Coder具备强大、多样和实用等优点,通过持续训练,结合源代码、文本代码混合数据及合成数据,显著提升了代码生成、推理和修复等核心任务的性能。此外,该模型还支持多种编程语言,并在人类偏好对齐方面表现出色。本文为周周的奇妙编程原创,阿里云社区首发,未经同意不得转载。
29363 18
|
Web App开发 存储 前端开发
【4万字长文吐血整理】LaTeX基础使用【助你熟练玩转LaTeX】
【4万字长文吐血整理】LaTeX基础使用【助你熟练玩转LaTeX】
|
弹性计算 前端开发 Java
通义千问API:让大模型写代码和跑代码
基于前面三章的铺垫,本章我们将展示大模型Agent的强大能力。我们不仅要实现让大模型同时使用多种查询工具,还要实现让大模型能查询天气情况,最后让大模型自己写代码来查询天气情况。
通义千问API:让大模型写代码和跑代码