以下是我为我的 4 个孩子安排的学校时间表,我尝试array
使用m{}
(垂直对齐中间)来获取单词彼得在其单元格中垂直对齐(在 处cmidrule
),因为这是垂直中心。同样,单词索尼娅应在她的行内垂直对齐。水平规则由 提供booktabs
。我的问题是孩子的名字没有垂直居中。
我想要的效果是这样的
作为后续问题,如果我(我知道这看起来很糟糕,我只是假设)希望第一列中的名称同时具有居中垂直对齐(m{}
)和居中水平对齐(c
),最好的方法是什么?我应该在列hfill
内使用吗m{}
?
我读过类似的问题,例如 这个但我不确定它们是否相同,因为我没有使用multirow
或multicol
。此外,解决方案这里需要手动估计高度,而我正在寻找自动化的东西。
近似 MWE 如下:
\documentclass[10pt,oneside]{article}
\usepackage[landscape, margin=0.2in]{geometry}
\usepackage{booktabs,array}
\newlength{\cwidth}
\setlength{\cwidth}{1.4in}
\begin{document}
\section{School Timetable}
\begin{tabular}{m{\cwidth}p{\cwidth}p{\cwidth}p{\cwidth}p{\cwidth}p{\cwidth}@{}} \toprule
&\textbf{Mon}&\textbf{Tues}&\textbf{Wed}&\textbf{Thurs}&\textbf{Fri}\\ \midrule
\textbf{Peter}&
Creative Arts\newline HSIE\newline Science &
English\newline Maths\newline Science\newline PDHPE---no sports&
Maths\newline TAS\newline Sport&
TAS\newline English\newline Science\newline Maths&
HSIE\newline Creative Arts\newline English \\
\cmidrule(r){2-6}
&English\newline HSIE\newline Science\newline PDHPE---no sports&
Science\newline Creative Arts\newline PDHPE---sports\newline English&
Maths\newline TAS\newline Sport&
PDHPE---sports\newline Maths\newline Creative Arts\newline TAS&
Science\newline English\newline Maths\newline HSIE\\ \midrule
\textbf{Sonya}&
&
&
&
Sport uniform\newline Library\newline Homework collected&
Homework issued \\ \midrule
\textbf{Michael}&
Sport Uniform&
Library&
&
Homework collected&
Homework issued\\ \midrule
\textbf{Andrew}&
Sport Uniform&
Library&
&
Homework collected&
Homework issued\\ \bottomrule
\end{tabular}
\end{document}
答案1
使用makecell
和multirow
,默认情况下,第一列水平居中(但可以更改)。该makecell
包允许在表格单元格中使用常见的格式和换行符,thead,\makecell, \multirowthead,``multirowcell
命令如下:
\documentclass[10pt,oneside]{article}
\usepackage[landscape, margin=0.2in, showframe]{geometry}
\usepackage{booktabs,array, makecell, multirow}
\newlength{\cwidth}
\setlength{\cwidth}{1.4in}
\renewcommand\theadfont{\normalsize\bfseries}
\begin{document}
\section{School Timetable}
\begin{center}
\begin{tabular}{m{\cwidth}p{\cwidth}p{\cwidth}p{\cwidth}p{\cwidth}p{\cwidth}@{}} \toprule
& \textbf{Mon} & \textbf{Tues} & \textbf{Wed} & \textbf{Thurs} & \textbf{Fri} \\%
\midrule
\multirowthead{8}[-\aboverulesep]{\textbf{Peter}}%
& Creative Arts\newline HSIE\newline Science %
& English\newline Maths\newline Science\newline PDHPE---no sports %
& Maths\newline TAS\newline Sport %
& TAS\newline English\newline Science\newline Maths%
& HSIE\newline Creative Arts\newline English \\ %
\cmidrule(r){2-6}
& English\newline HSIE\newline Science\newline PDHPE---no sports%
& Science\newline Creative Arts\newline PDHPE---sports\newline English%
& Maths\newline TAS\newline Sport& PDHPE---sports\newline Maths\newline Creative Arts\newline TAS %
& Science\newline English\newline Maths\newline HSIE \\%
\midrule
\multirowthead{3}{Sonya}&&&&%
Sport uniform\newline Library\newline Homework collected & Homework issued \\%
\midrule
\thead{Michael} & Sport Uniform & Library & & Homework collected & Homework issued \\%
\midrule
\thead{Andrew} & Sport Uniform&
Library&
&
Homework collected & Homework issued\\%
\bottomrule
\end{tabular}
\end{center}
\end{document}
答案2
使用multirow
包:
\multirow{8}[4]*{\textbf{Peter}}&
代码 :
\documentclass[10pt,oneside]{article}
\usepackage[landscape, margin=0.2in]{geometry}
\usepackage{booktabs,array}
\newlength{\cwidth}
\setlength{\cwidth}{1.4in}
\usepackage{multirow}
\begin{document}
\section{School Timetable}
\begin{tabular}{m{\cwidth}p{\cwidth}p{\cwidth}p{\cwidth}p{\cwidth}p{\cwidth}@{}} \toprule
&\textbf{Mon}&\textbf{Tues}&\textbf{Wed}&\textbf{Thurs}&\textbf{Fri}\\ \midrule
\multirow{8}[4]*{\textbf{Peter}}&
Creative Arts\newline HSIE\newline Science &
English\newline Maths\newline Science\newline PDHPE---no sports&
Maths\newline TAS\newline Sport&
TAS\newline English\newline Science\newline Maths&
HSIE\newline Creative Arts\newline English \\
\cmidrule(r){2-6}
&English\newline HSIE\newline Science\newline PDHPE---no sports&
Science\newline Creative Arts\newline PDHPE---sports\newline English&
Maths\newline TAS\newline Sport&
PDHPE---sports\newline Maths\newline Creative Arts\newline TAS&
Science\newline English\newline Maths\newline HSIE\\ \midrule
\multirow{3}*{\textbf{Sonya}}&
&
&
&
Sport uniform\newline Library\newline Homework collected&
Homework issued \\ \midrule
\textbf{Michael}&
Sport Uniform&
Library&
&
Homework collected&
Homework issued\\ \midrule
\textbf{Andrew}&
Sport Uniform&
Library&
&
Homework collected&
Homework issued\\ \bottomrule
\end{tabular}
\end{document}