本文介紹如何設置表格的行、列與單元格顏色,以及如何設置表格線的粗細與顏色。設置方法直接看代碼就明白了,不再贅述。
操作系統:Ubuntu 18.04
編輯工具:TeXstudio 2.12.6
編譯方式:LuaLaTeX
% 開源中國,陸巍
\documentclass{article}%
%
\usepackage{ctex}% 中文支持
\usepackage{geometry}% 用於頁面設置
\usepackage[english]{babel}% 載入美式英語斷字模板
\usepackage[dvipsnames, svgnames, x11names]{xcolor}% 顏色支持
\usepackage{colortbl}% 表格顏色支持
% 設置爲A4紙,並設置邊距
\geometry
{
a4paper,%
left = 3.17cm,%
right = 3.17cm,%
top = 2.54cm,%
bottom = 2.54cm%
}%
\setlength{\parindent}{0em}% 縮進爲0
%
\setmainfont{Ubuntu Mono}% 設置全局英文字體
% ------------------ 開始 -------------------
%
\begin{document}
\Large 表格顏色與表格線設置示例\\\normalsize
\begin{tabular}{p{3cm}!{\color{white}\vrule width 3pt}p{12cm}}
\rowcolor{black}\textcolor{white}{\textbf{Goal}} & \textcolor{white}{\textbf{Explanation}}\\
\noalign{{\color{white}\hrule height 5pt}}
\rowcolor{LightGray}Reusability & Frameworks and adaptations readily reusable\\
\noalign{{\color{white}\hrule height 3pt}}
\rowcolor{WhiteSmoke}Modularity & Decoupled and easy to reassemble\\
\noalign{{\color{white}\hrule height 3pt}}
\rowcolor{LightGray}Testability & Components easily isolated for testing\\
\noalign{{\color{white}\hrule height 3pt}}
\rowcolor{WhiteSmoke}Adaptability & Should be adaptable to new contexts and bridge to inherited\\
\noalign{{\color{white}\hrule height 3pt}}
\rowcolor{LightGray}Portability & Should be portable to new architectures and platforms\\
\noalign{{\color{white}\hrule height 3pt}}
\rowcolor{WhiteSmoke}Usability & Should be easily understood and used by customers\\
\noalign{{\color{white}\hrule height 3pt}}
\rowcolor{LightGray}Configurability & \textcolor{red}{Facilities in the architecture should be scalable and configurable}\\
\noalign{{\color{white}\hrule height 3pt}}
\rowcolor{WhiteSmoke}Performance &\cellcolor{green} Architecture should perform well in resource constrained contexts. Should be very compact.
\end{tabular}
\end{document}
效果如下:
注意事項:
- 這裏需要colortbl宏包支持表格顏色設置;
- 使用非基礎顏色名稱需要載入相關顏色庫,即\usepackage[dvipsnames, svgnames, x11names]{xcolor}