![长表与水平线问题](https://linux22.com/image/439979/%E9%95%BF%E8%A1%A8%E4%B8%8E%E6%B0%B4%E5%B9%B3%E7%BA%BF%E9%97%AE%E9%A2%98.png)
大家好,我想制作长表,因此我写了以下代码:
\documentclass[a4paper,11pt,english]{report}
\usepackage{longtable}
\usepackage{multirow}
\usepackage{graphicx}
\usepackage[table,xcdraw]{xcolor}
\usepackage{lipsum} % just for dummy text- not needed for a longtable
\begin{document}
\lipsum[1]
\lipsum[1]
\lipsum[1]
\definecolor{lightgray}{HTML}{EFEFEF}
\setlength\arrayrulewidth{.5pt}
\begin{longtable}{|
>{\columncolor{lightgray}}p{0.2\linewidth} | p{0.175\linewidth} |}
\hline
foo & bar \\[.5pt]\noalign{\nobreak\vskip-.5pt} \hline\noalign{\nobreak\vskip.5pt}
foo & bar \\ \cline{2-2}
foo & bar \\ \cline{2-2}
foo & bar \\ \cline{2-2}
foo & bar \\ \cline{2-2}
foo & bar \\ \cline{2-2}
foo & bar \\ \cline{2-2}
foo & bar \\ \cline{2-2}
foo & bar \\ \cline{2-2}
foo & bar \\ \cline{2-2}
foo & bar \\[.5pt]\noalign{\nobreak\vskip-.5pt} \hline\noalign{\nobreak\vskip.5pt}
\caption{Your caption here} % needs to go inside longtable environment
\label{tab:myfirstlongtable}
\end{longtable}
Table \ref{tab:myfirstlongtable} shows my first longtable.
\end{document}
代码运行良好,但有一个小问题:当表格分成多个页面时,页面之间没有绘制水平线,下面是我突出显示问题的输出:
我想要在第 1 页的表格末尾和第 2 页的表格开头绘制一条水平线
如何实现这一点?
感谢您的帮助
答案1
我认为,此代码符合longtable
语法(部分中的标题和标签firsthead
)并且\hhline
能够按照您的需要使用:
\definecolor{lightgray}{HTML}{EFEFEF}
\setlength\arrayrulewidth{.5pt}
\begin{longtable}{|>{\columncolor{lightgray}}p{0.2\linewidth} | p{0.175\linewidth} |}
\caption{Your caption here} % needs to go inside longtable environment
\label{tab:myfirstlongtable} \\
\endfirsthead
\caption{Your caption here (continued)}\\
\hline
\endhead
\hline
foo & bar \\[.5pt]\noalign{\nobreak\vskip-.5pt} \hline%\noalign{\nobreak\vskip.5pt}
foo & bar \\ \cline{2-2}
foo & bar \\ \cline{2-2}
foo & bar \\ \cline{2-2}
foo & bar \\ \hhline{|--|}
foo & bar \\ \cline{2-2}
foo & bar \\ \cline{2-2}
foo & bar \\ \cline{2-2}
foo & bar \\ \cline{2-2}
foo & bar \\ \cline{2-2}
foo & bar \\[.5pt]\noalign{\nobreak\vskip-.5pt} \hline\noalign{\nobreak\vskip.5pt}
\end{longtable}