给出下面的表格代码,我想添加\cline
到最后一列,在多行第四列之后。
\documentclass[10pt,fleqn]{article}
\usepackage{array}
\usepackage{multirow}
\begin{document}
\begin{table}[]
\begin{tabular}{|l|l|l|l|l|}
\hline
first & second & third & fourth & fifth \\\hline
1 & first & two & \multirow{5}{*}{list} &\\\cline{1-3}
2 & second & three & &\\\cline{1-3}
3 & third & four & &\\\cline{1-3}
4 & fourth &five & &\\\cline{1-3}
5 & fifth & six & &\\\hline
\end{tabular}
\end{table}
\end{document}
我试过了\cline{1-3,5}
,\cline{1-3}\cline{5}
。这些都不起作用。该怎么办呢?
答案1
的论点\cline
必须是范围列数,以 分隔-
。如果\cline
仅跨越一列,则在 之前和 之后注明该列的编号-
。
对于手头的表格,您需要输入的是\cline{1-3} \cline{5-5}
。
\documentclass{article}
\usepackage{array,multirow}
\begin{document}
\begin{table}[ht]
\centering
\begin{tabular}{|l|l|l|l|l|}
\hline
first & second & third & fourth & fifth \\
\hline
1 & first & two & \multirow{5}{*}{list}
& \\ \cline{1-3}\cline{5-5}
2 & second & three & & \\ \cline{1-3}\cline{5-5}
3 & third & four & & \\ \cline{1-3}\cline{5-5}
4 & fourth & five & & \\ \cline{1-3}\cline{5-5}
5 & fifth & six & & \\
\hline
\end{tabular}
\end{table}
\end{document}
答案2
{NiceTabular}
供参考,这里有一个使用创建表格的简单方法nicematrix
。
\documentclass{article}
\usepackage{nicematrix}
\begin{document}
\begin{table}[ht]
\centering
\begin{NiceTabular}{lllll}[hvlines]
first & second & third & fourth & fifth \\
1 & first & two & \Block{5-1}{list} \\
2 & second & three \\
3 & third & four \\
4 & fourth & five \\
5 & fifth & six \\
\end{NiceTabular}
\end{table}
\end{document}
答案3
版本tabularray
:
\documentclass{article}
\usepackage{tabularray}
\begin{document}
\begin{table}[ht]\centering
\begin{tblr}{
colspec={*5l},
hlines, vlines
}
first & second & third & fourth & fifth \\
1 & first & two & \SetCell[r=5]{c}list & \\
2 & second & three & & \\
3 & third & four & & \\
4 & fourth & five & & \\
5 & fifth & six & & \\
\end{tblr}
\end{table}
\end{document}