当我绘制下表时,表格顶部和标题底部之间会出现一条垂直线。(当我不插入标题时,该线会消失)
我使用 longtabu,因为这个表在我的论文中跨越了多页
\documentclass[10pt]{report}
\usepackage{caption}
\usepackage[table]{xcolor}
\usepackage{tabu}
\usepackage{lipsum}
\usepackage{longtable}
\begin{document}
\lipsum[1]
\begin{longtabu} to \textwidth {X[2.0] | X[0.3]}
\caption{\textit{The caption of this table}}\\
\label{test-table}\\
\hline
\rowcolor{lightgray} \textbf{Title 1} & \textbf{Title 2}\\
\hline
\endfirsthead
\hline
\endlastfoot
\multicolumn{2}{l} {{\cellcolor{lightgray!20}\textbf{Subtitle 1}}} \\
\hline
test 1 & 1 \\
test 2 & 2 \\
test 3 & 3 \\
test 4 & 4 \\
test 5 & 5 \\
test 6 & 6 \\
\end{longtabu}
\end{document}
结果如下:
有没有办法删除这条垂直线?或者有没有其他方法可以在表格中创建这些垂直线?
答案1
您将标题和标签放在环境中longtabu
,这样就会创建一个换行符。一种技巧可能是添加一个cline
以避免出现垂直线:
\documentclass[10pt]{report}
\usepackage{caption}
\usepackage[table]{xcolor}
\usepackage{tabu}
\usepackage{lipsum}
\usepackage{longtable}
\begin{document}
\lipsum[1]
\begin{longtabu} to \textwidth {X[2.0] | X[0.3]}
\caption{\textit{The caption of this table}}
\label{test-table}\\
\cline{1-2}
\hline
\rowcolor{lightgray} \textbf{Title 1} & \textbf{Title 2}\\
\hline
\endfirsthead
\hline
\endlastfoot
\multicolumn{2}{l} {{\cellcolor{lightgray!20}\textbf{Subtitle 1}}} \\
\hline
test 1 & 1 \\
test 2 & 2 \\
test 3 & 3 \\
test 4 & 4 \\
test 5 & 5 \\
test 6 & 6 \\
\end{longtabu}
\end{document}
输出:
如果您不需要将文档扩展到多页,您也可以使用table
环境:
\documentclass[10pt]{report}
\usepackage{caption}
\usepackage[table]{xcolor}
\usepackage{tabu}
\usepackage{lipsum}
\usepackage{longtable}
\begin{document}
\lipsum[1]
\begin{table}
\caption{\textit{The caption of this table}}
\label{MET-classification}
\begin{longtabu} to \textwidth {X[2.0] | X[0.3]}
\hline
\rowcolor{lightgray} \textbf{Title 1} & \textbf{Title 2}\\
\hline
\endfirsthead
\hline
\endlastfoot
\multicolumn{2}{l} {{\cellcolor{lightgray!20}\textbf{Subtitle 1}}} \\
\hline
test 1 & 1 \\
test 2 & 2 \\
test 3 & 3 \\
test 4 & 4 \\
test 5 & 5 \\
test 6 & 6 \\
\end{longtabu}
\end{table}
\end{document}
输出: