为表格中的行和列分别着色

为表格中的行和列分别着色

我们可以构建一个表格:

\begin{table*}[t]
\[
\begin{array}{@{} l *{9}{c} @{}}
\toprule
m & \multicolumn{2}{c}{J^*(m)}     & t^*(m)
& \multicolumn{2}{c}{J^{**}(m)}  & t^{**}(m)
& \multicolumn{2}{c}{J^{***}(m)} & t^{***}(m) \\
\cmidrule(lr){2-3} \cmidrule(lr){5-6} \cmidrule(lr){8-9}
& 1-1/m & 1+1/m & m\pi
& 1-3/m & 1+3/m & m\pi
& 1-5/m & 1+5/m & m\pi \\
\midrule
1 & 0   & 2   &  \pi \\
2 & 1/2 & 3/2 & 2\pi \\
3 & 2/3 & 4/3 & 3\pi & 0   & 2   & 3\pi \\
4 & 3/4 & 5/4 & 4\pi & 1/4 & 7/4 & 4\pi \\
5 & 4/5 & 6/5 & 5\pi & 2/5 & 8/5 & 5\pi & 0 & 2 & 5\pi \\
6 & 5/6 & 7/6 & 6\pi & 3/6 & 9/6 & 6\pi & 1/6 & 11/6 & 6\pi \\
7 & 6/7 & 8/7 & 7\pi & 4/7 & 10/7 & 7\pi & 2/7 & 12/7 & 7\pi \\
\bottomrule
\end{array}
\]
\end{table*}

当然我认为我们需要

 \usepackage{framed}
 \usepackage{tabularx}
 \usepackage{multirow}
 \usepackage{framed}

我们通过绘制两条所需的垂直黑线来添加它们,但我们不知道如何插入它们!!!

此外,我们希望用绿色、蓝色和红色勾勒出表格中的一些行,如下所示,但不包括任何分隔的列。我们该怎么做呢?

在此处输入图片描述

答案1

以下是该表的三个版本:

  1. 带有彩色单元格背景

  2. 带颜色和垂直线 + 原始书本标签线

  3. 带有颜色和垂直线+hline

请注意,我已删除了表格@{}\begin{tabular}否则彩色背景会溢出到表格的左侧和右侧。还请注意,颜色和线条的组合会导致一些与“缺失”线条相关的查看器相关问题。在下面的屏幕截图中,某些行中的垂直线似乎缺失了。要查看这些线条,请进一步放大。

在此处输入图片描述

\documentclass{article}
\usepackage{geometry}
\usepackage[table,svgnames]{xcolor}
\usepackage{booktabs}
\newcommand{\cellg}{\cellcolor{LightGreen}}
\newcommand{\cellb}{\cellcolor{LightBlue}}
\newcommand{\cellr}{\cellcolor{LightPink}}

\begin{document}


\[
\begin{array}{ l *{9}{c} }
\toprule
m & \multicolumn{2}{c}{J^*(m)}     & t^*(m)
& \multicolumn{2}{c}{J^{**}(m)}  & t^{**}(m)
& \multicolumn{2}{c}{J^{***}(m)} & t^{***}(m) \\
\cmidrule(lr){2-3} \cmidrule(lr){5-6} \cmidrule(lr){8-9}
& 1-1/m & 1+1/m & m\pi
& 1-3/m & 1+3/m & m\pi
& 1-5/m & 1+5/m & m\pi \\
\midrule
\cellg 1 & \cellg 0   & \cellg 2   &  \cellg \pi \\
2 & 1/2 & 3/2 & 2\pi \\
\cellg 3 & \cellg 2/3 & \cellg 4/3 & \cellg 3\pi & \cellb 0   & \cellb 2   & \cellb 3\pi \\
4 & 3/4 & 5/4 & 4\pi & 1/4 & 7/4 & 4\pi \\
\cellg 5 & \cellg 4/5 & \cellg 6/5 & \cellg 5\pi & \cellb 2/5 & \cellb 8/5 & \cellb 5\pi & \cellr 0 & \cellr 2 & \cellr 5\pi \\
6 & 5/6 & 7/6 & 6\pi & 3/6 & 9/6 & 6\pi & 1/6 & 11/6 & 6\pi \\
\cellg 7 & \cellg 6/7 & \cellg 8/7 & \cellg 7\pi & \cellb 4/7 & \cellb 10/7 & \cellb 7\pi & \cellr 2/7 & \cellr 12/7 & \cellr 7\pi \\
\bottomrule
\end{array}
\]

