梅威瑟:
我尝试添加多次\cline
,但没有成功...!
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{multirow, makecell, booktabs, tabularx, longtable}
\usepackage[dvipsnames,table]{xcolor}
\definecolor{light-gray}{HTML}{FFFFFF}
\definecolor{light-blue}{HTML}{EBF5FB}
\title{}
\author{}
\begin{document}
\maketitle
\rowcolors{1}{light-gray}{light-blue}
\begin{longtable}
{m{1.2cm} m{0.5cm} m{1cm} m{1.5cm} m{1.5cm} m{1.5cm} m{1.5cm}}
\hline
\rowcolor{white}
& $Day$
& $Month$
& $Hours$
& $Feature 1$
& $Feature 2$
& $Feature 3$\\
\hline
%-------------------------------------------------
Friday
& $5$
& June
&
& $A_1$
& $A_2$
& $A_3$
\\
\hline
%-------------------------------------------------
\global\rownum=2\relax
&
&
& $14 - 21$
& $B_1$
&
& $B_3$
\\
\multirow{-2}{*}[0em]{Saturday}
& \multirow{-2}{*}[0em]{$6$}
& \multirow{-2}{*}[0em]{June}
&
& $C_1$
& $C_2$
& $C_3$
\\
\hline
% -------------------------------------------------
\global\rownum=1\relax
&
&
& $08 - 10$
& $D_1$
& $D_2$
& $D_3$
\\
\global\rownum=1\relax
&
&
& $10 - 17$
& $E_1$
&
& $E_3$
\\
\multirow{-3}{*}[0em]{Sunday}
& \multirow{-3}{*}[0em]{$7$}
& \multirow{-3}{*}[0em]{June}
&
& $F_1$
& $F_2$
& $F_3$
\\
\hline
% -------------------------------------------------
\hiderowcolors
\\
\caption{This is a caption.}
\end{longtable}
\end{document}
此代码生成的内容:
我的期望输出:
答案1
我建议使用tabularray
:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[dvipsnames,table]{xcolor}
\definecolor{light-gray}{HTML}{FFFFFF}
\definecolor{light-blue}{HTML}{EBF5FB}
\usepackage{tabularray}
\title{}
\author{}
\begin{document}
\maketitle
\begin{longtblr}[
caption = {This is a caption.},
]{
colspec={m{1.2cm} m{0.5cm} m{1cm} m{1.5cm} m{1.5cm} m{1.5cm} m{1.5cm}},
row{1}={font=\itshape},
cell{2-Z}{5-Z}={mode=math},
row{2,5-7}={bg=light-blue},
row{3-4}={bg=light-gray},
hlines
}
& Day
& Month
& Hours
& Feature 1
& Feature 2
& Feature 3\\
%-------------------------------------------------
Friday
& 5
& June
&
& A_1
& A_2
& A_3
\\
%-------------------------------------------------
\SetCell[r=2]{l} Saturday
& \SetCell[r=2]{l} 6
& \SetCell[r=2]{l} June
& 14 -- 21
& B_1
&
& B_3
\\
&
&
&
& C_1
& C_2
& C_3
\\
% -------------------------------------------------
\SetCell[r=3]{l} Sunday
& \SetCell[r=3]{l} 7
& \SetCell[r=3]{l} June
& 08 -- 10
& D_1
& D_2
& D_3
\\
&
&
& 10 -- 17
& E_1
&
& E_3
\\
&
&
&
& F_1
& F_2
& F_3
\\
% -------------------------------------------------
\end{longtblr}
\end{document}
如果您使用数学模式仅有下标,但您的单元格实际上只有文本:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[dvipsnames,table]{xcolor}
\definecolor{light-gray}{HTML}{FFFFFF}
\definecolor{light-blue}{HTML}{EBF5FB}
\usepackage{tabularray}
\title{}
\author{}
\begin{document}
\maketitle
\begin{longtblr}[
caption = {This is a caption.},
]{
colspec={m{1.2cm} m{0.5cm} m{1cm} m{1.5cm} m{1.5cm} m{1.5cm} m{1.5cm}},
row{1}={font=\itshape},
row{2,5-7}={bg=light-blue},
row{3-4}={bg=light-gray},
hlines
}
& Day
& Month
& Hours
& Feature 1
& Feature 2
& Feature 3\\
%-------------------------------------------------
Friday
& 5
& June
&
& A\textsubscript{1}
& A\textsubscript{2}
& A\textsubscript{3}
\\
%-------------------------------------------------
\SetCell[r=2]{l} Saturday
& \SetCell[r=2]{l} 6
& \SetCell[r=2]{l} June
& 14 -- 21
& B\textsubscript{1}
&
& B\textsubscript{3}
\\
&
&
&
& C\textsubscript{1}
& C\textsubscript{2}
& C\textsubscript{3}
\\
% -------------------------------------------------
\SetCell[r=3]{l} Sunday
& \SetCell[r=3]{l} 7
& \SetCell[r=3]{l} June
& 08 -- 10
& D\textsubscript{1}
& D\textsubscript{2}
& D\textsubscript{3}
\\
&
&
& 10 -- 17
& E\textsubscript{1}
&
& E\textsubscript{3}
\\
&
&
&
& F\textsubscript{1}
& F\textsubscript{2}
& F\textsubscript{3}
\\
% -------------------------------------------------
\end{longtblr}
\end{document}