# Booktabs and longtable - strange spaces between lines

I needed to make some horizontal table lines bold so I used booktabs package. However if I use \toprule command to make line bold I get strange outcome - there are some spaces between bold line and vertical table lines (please take a look at screen )

code used to generate table looks this way

    \begin{longtable}{|c|c|c|c|c|c|c|c|c|}
\caption{Wyniki rozpoznawania obrazów dla obrazu zapytania 022\_0007.jpg oraz kategorii $budda$}
\label{tab:budda}
\\
\toprule
\multicolumn{2}{|c|}{\textbf{Obraz zapytanie}} & \multicolumn{3}{|c|}{\textbf{Obraz przetwarzany}} & \multicolumn{4}{|c|}{\textbf{Wynik}} \\
\toprule
\textbf{Nazwa} & \textbf{N} & \textbf{Katalog} & \textbf{Nazwa} & \textbf{N} & \textbf{ $J_{b}$} & \textbf{$J_{a}$} & \textbf{Czas[s]} & \textbf{Gęstość} \\ \hline
...
..
..
\end{longtable}


PS Is it possible to make horizontal lines bold ??

EDIT I decied to resign from booktabs and I used solution presented in here LaTeX tables: How do I make bold horizontal lines (typically \hline)? (pluton answer) now I have a horizontal bold lines and I also managed to make vertical lines bold. The problem however is horizontal line length. My table's length is a bit bigger than length of page (from one margin to another) and I think it makes the horizontal lines look like that

Is it possible to somehow adjust this command

    \def\hlinewd#1{%
\noalign{\ifnum0=}\fi\hrule \@height #1 %
\futurelet\reserved@a\@xhline}


so that it adjust length of the bolded line to the length of the table

Here is compilable code snipet

\documentclass[a4paper,12pt]{mwrep}

\usepackage[cp1250]{inputenc}
\usepackage[left=3.0cm,right=3cm,top=3.0cm,bottom=3.0cm]{geometry}
\usepackage{amsmath,amssymb}
\usepackage{graphicx}
\usepackage{setspace}
\usepackage{algorithmic}
\usepackage{tabularx}
\usepackage{longtable}

\usepackage[centerlast]{caption}
\usepackage{multirow}
\usepackage[section] {placeins}
\usepackage{booktabs}
\makeatletter
\def\hlinewd#1{%
\noalign{\ifnum0=}\fi\hrule \@height #1 %
\futurelet\reserved@a\@xhline}
\makeatother
\begin{document}
\chapter{somechapter}
\section{somesection}
\small
\begin{longtable}{!{\vrule width 2pt} c!{\vrule width 2pt} c!{\vrule width 2pt} c!{\vrule width 2pt} c!{\vrule width 2pt} c!{\vrule width 2pt} c!{\vrule width 2pt} c!{\vrule width 2pt} c!{\vrule width 2pt} c!{\vrule width 2pt} }

\caption{something something somethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomething}
\label{tab:budda}
\\ \hlinewd{2pt}
\multicolumn{2}{!{\vrule width 2pt}c!{\vrule width 2pt}}{\textbf{Query image }} & \multicolumn{3}{c!{\vrule width 2pt}}{\textbf{Processed image}} & \multicolumn{4}{c!{\vrule width 2pt}}{\textbf{Outcome}} \\ \hlinewd{2pt}

\textbf{Name} & \textbf{N} & \textbf{Directory} & \textbf{Name} & \textbf{N} & \textbf{ $J_{b}$} & \textbf{$J_{a}$} & \textbf{time[s]} & \textbf{Density} \\ \hlinewd{2pt}
022\_0007.jpg   &   193 &   budda   &   22\_0007.jpg    &   193 &   25512.9 &   156.1   &   288.5   &   0.73    \\  \hline
\end{longtable}
\end{document}

-
The booktabs package is explicitly designed for tables without vertical rules. So either you should redo your table without vertical rules, (generally preferred) or not use booktabs rules. – Alan Munn Jul 29 '11 at 19:32
Further to @Alan's comment: This is taken from the booktabs documentation (p 3): "You will not go far wrong if you remember two simple guidelines at all times: 1. Never, ever use vertical rules. 2. Never use double rules." – Werner Jul 29 '11 at 19:51
@AlanMunn please see my edit – imagePlacer Jul 29 '11 at 22:07
@imagePlacer for all intents and purposes, it's impossible. Probably not literally so, since very little in TeX is truly impossible it seems, but in practical terms, yes, you can't use booktabs rules with vertical lines. To give another quote from the docs: "More importantly the rules generated by the [booktabs] commands are in no way guaranteed to connect with verticals generated by {|} characters in the preamble. This is a feature (see above). You should not use vertical rules in tables, end of story." (p.5) – Alan Munn Jul 29 '11 at 22:08
@imagePlacer It would help you make your new edit have a complete, compilable minimal document which produces just the output you are having trouble with. That way people can see what you are doing without having to guess. – Alan Munn Jul 29 '11 at 22:11

