我正在尝试编写一个表格,但最后几列缺少垂直行。有人知道如何修复这个问题吗?
\setlength\tabcolsep{4pt}
\begin{tabular}{|l|l|l|l|l|}
\cline{2-5}
\multicolumn{1}{l|}{} & Autumn & Pre-requisites & Spring & Pre-requisites \\\hline
\multirow{4}{*}{\textbf{Year 1}} & MATH187 & Either a mark of at least 80 in \\ & & MATH151 OR (in the NSW HSC \\ & & Examination) Mathematics Band \\ & & 4; or Mathematics Ext 1. & MATH188 & MATH187 \\\cline{2-5}
& MATH100 & None & MATH123 & MATH187 or MATH141 with \\ & & & & co-requisites of MATH188 \\ & & & & or MATH142 \\\cline{2-5}
& CSIT110 & None & STAT101 & None \\\cline{2-5}
& ACCY111 & None & ACCY112 & ACCY112 \\\hline \hline
\multirow{4}{*}{\textbf{Year 2}} & MATH201 & One of MATH110, MATH188 or \\ & & MATH283, or a mark of at least \\ & & 75 in MATH142 or MATH162, or \\ & & enrolment in course code 762A. & MATH202 & MATH201 \\\cline{2-5}
& MATH203 & One of MATH101, MATH188 or \\ & & MATH283 or enrolment in course \\ & & code 762A. & MATH204 & MATH201 \\\cline{2-5}
& MATH222 & One of MATH101, MATH188 or \\ & & enrolment in course code 762A & MATH212 & One of MATH101, MATH188, \\ & & & & MATH283 or enrolment in \\ & & & & course code 762A \\\cline{2-5}
& STAT231 & MATH188 or enrolment in \\ & & course code 762A. & STAT232 & STAT231 \\\cline{2-5}
\hline
\end{tabular}
答案1
booktabs
带包装且行数较少的版本,列类型X
为适应可用宽度的列类型tabularx
:p
\documentclass{article}
\usepackage{geometry}
\usepackage{array}
\usepackage{booktabs}
\usepackage{tabularx}
\begin{document}
\noindent
\begin{tabularx}{\linewidth}
{ll>{\raggedright}Xl>{\raggedright\arraybackslash}X}
\toprule
& Autumn & Pre-requisites & Spring & Pre-requisites \\
\midrule
\textbf{Year 1} & MATH187
& Either a mark of at least 80 in
MATH151 OR (in the NSW HSC
Examination) Mathematics Band~4; or Mathematics Ext~1.
& MATH188 & MATH187 \\
\cmidrule{2-5}
& MATH100 & None & MATH123
& MATH187 or MATH141 with co-requisites of MATH188
or MATH142 \\
\cmidrule{2-5}
& CSIT110 & None & STAT101 & None \tabularnewline
\cmidrule{2-5}
& ACCY111 & None & ACCY112 & ACCY112 \tabularnewline
\midrule
\textbf{Year 2} & MATH201
& One of MATH110, MATH188 or MATH283, or a mark of at least
75 in MATH142 or MATH162, or enrolment in course code 762A.
& MATH202 & MATH201 \\
\cmidrule{2-5}
& MATH203
& One of MATH101, MATH188 or MATH283 or enrolment in course
code 762A.
& MATH204 & MATH201 \\
\cmidrule{2-5}
& MATH222
& One of MATH101, MATH188 or enrolment in course code 762A
& MATH212 & One of MATH101, MATH188, MATH283 or enrolment in
course code 762A \\
\cmidrule{2-5}
& STAT231
& MATH188 or enrolment in course code 762A.
& STAT232 & STAT231 \\
\bottomrule
\end{tabularx}
\end{document}
或者用更少的行替换\cmidrule{2-5}
`\addlinespace:
答案2
您没有最后两列,因为您没有告诉 Latex 您想要它们:您使用 '\' 强制在第三列中使用换行符,但这基本上告诉 LaTeX“在此结束行”,这就是它所做的。如果您添加缺少的 '&',您将得到垂直线。
但我认为最好将第 3 列和第 5 列指定为“p”列,例如
\begin{tabular}{|l|l|p{.33\textwidth}|l|p{.33\textwidth}|}
删除表格内容中的手动格式。让 Latex 决定在哪里截断线条。这样就可以得到“第 1 年”部分(添加最少内容以使其编译后 :P)
\documentclass{article}
\begin{document}
\setlength\tabcolsep{4pt}
\begin{tabular}{|l|l|p{.33\textwidth}|l|p{.33\textwidth}|}
\cline{2-5}
\multicolumn{1}{l|}{} & Autumn & Pre-requisites & Spring & Pre-requisites \\
\hline
\multirow{4}{*}{\textbf{Year 1}} & MATH187 & Either a mark of at least 80 in MATH151 OR (in the NSW HSC Examination) Mathematics Band 4; or Mathematics Ext 1. & MATH188 & MATH187 \\\cline{2-5}
& MATH100 & None & MATH123 & MATH187 or MATH141 with co-requisites of MATH188 or MATH142 \\\cline{2-5}
& CSIT110 & None & STAT101 & None \\\cline{2-5}
& ACCY111 & None & ACCY112 & ACCY112 \\\hline \hline
%same for Year 2.
\hline
\end{tabular}
以同样的方式调整“第 2 年”部分。