0

I have made this table for latex and placed 1 vertical line in it but this line is discontinuous i want this vertical line to meet with the horizontal line my code is

\begin{table}[htbp]
  \centering
  \caption{Add caption}
    \begin{tabular}{cc|cccc}
    \toprule
    \textbf{Sr. No.} & \multicolumn{1}{c}{\textbf{Parameter}} & \textbf{Number} & \textbf{C} & \textbf{D} \\
    \midrule
    \multirow{2}[1]{*}{1} & \multirow{2}[1]{*}{A} & \multirow{2}[1]{*}{2} & 0     & 0    \\
          &       &       & 0     & 0    \\
    1     & B & 2     &  5   & 7     \\
    \end{tabular}%
  \label{tab:addlabel}%
\end{table}% 
3

1 Answer 1

5

Using vertical lines with booktabs is not recommended at all.

Excerpt from the documentation:

enter image description here

If you want to "separate" the first two columns from the others, I suggest you to use \cmidrule as in the following example:

\documentclass{article}
\usepackage{multirow,booktabs}

\begin{document}

\begin{table}[htbp]
  \centering
  \caption{Add caption}\label{tab:addlabel}
    \begin{tabular}{cccccc}
    \toprule
    \textbf{Sr. No.} & \textbf{Parameter} & \textbf{Number} & \textbf{C} & \textbf{D} \\
    \cmidrule(lr){1-2}\cmidrule(lr){3-5}
    \multirow{2}[1]{*}{1} & \multirow{2}[1]{*}{A} & \multirow{2}[1]{*}{2} & 0     & 0    \\
          &       &       & 0     & 0    \\
    1     & B & 2     &  5   & 7     \\
    \end{tabular}
\end{table}

\end{document} 

Output:

enter image description here

Also note that the \label must immediately follow the \caption command.

4
  • i have much complex tables where i am using toprule, bottomrule, midrule, cmidrule so using booktabs is necessary is there any package which can remove the spaces in vertical lines created by booktabs package?
    – Shaggi3
    Jun 18, 2017 at 7:04
  • 1
    @Shaggi3 - The short answer is, "No". Do read the user guide of the booktabs package: The package's author leaves no doubt that he believes strongly that the use of vertical rules in a well-designed table can have no valid justification. It is with this design principle in mind that the details of \toprule, \midrule, etc macros were chosen. Short of undertaking a very major (and, in my view, utterly undesirable) hack of the booktabs package, one cannot obtain uninterrupted vertical lines in a tabular-like environment. By the way: Why are you trying to use vertical lines at all?
    – Mico
    Jun 18, 2017 at 7:15
  • 1
    @Shaggi3 I completely agree with Mico. If you don't want to follow our advice, you can use \midrule\addlinespace[-.5pt] but I don't recommend it at all. Jun 18, 2017 at 7:21
  • ok i guess the best solution here might be to remove the vertical lines @Mico
    – Shaggi3
    Jun 18, 2017 at 7:52

You must log in to answer this question.

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