\bigskip

\[
\begin{array}{ l *{3}{c}*{2}{|ccc} }
\toprule
m & \multicolumn{2}{c}{J^*(m)}     & t^*(m)
& \multicolumn{2}{c}{J^{**}(m)}  & t^{**}(m)
& \multicolumn{2}{c}{J^{***}(m)} & t^{***}(m) \\
\cmidrule(lr){2-3} \cmidrule(lr){5-6} \cmidrule(lr){8-9}
& 1-1/m & 1+1/m & m\pi
& 1-3/m & 1+3/m & m\pi
& 1-5/m & 1+5/m & m\pi \\
\midrule
\cellg 1 & \cellg 0   & \cellg 2   &  \cellg \pi & & & & & \\
2 & 1/2 & 3/2 & 2\pi & & & & & \\
\cellg 3 & \cellg 2/3 & \cellg 4/3 & \cellg 3\pi & \cellb 0   & \cellb 2   & \cellb 3\pi \\
4 & 3/4 & 5/4 & 4\pi & 1/4 & 7/4 & 4\pi \\
\cellg 5 & \cellg 4/5 & \cellg 6/5 & \cellg 5\pi & \cellb 2/5 & \cellb 8/5 & \cellb 5\pi & \cellr 0 & \cellr 2 & \cellr 5\pi \\
6 & 5/6 & 7/6 & 6\pi & 3/6 & 9/6 & 6\pi & 1/6 & 11/6 & 6\pi \\
\cellg 7 & \cellg 6/7 & \cellg 8/7 & \cellg 7\pi & \cellb 4/7 & \cellb 10/7 & \cellb 7\pi & \cellr 2/7 & \cellr 12/7 & \cellr 7\pi \\
\bottomrule
\end{array}
\]

\bigskip

\[
\begin{array}{ l *{3}{c}*{2}{|ccc} }
\hline
m & \multicolumn{2}{c}{J^*(m)}     & t^*(m)
& \multicolumn{2}{c}{J^{**}(m)}  & t^{**}(m)
& \multicolumn{2}{c}{J^{***}(m)} & t^{***}(m) \\
\cline{2-3} \cline{5-6} \cline{8-9}
& 1-1/m & 1+1/m & m\pi
& 1-3/m & 1+3/m & m\pi
& 1-5/m & 1+5/m & m\pi \\
\hline
\cellg 1 & \cellg 0   & \cellg 2   &  \cellg \pi & & & & & \\
2 & 1/2 & 3/2 & 2\pi & & & & & \\
\cellg 3 & \cellg 2/3 & \cellg 4/3 & \cellg 3\pi & \cellb 0   & \cellb 2   & \cellb 3\pi \\
4 & 3/4 & 5/4 & 4\pi & 1/4 & 7/4 & 4\pi \\
\cellg 5 & \cellg 4/5 & \cellg 6/5 & \cellg 5\pi & \cellb 2/5 & \cellb 8/5 & \cellb 5\pi & \cellr 0 & \cellr 2 & \cellr 5\pi \\
6 & 5/6 & 7/6 & 6\pi & 3/6 & 9/6 & 6\pi & 1/6 & 11/6 & 6\pi \\
\cellg 7 & \cellg 6/7 & \cellg 8/7 & \cellg 7\pi & \cellb 4/7 & \cellb 10/7 & \cellb 7\pi & \cellr 2/7 & \cellr 12/7 & \cellr 7\pi \\
\hline
\end{array}
\]




\end{document}

相关内容