1

When I draw the following table, a vertical line appears between the head of the table and the bottom of the caption. (When I don't insert the caption the line disappears)

I use longtabu because this table spans multiple pages in my thesis

\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}

The result is as follows:

vertical line caption

Is there a way to remove this vertical line? Or is there another way to create these vertical lines in the table?

1

You put the caption and the label inside the longtabu environnement and this create a newline. A hack may be to add a cline to avoid the vertical line:

\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}

output:

enter image description here

If you do not need to span your document on several page you can also use a table environnement:

\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}

output:

enter image description here

  • In this way the table can't span across multiple pages because "the table environment cannot be split across pages" – Hette Jan 7 '16 at 15:35
  • @Hette see my edit – Romain Picot Jan 7 '16 at 15:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.