I think I finally found a solution for making booktabs and hrules work so that is why I make an answer to my own question I created my own command

\newcommand{\mytoprule}{\specialrule{2pt}{0em}{0em}}
\newcommand{\mybottomrule}{\specialrule{2pt}{0em}{0em}}


and now everyting looks fine.

-
This works even better with \bigstrut to help with the cramped row heights. – srking Jul 20 '12 at 19:14

To your second question:

the \midrule[width] has an optional argument for the line width and should at least leave the same space above and below the line.

With the command \cmidrule[width]{columns} you can add a horizontal line with defined width that spans not all columns.

See booktabs documentation for more information.

AFAIK you can not suppress the vertical spaces easily, as they are part of the "philosophy" of booktabs (not to use vertical lines at all) and they make the difference between the toprule and the bottomrule.

example for line width for a midrule with very thick lines:

\documentclass{article}

\usepackage{longtable, booktabs}

\begin{document}
\begin{longtable}{|c|c|c|c|c|c|c|c|c|}
\caption{Wyniki rozpoznawania obrazów dla obrazu zapytania 022\_0007.jpg oraz kategorii $budda$}
\label{tab:budda}
\\
\toprule
\multicolumn{2}{|c|}{\textbf{Obraz zapytanie}} & \multicolumn{3}{|c|}{\textbf{Obraz przetwarzany}} & \multicolumn{4}{|c|}{\textbf{Wynik}} \\
\toprule
\textbf{Nazwa} & \textbf{N} & \textbf{Katalog} & \textbf{Nazwa} & \textbf{N} & \textbf{ $J_{b}$} & \textbf{$J_{a}$} & \textbf{Czas[s]} & \textbf{Gęstość} \\ \hline
…\\
new line\\
\midrule[2 pt]
new line\\
\cmidrule[5pt]{1-5}\\
..
..
\end{longtable}

\end{document}


-
please use CTAN addresses as http://mirror.ctan.org/macros/latex/... – Herbert Jul 29 '11 at 20:08
@Martin please see my edit :) – imagePlacer Jul 29 '11 at 22:05
The length of the line (whether via \hline or \hlinewd) defaults to \hline which stretches across the entire length of the table. If it protrudes into your margins, then the actual table is too wide, not the line. You need to either adjust the \@extracolsep{...}, or resize the entire table to fit within the margins: \resizebox{\linewidth}{!}{\begin{tabular}...\end{tabular}}. – Werner Jul 29 '11 at 22:19
@Werner Are You sure that resizebox works with longtable ? I don't understand Your answer. You wrote that \hline as well as \hlinewd should strech across entire length of the table, however only \hline is streched but \hlinewd is too short. I added compilable code snipet which presnets my problem – imagePlacer Jul 30 '11 at 0:15
@imagePlacer: I missed your use of \begin{longtable}, sorry. No, resizing of a longtable is not possible, since it is meant to flow across pages. Also, I see now that your \hlinewd uses \hrule, not \hline. \hrule exists only within \linewidth. So, as soon as the end of the line is reached, \hrule stops, hence the gap from the right margin to the right edge of your longtable. – Werner Jul 30 '11 at 6:36

By using

\renewcommand{\arrayrulewidth}{2pt}%


you can drastically improve readability of your code and produce the desired effect (assuming, of course, that all your rules - vertical and horizontal - are the same width). The advantage is that is also works with longtable.

\documentclass[a4paper,12pt]{mwrep}
...
\begin{document}
\renewcommand{\arrayrulewidth}{2pt}
\chapter{somechapter}
\section{somesection}
\small
\begin{longtable}{|c|c|c|c|c|c|c|c|c|}
\caption{something something somethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomething}
\label{tab:budda}
\\ \hline
\multicolumn{2}{|c|}{\textbf{Query image }} & \multicolumn{3}{c|}{\textbf{Processed image}} & \multicolumn{4}{c|}{\textbf{Outcome}} \\ \hline
\textbf{Name} & \textbf{N} & \textbf{Directory} & \textbf{Name} & \textbf{N} & \textbf{ $J_{b}$} & \textbf{$J_{a}$} & \textbf{time[s]} & \textbf{Density} \\ \hline
022\_0007.jpg   &   193 &   budda   &   22\_0007.jpg    &   193 &   25512.9 &   156.1   &   288.5   &   0.73    \\  \hline
\end{longtable}
\end{document}


-