我正在尝试使用多行包将列频率的标题细分为早上、中午、晚上。但我遇到了错误,我无法纠正。请帮忙
\documentclass{article}
\usepackage{multirow, booktabs}
\usepackage{arydshln}
\setlength{\dashlinedash}{.4pt}
\setlength{\dashlinegap}{.8pt}
\newcommand{\instructions}{\footnotesize{$\frac{before}{after}$meals/bedtime}}
\begin{document}
\begin{center}
\renewcommand\arraystretch{1.75}
\setlength\arrayrulewidth{0.1pt}
\begin{tabular}{p{0.5cm}|p{3cm}|p{1.5cm}|p{3cm}|p{2cm}|p{3.5cm}}
\toprule
\multirow {2} {*} {Sr} & {Drug} & {\multicolumn{4}{c|}{Frequency}}& {Duration} & {Remark}\\
& & Morn & Noon & Eve & Night & & \\
\midrule
1 & & & & \hspace{1cm} days & \hspace{1cm}{\instructions} \\ \hdashline
2 & & & & \hspace{1cm} days & \hspace{1cm}{\instructions} \\ \hdashline
3 & & & & \hspace{1cm} days & \hspace{1cm}{\instructions} \\ \hdashline
4 & & & & \hspace{1cm} days & \hspace{1cm}{\instructions} \\ \hdashline
5 & & & & \hspace{1cm} days & \hspace{01cm}{\instructions} \\ \hdashline
6 & & & & \hspace{1cm} days & \\ \hdashline
7 & & & & & \\ \bottomrule
\end{tabular}
\end{center}
\end{document}
答案1
让我们将我的评论延伸到答案。我猜你的表格应该是这样的:
与您的 MWE 相比的变化:
- 而是
tabular
使用tabularx
- 列数增加到 9 个,其中 3 个用于替换
\hspace{...}
\aboverulesep
并\belowrulesep
设置为零以获得更好的垂直线外观- \instructions 的定义得到改进
所有这些更改都是通过在序言中添加的包来启用的:geometry
用于确定页面布局,选项showframe
显示它,amsmath
(对于\instructions
),tabularx
用于替换tabular
:
\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{booktabs, multirow, tabularx}
\usepackage{arydshln}
\usepackage{amsmath}
\setlength{\dashlinedash}{.4pt}
\setlength{\dashlinegap}{.8pt}
\newcommand{\instructions}{$\frac{\text{before}}{\text{after}}$ meals/bedtime}
\begin{document}
\begin{center}
\renewcommand\arraystretch{1.75}
\setlength\arrayrulewidth{0.1pt}
\setlength\aboverulesep{0pt}
\setlength\belowrulesep{0pt}
\begin{tabularx}{\linewidth}{| l |
p{3cm} |
X |
*{2}{X X |}
X l |
}
\toprule
\multirow{2}{*}{Sr}
& Drug & \multicolumn{3}{c|}{Frequency}
& \multicolumn{2}{c|}{Duration}
& \multicolumn{2}{c|}{Remark} \\
\cdashline{2-9}
& & Morn & \multicolumn{2}{c|}{Noon}
& \multicolumn{2}{c|}{Eve}
& & Night \\
\midrule
1 & & ~ & ~& daily & ~& days & ~ & \instructions \\
\hdashline
2 & & & & daily & & days & & \instructions \\
3 & & & & daily & & days & & \instructions \\
\hdashline
4 & & & & daily & & days & & \instructions \\
\hdashline
5 & & & & daily & & days & & \instructions \\
\hdashline
6 & & & & daily & & days & & \\
\hdashline
7 & & & & & & & & \\
\bottomrule
\end{tabularx}
\end{center}
\end{document}
答案2
这是一个工作版本(删除周围的分组\multicolumn
,更正使用的列数),但您应该考虑以下几点:
- 正如您在文档中看到的,
booktabs
您绝对应该避免在表格中使用垂直线。这看起来不太好看。如果您需要这些垂直线,仍然可以选择使用普通的 LaTeX\hline
。 - 最后一列现在这样设计肯定不好,空间太大了。也许应该把它去掉。
- 您的行包含“早晨/中午”等,根据列,不符合任何有用的定义,因此我将其删除。您可能需要更多列。
\documentclass{article}
\usepackage{multirow, booktabs}
\usepackage{arydshln}
\setlength{\dashlinedash}{.4pt}
\setlength{\dashlinegap}{.8pt}
\newcommand{\instructions}{\footnotesize{$\frac{before}{after}$meals/bedtime}}
\begin{document}
\begin{center}
\renewcommand\arraystretch{1.75}
\setlength\arrayrulewidth{0.1pt}
\begin{tabular}{p{0.5cm}|p{3cm}|p{1.5cm}|p{3cm}|p{2cm}|p{3.5cm}}
\toprule
\multirow{2}{*}{Sr} & Drug & \multicolumn{2}{c|}{Frequency} & Duration & Remark\\
& & & & &\\
\midrule
1 & & & & \hspace{1cm} days & \hspace{1cm}{\instructions} \\ \hdashline
2 & & & & \hspace{1cm} days & \hspace{1cm}{\instructions} \\ \hdashline
3 & & & & \hspace{1cm} days & \hspace{1cm}{\instructions} \\ \hdashline
4 & & & & \hspace{1cm} days & \hspace{1cm}{\instructions} \\ \hdashline
5 & & & & \hspace{1cm} days & \hspace{01cm}{\instructions} \\ \hdashline
6 & & & & \hspace{1cm} days & \\ \hdashline
7 & & & & & \\ \bottomrule
\end{tabular}
\end{center}
\end{document}