我使用 LaTeX 表格环境创建了一个时间表,我想在一些空单元格中添加对角线条,如下图所示:
这是我想要的模式:
我该怎么做?下面是我用来生成表格的代码:
\documentclass[landscape,a4paper]{article}
\usepackage{graphicx,caption,multirow}
\usepackage[top=0.5cm,bottom=3.8cm,right=2cm,left=2cm]{geometry}
\usepackage[table]{xcolor}
\captionsetup{labelformat=empty}
\begin{document}
\begin{table}[ht]
\large
\centering
\caption{{\Large 08/01/2024 $\rightarrow$ 13/01/2024}}
\resizebox{0.8\textwidth}{!}{
\setlength{\tabcolsep}{10pt}
\renewcommand{\arraystretch}{2.5}
\begin{tabular}{|>{\columncolor{cyan!30}}l|c|c|c|c|c|}
\cline{2-6}
\multicolumn{1}{c|}{} & \cellcolor{cyan!30}8:30-10:30 & \cellcolor{cyan!30}10:30-12:30 & \cellcolor{cyan!30}12:30-14:30 & \cellcolor{cyan!30}14:30-16:30 & \cellcolor{cyan!30}16:30-18:30 \\ \hline
Lundi & & & & & \\ \hline
Mardi & & & & & \\ \hline
Mercredi & & & & & \cellcolor{red!30}\parbox[c]{3cm}{Droit\\{\small Ms Y}} \\ \hline
Jeudi & & & & & \\ \hline
Vendredi & & & & & \\ \hline
Samedi & & & & \cellcolor{red!30}\parbox[c]{3cm}{Informatique\\{\small Mr X}} & \\ \hline
\end{tabular}}
\end{table}
\end{document}
答案1
使用{NiceTabular}
和nicematrix
TikZ 来绘制图案。
\documentclass[landscape,a4paper]{article}
\usepackage{graphicx,caption}
\usepackage[top=0.5cm,bottom=3.8cm,right=2cm,left=2cm]{geometry}
\usepackage{xcolor}
\captionsetup{labelformat=empty}
\usepackage{nicematrix}
\usepackage{tikz}
\usetikzlibrary{patterns}
\newcommand{\MyBlock}{\Block[transparent,tikz={pattern = north west lines, pattern color = red}]}
\begin{document}
\begin{table}[ht]
\large
\centering
\caption{{\Large 08/01/2024 $\rightarrow$ 13/01/2024}}
\renewcommand{\arraystretch}{2.5}
\begin{NiceTabular}{|>{\columncolor{cyan!30}}X[l]X[c]X[c]X[c]X[c]X[c]}[hvlines,color-inside,width=0.8\textwidth]
\rowcolor{cyan!30}
& 8:30-10:30 & 10:30-12:30 & 12:30-14:30 & 14:30-16:30 & 16:30-18:30 \\
Lundi & & & \MyBlock{*-1}{} \\
Mardi & & & & & \\
Mercredi & & & & \MyBlock{}{} & \Block[fill=red!30]{}{Droit\\ \small Ms Y} \\
Jeudi & & & & & \\
Vendredi & & & & & \\
Samedi & & & & \Block[fill=red!30]{}{Informatique\\ \small Mr X} & \MyBlock{}{}\\
\end{NiceTabular}
\end{table}
\end{document}
您需要进行多次编译(因为nicematrix
在后台使用了 PGF/TikZ 节点)。
这是在西北位置有一个空角的版本(西北corners
)。的键nicematrix
是为该任务设计的,但由于技术原因,它不适用于 类型的单元格。这就是为什么我对第一列X
使用了 列类型。l
\documentclass[landscape,a4paper]{article}
\usepackage{graphicx,caption}
\usepackage[top=0.5cm,bottom=3.8cm,right=2cm,left=2cm]{geometry}
\usepackage{xcolor}
\captionsetup{labelformat=empty}
\usepackage{nicematrix}
\usepackage{tikz}
\usetikzlibrary{patterns}
\newcommand{\MyBlock}{\Block[transparent,tikz={pattern = north west lines, pattern color = red}]}
\begin{document}
\begin{table}[ht]
\large
\centering
\caption{{\Large 08/01/2024 $\rightarrow$ 13/01/2024}}
\renewcommand{\arraystretch}{2.5}
\begin{NiceTabular}{|>{\columncolor{cyan!30}}lX[c]X[c]X[c]X[c]X[c]}[hvlines,corners=NW,color-inside,width=0.8\textwidth]
\rowcolor{cyan!30}
& 8:30-10:30 & 10:30-12:30 & 12:30-14:30 & 14:30-16:30 & 16:30-18:30 \\
Lundi & & & \MyBlock{*-1}{} \\
Mardi & & & & & \\
Mercredi & & & & \MyBlock{}{} & \Block[fill=red!30]{}{Droit\\ \small Ms Y} \\
Jeudi & & & & & \\
Vendredi & & & & & \\
Samedi & & & & \Block[fill=red!30]{}{Informatique\\ \small Mr X} & \MyBlock{}{}\\
\end{NiceTabular}
\end{table}
\end{document}