请考虑以下示例:
\documentclass[
a4paper,
12pt,
landscape,
danish
]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage[
hmargin = 2.4cm,
vmargin = 3cm
]{geometry}
\usepackage{fancyhdr}
\usepackage{booktabs}
\newcommand*\mc[1]{\multicolumn{3}{c}{#1}}
\newcommand*\Alignment[1]{% Justering ved `--'.
\multicolumn{1}{r@{}}{\llap{\makebox[\widthof{--}][c]{#1}}}%
}
\def\mlrA{\hskip 2.5em}
\def\mlrB{\hskip 0.8em}
\def\mlrC{3ex}
\pagestyle{fancy}
\renewcommand*\headrulewidth{0pt}
\setlength\headheight{14.5pt}
\lhead{}
\rhead{}
\cfoot{}
\begin{document}
\begin{center}
\textbf{\Huge Skema for skoleåret 2015--2016}
\end{center}
\vspace{5ex}
\begin{table}[htbp]
\centering
\begin{tabular}{
c @{\mlrB}
r @{\,--\,}
l @{\mlrA}
l @{\mlrB}
l @{\mlrB}
l @{\mlrA}
l @{\mlrB}
l @{\mlrB}
l @{\mlrA}
l @{\mlrB}
l @{\mlrB}
l @{\mlrA}
l @{\mlrB}
l @{\mlrB}
l @{\mlrA}
l @{\mlrB}
l @{\mlrB}
l
}
\toprule
Lektion & \multicolumn{2}{l}{Tidspunkt} & \mc{Mandag}{\mlrA} & \mc{Tirsdag}{\mlrA} & \mc{Onsdag}{\mlrA} & \mc{Torsdag}{\mlrA} & \mc{Fredag}{\mlrA} \\
\midrule
1 & 8:10 & 8:55 & & & & 7.C & F/K & fys & 5.A & MAT & 09 & & & & 7.C & MAT & 22 \\[\mlrC]
2 & 8:55 & 9:40 & & & & 7.C & F/K & fys & 5.A & N/T & 09 & & & & 7.C & STU & 22 \\[\mlrC]
3 & 10:00 & 10:45 & 8. & IDR & hal/gym & 5.A & MAT & 09 & 7.C & STU & 22 & 7.C & BIO & bio & & & \\[\mlrC]
4 & 10:45 & 11:30 & 8. & IDR & hal/gym & 5.A & MAT & 09 & & & & 7.C & BIO & bio & & & \\[\mlrC]
5 & 11:30 & 12:00 & 5.A & FORD & 09 & 7.C & FORD & 22 & 5.A & FORD & 09 & & & & & & \\[\mlrC]
6 & 12:40 & 13:25 & 7.C & GEO & 22 & 5.A & HIS & 09 & 7.C & MAT & 22 & & & & & & \\[\mlrC]
7 & 13:25 & 14:10 & 7.C & GEO & 22 & 5.A & HIS & 09 & 7.C & MAT & 22 & & & & & & \\[\mlrC]
8 & 14:25 & 15:10 & 7.C & MAT & 22 & \mc{TEAM}{\mlrA} & & & & & & & & & \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
以下是我遇到的两个问题:
是否
Tidspunkt
正好位于时间间隔的中心?(我不确定。)我如何将
Fredag
最后三列置于中心而不是只将最后三列的前两列置于中心?
PS 如果有人有“更好”的表格输入方式,请随时提供您的建议。
更新
使用Heiko Oberdiek 的回答并稍微简化了代码,最终得到如下结果:
\documentclass[
a4paper,
12pt,
landscape,
danish
]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage[
hmargin = 2.4cm,
vmargin = 3cm
]{geometry}
\usepackage{fancyhdr}
\usepackage{booktabs}
\newcommand*\mc[1]{\multicolumn{3}{@{}c@{\mlrA}}{#1}}
\newcommand*\Alignment[1]{% adjustment at `--'
\multicolumn{1}{r@{}}{\llap{\makebox[\widthof{--}][c]{#1}}}%
}
\def\mlrA{\hskip 2.5em}
\def\mlrB{\hskip 0.8em}
\def\mlrC{3ex}
\pagestyle{fancy}
\renewcommand*\headrulewidth{0pt}
\setlength\headheight{14.5pt}
\lhead{}
\rhead{}
\cfoot{}
\begin{document}
\begin{center}
\textbf{\Huge Skema for skoleåret~2015--2016}
\vspace{10ex}
\renewcommand*\arraystretch{1.2}
\begin{tabular}{
c @{\mlrB}
r @{\,--\,}
*{5}{
l @{\mlrA}
l @{\mlrB}
l @{\mlrB}
}
l
}
\toprule
Lektion
& \multicolumn{2}{@{}c@{\mlrA}}{Tidspunkt}
& \mc{Mandag}
& \mc{Tirsdag}
& \mc{Onsdag}
& \mc{Torsdag}
& \multicolumn{3}{@{}c}{Fredag} \\
\midrule
1 & 8:10 & 8:55 & & & & 7.C & F/K & fys & 5.A & MAT & 09 & & & & 7.C & MAT & 22 \\[\mlrC]
2 & 8:55 & 9:40 & & & & 7.C & F/K & fys & 5.A & N/T & 09 & & & & 7.C & STU & 22 \\[\mlrC]
3 & 10:00 & 10:45 & 8. & IDR & hal/gym & 5.A & MAT & 09 & 7.C & STU & 22 & 7.C & BIO & bio & & & \\[\mlrC]
4 & 10:45 & 11:30 & 8. & IDR & hal/gym & 5.A & MAT & 09 & & & & 7.C & BIO & bio & & & \\[\mlrC]
5 & 11:30 & 12:00 & 5.A & FORD & 09 & 7.C & FORD & 22 & 5.A & FORD & 09 & & & & & & \\[\mlrC]
6 & 12:40 & 13:25 & 7.C & GEO & 22 & 5.A & HIS & 09 & 7.C & MAT & 22 & & & & & & \\[\mlrC]
7 & 13:25 & 14:10 & 7.C & GEO & 22 & 5.A & HIS & 09 & 7.C & MAT & 22 & & & & & & \\[\mlrC]
8 & 14:25 & 15:10 & 7.C & MAT & 22 & \mc{TEAM} & & & & & & & & & \\
\bottomrule
\end{tabular}
\end{center}
\end{document}
答案1
大多数列之间的法线\tabcolsep
被 取代\@{...}
。这被添加到列的右侧,需要在 中重复\multicolumn
。因此, 的定义\mc
应该是:
\newcommand*\mc[1]{\multicolumn{3}{@{}c@{\mlrA}}{#1}}
And\mc
仅与一个参数一起使用。
最后一列以正常方式结束\tabcolsep
并且\mc
无法使用,而是使用正常方式\multicolumn
即可:
\multicolumn{3}{@{}c}{Fredag}
第 2 列和第 3 列的居中标题:
\multicolumn{2}{@{}c@{\mlrA}}{Tidspunkt}
现在,列标题应该正确居中,见以下示例。该示例还减小了\mlrC
表体中的行距,并增加了行距,\arraystretch
以使整体行距稍微平滑一些。
\documentclass[
a4paper,
12pt,
landscape,
danish
]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage[
hmargin = 2.4cm,
vmargin = 3cm
]{geometry}
\usepackage{fancyhdr}
\usepackage{booktabs}
\newcommand*\mc[1]{\multicolumn{3}{@{}c@{\mlrA}}{#1}}
\newcommand*\Alignment[1]{% adjustment at `--'
\multicolumn{1}{r@{}}{\llap{\makebox[\widthof{--}][c]{#1}}}%
}
\def\mlrA{\hskip 2.5em}
\def\mlrB{\hskip 0.8em}
\def\mlrC{1.5ex}
\pagestyle{fancy}
\renewcommand*\headrulewidth{0pt}
\setlength\headheight{14.5pt}
\lhead{}
\rhead{}
\cfoot{}
\begin{document}
\begin{center}
\textbf{\Huge Skema for skoleåret 2015--2016}
\vspace{5ex}
\renewcommand*{\arraystretch}{1.3}
\begin{tabular}{
c @{\mlrB}
r @{\,--\,}
l @{\mlrA}
l @{\mlrB}
l @{\mlrB}
l @{\mlrA}
l @{\mlrB}
l @{\mlrB}
l @{\mlrA}
l @{\mlrB}
l @{\mlrB}
l @{\mlrA}
l @{\mlrB}
l @{\mlrB}
l @{\mlrA}
l @{\mlrB}
l @{\mlrB}
l
}
\toprule
Lektion
& \multicolumn{2}{@{}c@{\mlrA}}{Tidspunkt}
& \mc{Mandag}
& \mc{Tirsdag}
& \mc{Onsdag}
& \mc{Torsdag}
& \multicolumn{3}{@{}c}{Fredag} \\
\midrule
1 & 8:10 & 8:55 & & & & 7.C & F/K & fys & 5.A & MAT & 09 & & & & 7.C & MAT & 22 \\[\mlrC]
2 & 8:55 & 9:40 & & & & 7.C & F/K & fys & 5.A & N/T & 09 & & & & 7.C & STU & 22 \\[\mlrC]
3 & 10:00 & 10:45 & 8. & IDR & hal/gym & 5.A & MAT & 09 & 7.C & STU & 22 & 7.C & BIO & bio & & & \\[\mlrC]
4 & 10:45 & 11:30 & 8. & IDR & hal/gym & 5.A & MAT & 09 & & & & 7.C & BIO & bio & & & \\[\mlrC]
5 & 11:30 & 12:00 & 5.A & FORD & 09 & 7.C & FORD & 22 & 5.A & FORD & 09 & & & & & & \\[\mlrC]
6 & 12:40 & 13:25 & 7.C & GEO & 22 & 5.A & HIS & 09 & 7.C & MAT & 22 & & & & & & \\[\mlrC]
7 & 13:25 & 14:10 & 7.C & GEO & 22 & 5.A & HIS & 09 & 7.C & MAT & 22 & & & & & & \\[\mlrC]
8 & 14:25 & 15:10 & 7.C & MAT & 22 & \mc{TEAM} & & & & & & & & & \\
\bottomrule
\end{tabular}
\end{center}
\end{document}
由于表格标题属于表格,因此环境被移除,表格与表格标题一起table
放入环境中。或者,当不需要/不想要环境的额外垂直空间时,可以使用。center
\centering
center