3

I'm trying to use one longtable in my thesis while all others are created with table and tabular environment. I tried to find help visiting this link. But there only one type of table (longtable) is used.

The first lines (between %and %) in my preamble are copied from the link above. If I don't use them the code works but at the same time there's no space between the \hline\hline anymore. If I only use the longtable or put the longtable first, the code can be compiled. But the order represented in this extract represents the order in my thesis.

If I don't use the colortbl respectively xcolor with the option table it works fine. But I don't know how I can color my rows without using this package. But I need the space between the two lines to separate different categories.

Thanks for your help.

\documentclass{article}
%
\usepackage{color}
\makeatletter
\let\xx@begindocumenthook\@begindocumenthook
\let\xxhline\hline
\let\xx@xhline\@xhline
\usepackage{colortbl}
\let\hline\xxhline
\let\@xhline\xx@xhline
\let\@begindocumenthook\xx@begindocumenthook
\makeatother
\usepackage{longtable}
%
\usepackage[table]{xcolor}
%
\usepackage{subcaption}
%
\usepackage{tabularx}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{listings,color}
%
\begin{document}\color{black}
%
\begin{table}[H]
\centering
\begin{tabular}{|l|r|r|}
\hline
\rowcolor{lightgray}
\textbf{Component} & \multicolumn{1}{c|}{\textbf{Flight segment [\%]}} & \multicolumn{1}{c|}{\textbf{Passenger segment [\%]}} \\ \hline
1 & 20 & 80 \\ \hline \hline
2 & 10 & 90 \\ \hline
\end{tabular}
\caption{Caption 2}
\end{table}
%
\begin{center}
\begin{longtable}{|p{5cm}|c|p{4cm}|}
\hline
\rowcolor{lightgray}
\textbf{Mass component} & \multicolumn{1}{c|}{\textbf{Techfactor}} & \multicolumn{1}{c|}{\textbf{Reason}} \\ \hline
A lot of text & a lot of text & a lot of text \\ \hline
A lot of text & a lot of text & a lot of text \\ \hline
A lot of text & a lot of text & a lot of text \\ \hline \hline
A lot of text & a lot of text & a lot of text \\ \hline
A lot of text & a lot of text & a lot of text \\ \hline \hline
A lot of text & a lot of text & a lot of text \\ \hline
\caption{Caption 1}
\end{longtable}
\end{center}
%
Text text text.
%

% 
\end{document}

3 Answers 3

2
  • If the problem is only drawing \hline\hline in a long table, then a simple solution would be hhline{===} (in the case of the table with three columns) from package hhline
  • off topic:
    • It is sufficient to load xcolor paclage exclusively, which is supersede of color package and its option table calls colortbl;
    • Long table is default centered, so encapulating it in \begin{center} ... \end{center} is superfluous;
    • Captions, especially in the case of long tables, should be on the top of them, not at the bottom;

enter image description here

\documentclass{article}

\usepackage{longtable, makecell, multirow, tabularx}
\renewcommand\theadfont{\normalsize\bfseries}
\usepackage{hhline}
%
\usepackage[table]{xcolor}
%
\usepackage{subcaption}
%
\usepackage{multicol}
\usepackage{listings}
%
\begin{document}
%
\begin{longtable}{|p{5cm}|c|p{4cm}|}
    \caption{Caption 1}                       \\
   \hline
\rowcolor{lightgray}
\thead{Mass component}  & \thead{Techfactor} &  \thead{Reason}  \\
    \hline
A lot of text & a lot of text & a lot of text \\ \hline
A lot of text & a lot of text & a lot of text \\ \hline
A lot of text & a lot of text & a lot of text \\
    \hhline{===}
A lot of text & a lot of text & a lot of text \\ \hline
A lot of text & a lot of text & a lot of text \\
    \hhline{===}
A lot of text & a lot of text & a lot of text \\ \hline
\end{longtable}
%
Text text text.
%
\end{document}
4
  • @Roboticist -- please restore the code of the example that was originally provided. it should not be left to a reader to have to reconstruct the details from a description when they were provided by the person who originally answreed. Commented Oct 11, 2017 at 0:11
  • @barbarabeeton, i return the code. when approving his editing of my terrible language (well, here 02:15) i not see that he is also deleted my code ..
    – Zarko
    Commented Oct 11, 2017 at 0:14
  • i was checking the edit, and thought the grammatical changes were decent, but was rather scandalized that the code was removed. i was trying to fix it, but couldn't do it fast enough on my laptop -- you beat me to it. good going. Commented Oct 11, 2017 at 0:19
  • @barbarabeeton@Zarko Sorry for the (inadvertent) inappropriate change applied to the code, which was not really what I was intended to do!
    – user78499
    Commented Oct 11, 2017 at 0:25
1

Instead of using the \hline twice, i defined a new line-type to get it done. A workaround - but providing the desired behavior. This is the code for the new line-type that need to be put into the document/preamble:

\newcommand{\lline}[1]{\hline\multicolumn{#1}{c}{}\\[-1.3em]\hline}

So instead of \hline\hline i used \lline.

1

I did use another trick. I'm German so please apologize for my language. That use of to heads is only important if u wanna continue ur heading on the next pages

\begin{longtable}{p{4cm} | p{1.5cm} | p{1.7cm} | p{7.5cm}}
\caption{This is a wonderful caption}\\
    \hline
    \multicolumn{4}{c}{ } \\[-1,3em]  %intresting part for ur question
    \hline
\label{tab:wonduferful_longtable}
    \textbf{column 1st header} & \textbf{column 2nd header} & \textbf{column 3rd header} & \textbf{column 4th header} \\
    \hline
    \endfirsthead
    \textbf{column 1st header} & \textbf{column 2nd header} & \textbf{column 3rd header} & \textbf{column 4th header} \\
    \hline
    \endhead
    blabla & blabla & blabla & blabla \\
    blabla & blabla & blabla & blabla \\
    blabla & blabla & blabla & blabla \\
\end{longtable}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .