是否可以使用csvloop
命令更改行颜色以获得条纹长表?相当于 late after line=\csvifoddrow{\\\rowcolor{white}{\\\rowcolor{gray!20}},
我们使用csvreader
举例来说,是否可以调整以下 MWE?
\documentclass{article}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{csvsimple}
\usepackage{hyperref}
\begin{document}
\begin{filecontents*}{test.csv}
a|b|c
1|2|3
4|5|6
7|8|9
10|11|12
13|14|15
16|17|18
\end{filecontents*}
\csvloop{
file=test.csv,
respect all,
separator=pipe,
no head,
before reading={
\begin{longtable}{lll}
\toprule
},
command={\csviffirstrow
{\textbf{\csvcoli} & \textbf{\csvcolii} & \textbf{\csvcoliii} }
{\csvcoli & \csvcolii & \csvcoliii }
},
late after line={\\},
late after first line={\\\midrule\endhead},
late after last line={\\\bottomrule},
after reading={
\end{longtable}
}
}
\end{document}
答案1
包xcolor
(带有table
包选项)提供了\rowcolors
命令,用于设置交替行颜色。此命令在启动表格之前使用,因此可以包含在中before reading
。
梅威瑟:
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{csvsimple}
\usepackage{hyperref}
\begin{document}
\begin{filecontents*}{test.csv}
a|b|c
1|2|3
4|5|6
7|8|9
10|11|12
13|14|15
16|17|18
\end{filecontents*}
\csvloop{
file=test.csv,
respect all,
separator=pipe,
no head,
before reading={
\rowcolors{2}{gray!25}{white}
\begin{longtable}{lll}
\toprule
},
command={\csviffirstrow
{\textbf{\csvcoli} & \textbf{\csvcolii} & \textbf{\csvcoliii} }
{\csvcoli & \csvcolii & \csvcoliii }
},
late after line={\\},
late after first line={\\\midrule\endhead},
late after last line={\\\bottomrule},
after reading={
\end{longtable}
}
}
\end{document}
结果: