我想制定一个课程表。
我写了下面的内容,部分内容改编自别人给出的示例。
\documentclass[9pt]{extarticle}
\RequirePackage{scrextend}
\changefontsizes[11.5pt]{9.5pt}
\usepackage{ctex}
\setmainfont{Linux Libertine O}
\setsansfont{Linux Biolinum O}
\usepackage{makecell}
\usepackage{diagbox}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage[margin=1cm,a4paper]{geometry}
\usepackage{graphicx}
\setlength{\parindent}{0pt}
\usepackage{ulem}
\title{xxx}
\author{xx}
\date{2022}
\makeatletter
\renewcommand{\maketitle}{
{\centering\sffamily\large\@date\hfil\@title\hfil\@author\par}
\vskip1ex}
\makeatother
\newcommand{\timeslot}[2]{\makecell*{#1\\#2}}
\newcommand{\class}[3][]{\makecell{#2\\[-1ex]{\hfill\scriptsize#3}}}
\pagestyle{empty}
\newcommand\Mandarin{\class{xx}{xxx}}
\newcommand\MandarinX{\class{xx}{xxx}}
\newcommand\Mathematics{\class{xx}{xxx}}
\newcommand\MathematicsX{\class{xx}{xxx}}
\newcommand\English{\class{xx}{xx}}
\newcommand\EnglishX{\class{xx}{xxx}}
\newcommand\Physics{\class{xx}{xxx}}
\newcommand\PhysicsX{\class{xx}{xxx}}
\newcommand\PhysicsXX{\class{xx}{xxx}}
\newcommand\Chemistry{\class{xx}{xxx}}
\newcommand\ChemistryX{\class{xx}{xxx}}
\newcommand\Geography{\class{xx}{xxx}}
\newcommand\PhysEd{\class{xx}{xxx}}
\newcommand\PhysEdX{\class{xx}{xxx}}
\newcommand\Society{\class{xx}{xxx}}
\newcommand\Labour{\class{xx}{xxx}}
\newcommand\History{\class{xx}{xxx}}
\newcommand\Politics{\class{xx}{xxx}}
\newcommand\Psychology{\class{xx}{xxx}}
\newcommand\Art{\class{xx}{xxx}}
\newcommand\Biology{\class{xx}{xxx}}
\newcommand\Assembly{\class{xx}{xxx}}
\newcommand\IT{\class{xx}{xxx}}
\newcommand\Recess{\multirow{7}{*}[-2.75ex]{\makecell{x\\x\\[1em]B\\R\\E\\A\\K}}}
\newcommand{\Cline}[2]{%
\noalign{\global\setlength{\Oldarrayrulewidth}{\arrayrulewidth}}%
\noalign{\global\setlength{\arrayrulewidth}{#1}}\cline{#2}%
\noalign{\global\setlength{\arrayrulewidth}{\Oldarrayrulewidth}}}
\begin{document}
\newsavebox{\HNtimetable}
\savebox{\HNtimetable}{\parbox{\textwidth}{
\maketitle
\centering
\begin{tabular}{!{\vrule width1.2pt}c!{\vrule width1.2pt}c|c|c|c!{\vrule width1.2pt}c!{\vrule width1.2pt}c|c|c|c|c|c!{\vrule width1.2pt}}
\Xhline{1.2pt}
Lesson & 1 & 2 & 3 & 4 && 5 & 6 & 7 & 8 & 9 & 10 \\
\Cline{0.8pt}{1-5}
\Cline{0.8pt}{7-12}
\diagbox{\footnotesize x}{\footnotesize x}
&
\timeslot{08:00}{08:40} &
\timeslot{08:50}{09:30} &
\timeslot{09:45}{10:25} &
\timeslot{10:35}{11:15} &
\Recess &
\timeslot{12:40}{13:20} &
\timeslot{13:30}{14:10} &
\timeslot{14:25}{15:05} &
\timeslot{15:15}{15:55} &
\timeslot{16:05}{16:45} &
\timeslot{16:55}{17:35} \\
\Cline{1.2pt}{1-5}
\Cline{1.2pt}{7-12}
Mon &
\Mathematics &
\Mandarin &
\Chemistry &
\PhysEd &
&
\EnglishX &
\Biology &
\Physics &
\PhysicsXX &
\Society &
&
\\
\cline{1-5}
\cline{7-12}
Tue &
\EnglishX &
\Geography &
\Mathematics &
\Labour &
&
\History &
\Art &
\Politics &
\Mandarin &
&
&
\\
\cline{1-5}
\cline{7-12}
Wed &
\Mathematics&
\Chemistry &
\English &
\Psychology &
&
\Mandarin &
\PhysEdX &
\PhysEdX &
\Biology &
\Physics &
&
&
\\
\cline{1-5}
\cline{7-12}
Thu &
\IT &
\IT &
\MandarinX &
\English &
&
\PhysEd &
\Geography &
\Mathematics &
\Labour &
&
&
\\
\cline{1-5}
\cline{7-12}
Fri &
\PhysicsX &
\History &
\MathematicsX &
\ChemistryX &
&
\Politics &
\English &
\MandarinX &
\Assembly &
&
&
\\
\Xhline{1.2pt}
\end{tabular}
}}
\noindent\usebox{\HNtimetable}
\end{document}
但是,当我对其进行个性化设置时,出现了一些问题,导致表单不太完美。我建议您在 OverLeaf 上运行此代码,因为它会引发一些异常,而 OverLeaf 可以处理它们。
现在我想改进3个方面:
- 如你所见,桌子的最后几行有很大裂缝。你该如何修复它们?
- 我使用了
diagbox
,但它与框架的顶角并不完美贴合。 - 我使用的 Cline 命令效果不太好。尽管我传入了参数,但它无法自定义线条的粗细。
答案1
这是一个{NiceTabular}
使用 的解决方案nicematrix
。
该环境为经典的 添加了功能{tabular}
。特别是,您可以使用内置命令 水平和垂直合并单元格\Block
。使用键hvlines
,除块(由 创建)外,所有规则均会绘制\Block
。这就是我在以下代码中使用的。
对于繁重的规则,我在构建数组后使用 Tikz 绘制了它们。实际上,nicematrix
在数组的行、列和单元格下创建了 PGF/Tikz 节点。在构建表格后,可以使用这些节点和 Tikz 绘制您想要的任何规则。
这就是我所做的
\tikz \draw [very thick] (1-|1) rectangle (last-|last)
(1-|6) -- (last-|6)
(1-|7) -- (last-|7) ;
最终,环境{NiceTabular}
有其内置命令\diagbox
,它总是给出完美的结果(因为对角线规则是用 Tikz 绘制的)。
\documentclass[9pt]{extarticle}
\usepackage{scrextend}
\usepackage[margin=1cm,a4paper]{geometry}
\changefontsizes[11.5pt]{9.5pt}
\usepackage{nicematrix,tikz}
\usepackage{makecell}
\setlength{\parindent}{0pt}
\newcommand{\timeslot}[2]{\makecell{#1\\#2}}
\newcommand{\class}[3][]{\makecell{#2\\[-1ex]{\hfill\scriptsize#3}}}
\pagestyle{empty}
\begin{document}
\newcommand\Mandarin{\class{xx}{xxx}}
\newcommand\MandarinX{\class{xx}{xxx}}
\newcommand\Mathematics{\class{xx}{xxx}}
\newcommand\MathematicsX{\class{xx}{xxx}}
\newcommand\English{\class{xx}{xx}}
\newcommand\EnglishX{\class{xx}{xxx}}
\newcommand\Physics{\class{xx}{xxx}}
\newcommand\PhysicsX{\class{xx}{xxx}}
\newcommand\PhysicsXX{\class{xx}{xxx}}
\newcommand\Chemistry{\class{xx}{xxx}}
\newcommand\ChemistryX{\class{xx}{xxx}}
\newcommand\Geography{\class{xx}{xxx}}
\newcommand\PhysEd{\class{xx}{xxx}}
\newcommand\PhysEdX{\class{xx}{xxx}}
\newcommand\Society{\class{xx}{xxx}}
\newcommand\Labour{\class{xx}{xxx}}
\newcommand\History{\class{xx}{xxx}}
\newcommand\Politics{\class{xx}{xxx}}
\newcommand\Psychology{\class{xx}{xxx}}
\newcommand\Art{\class{xx}{xxx}}
\newcommand\Biology{\class{xx}{xxx}}
\newcommand\Assembly{\class{xx}{xxx}}
\newcommand\IT{\class{xx}{xxx}}
\begin{table}
\centering
\begin{NiceTabular}{cccccccccccc}[hvlines]
Lesson & 1 & 2 & 3 & 4 & \Block{*-1}{x\\x\\ \\ B\\R\\E\\A\\K} & 5 & 6 & 7 & 8 & 9 & 10 \\
\diagbox{\footnotesize\; x\strut}{\footnotesize x\strut\;}
&
\timeslot{08:00}{08:40} &
\timeslot{08:50}{09:30} &
\timeslot{09:45}{10:25} &
\timeslot{10:35}{11:15} & &
\timeslot{12:40}{13:20} &
\timeslot{13:30}{14:10} &
\timeslot{14:25}{15:05} &
\timeslot{15:15}{15:55} &
\timeslot{16:05}{16:45} &
\timeslot{16:55}{17:35} \\
Mon &
\Mathematics &
\Mandarin &
\Chemistry &
\PhysEd &
&
\EnglishX &
\Biology &
\Physics &
\PhysicsXX &
\Society &
\\
Tue &
\EnglishX &
\Geography &
\Mathematics &
\Labour &
&
\History &
\Art &
\Politics &
\Mandarin &
&
\\
Wed &
\Mathematics&
\Chemistry &
\English &
\Psychology &
&
\Mandarin &
\PhysEdX &
\PhysEdX &
\Biology &
\Physics &
\\
Thu &
\IT &
\IT &
\MandarinX &
\English &
&
\PhysEd &
\Geography &
\Mathematics &
\Labour &
&
\\
Fri &
\PhysicsX &
\History &
\MathematicsX &
\ChemistryX &
&
\Politics &
\English &
\MandarinX &
\Assembly &
&
\\
\CodeAfter
\tikz \draw [very thick] (1-|1) rectangle (last-|last)
(1-|6) -- (last-|6)
(1-|7) -- (last-|7) ;
\end{NiceTabular}
\end{table}
\end{document}
由于使用了 PGF/Tikz 节点,因此您需要进行多次编译nicematrix
。
答案2
- 你必须定义
\newlength{\Oldarrayrulewidth}
- 有几行
&
多了一两行。
这是更正后的版本
\documentclass[9pt]{extarticle}
\RequirePackage{scrextend}
\changefontsizes[11.5pt]{9.5pt}
\usepackage{ctex}
\setmainfont{Linux Libertine O}
\setsansfont{Linux Biolinum O}
\usepackage{makecell}
\usepackage{diagbox}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage[margin=1cm,a4paper]{geometry}
\usepackage{graphicx}
\setlength{\parindent}{0pt}
\usepackage{ulem}
\title{xxx}
\author{xx}
\date{2022}
\makeatletter
\renewcommand{\maketitle}{
{\centering\sffamily\large\@date\hfil\@title\hfil\@author\par}
\vskip1ex}
\makeatother
\newcommand{\timeslot}[2]{\makecell*{#1\\#2}}
\newcommand{\class}[3][]{\makecell{#2\\[-1ex]{\hfill\scriptsize#3}}}
\pagestyle{empty}
\newcommand\Mandarin{\class{xx}{xxx}}
\newcommand\MandarinX{\class{xx}{xxx}}
\newcommand\Mathematics{\class{xx}{xxx}}
\newcommand\MathematicsX{\class{xx}{xxx}}
\newcommand\English{\class{xx}{xx}}
\newcommand\EnglishX{\class{xx}{xxx}}
\newcommand\Physics{\class{xx}{xxx}}
\newcommand\PhysicsX{\class{xx}{xxx}}
\newcommand\PhysicsXX{\class{xx}{xxx}}
\newcommand\Chemistry{\class{xx}{xxx}}
\newcommand\ChemistryX{\class{xx}{xxx}}
\newcommand\Geography{\class{xx}{xxx}}
\newcommand\PhysEd{\class{xx}{xxx}}
\newcommand\PhysEdX{\class{xx}{xxx}}
\newcommand\Society{\class{xx}{xxx}}
\newcommand\Labour{\class{xx}{xxx}}
\newcommand\History{\class{xx}{xxx}}
\newcommand\Politics{\class{xx}{xxx}}
\newcommand\Psychology{\class{xx}{xxx}}
\newcommand\Art{\class{xx}{xxx}}
\newcommand\Biology{\class{xx}{xxx}}
\newcommand\Assembly{\class{xx}{xxx}}
\newcommand\IT{\class{xx}{xxx}}
\newcommand\Recess{\multirow{7}{*}[-2.75ex]{\makecell{x\\x\\[1em]B\\R\\E\\A\\K}}}
\newlength{\Oldarrayrulewidth}% <<<<<<<<<<<<<<<<
\newcommand{\Cline}[2]{%
\noalign{\global\setlength{\Oldarrayrulewidth}{\arrayrulewidth}}%
\noalign{\global\setlength{\arrayrulewidth}{#1}}\cline{#2}%
\noalign{\global\setlength{\arrayrulewidth}{\Oldarrayrulewidth}}}
\begin{document}
\newsavebox{\HNtimetable}
\savebox{\HNtimetable}{\parbox{\textwidth}{
\maketitle
\centering
\begin{tabular}{!{\vrule width1.2pt}c!{\vrule width1.2pt}c|c|c|c!{\vrule width1.2pt}c!{\vrule width1.2pt}c|c|c|c|c|c!{\vrule width1.2pt}}
\Xhline{1.2pt}
Lesson & 1 & 2 & 3 & 4 && 5 & 6 & 7 & 8 & 9 & 10 \\
\Cline{0.8pt}{1-5}
\Cline{0.8pt}{7-12}
\diagbox{\footnotesize x}{\footnotesize x}
&
\timeslot{08:00}{08:40} &
\timeslot{08:50}{09:30} &
\timeslot{09:45}{10:25} &
\timeslot{10:35}{11:15} &
\Recess &
\timeslot{12:40}{13:20} &
\timeslot{13:30}{14:10} &
\timeslot{14:25}{15:05} &
\timeslot{15:15}{15:55} &
\timeslot{16:05}{16:45} &
\timeslot{16:55}{17:35} \\
\Cline{1.2pt}{1-5}
\Cline{1.2pt}{7-12}
Mon &
\Mathematics &
\Mandarin &
\Chemistry &
\PhysEd &
&
\EnglishX &
\Biology &
\Physics &
\PhysicsXX &
\Society &
\\
\cline{1-5}
\cline{7-12}
Tue &
\EnglishX &
\Geography &
\Mathematics &
\Labour &
&
\History &
\Art &
\Politics &
\Mandarin &
&
\\
\cline{1-5}
\cline{7-12}
Wed &
\Mathematics&
\Chemistry &
\English &
\Psychology &
&
\Mandarin &
\PhysEdX &
\PhysEdX &
\Biology &
\Physics &
\\
\cline{1-5}
\cline{7-12}
Thu &
\IT &
\IT &
\MandarinX &
\English &
&
\PhysEd &
\Geography &
\Mathematics &
\Labour &
&
\\
\cline{1-5}
\cline{7-12}
Fri &
\PhysicsX &
\History &
\MathematicsX &
\ChemistryX &
&
\Politics &
\English &
\MandarinX &
\Assembly &
&
\\
\Xhline{1.2pt}
\end{tabular}
}}
\noindent\usebox{\HNtimetable}
\end{document}