[Tex/LaTex] Change border of a few cells in a table

tables

Let's say I have a table with 4 columns and 8 rows. The top row is the label for each of the rows below. Suppose I want the cell borders for rows 4 and 5 to be thicker than the rest of the cells in the table. Is there a way to accomplish this in LaTeX?

\begin{table*}[ht]
{\normalsize
\hfill{}
\large
\begin{tabular}{|c|c|c|c|c|}
\hline \bf ID & \bf Raw Score & \bf Num & \bf Total Hits & \bf Avg \\ 
\hline 217842950 & 8282 & 9 & 10059 & 0.176658 \\ 
\hline 264307945 & 7700 & 13 & 11076 & 0.304803 \\ 
\hline 111824111 & 6170 & 16 & 9467 & 0.348262 \\ 
\hline 331180650 & 1705 & 31 & 2668 & 0.360945 \\ 
\hline 436114131 & 1540 & 6 & 1773 & 0.131416 \\ 
\hline 546694115 & 1460 & 6 & 1685 & 0.133531 \\ 
\hline 467026458 & 1058 & 36 & 1237 & 0.144705 \\ 
\hline 
\end{tabular} }
\hfill{}
\caption{Scores for the top-7 IDs .}
\label{tb:tablename}
\end{table*}

Above is the table I have. I'm unsure how I would even go about changing the border around any row (or cell)

Best Answer

Here you have a simple example; the idea is to use \noalign{\hrule height <length>} instead of \hline to get a horixontal rule of thickness given by <length>; for a vertical rule, not spanning the whole table, the idea is to use \multicolumn and in the second argument to use !{\vrule width <length>} instead of | to get a vertical rule of thickness given by <length> for that cell (the array package is required for this last construction):

\documentclass{article}
\usepackage{array}

\begin{document} 

\begin{tabular}{|c|c|}
\hline
column1a & column2a \\
\noalign{\hrule height 2pt}
\multicolumn{1}{!{\vrule width 2pt}c!{\vrule width 1pt}}{column1b} & 
  \multicolumn{1}{!{\vrule width 1pt}c!{\vrule width 2pt}}{column2b} \\
\noalign{\hrule height 2pt}
column1c & column2c \\
\hline
\end{tabular}

\end{document}

enter image description here

And here's an example with your table:

\documentclass{article}
\usepackage{array}

\begin{document} 

\begin{table*}
{\normalsize
\hfill{}
\large
\begin{tabular}{|c|c|c|c|c|}
\hline \bf ID & \bf Raw Score & \bf Num & \bf Total Hits & \bf Avg \\ 
\hline 217842950 & 8282 & 9 & 10059 & 0.176658 \\ 
\hline 264307945 & 7700 & 13 & 11076 & 0.304803 \\ 
\noalign{\hrule height 2pt}
\multicolumn{1}{!{\vrule width 2pt}c!{\vrule width 1pt}}{111824111} & 
  \multicolumn{1}{!{\vrule width 1pt}c!{\vrule width 1pt}}{6170} & 
  \multicolumn{1}{!{\vrule width 1pt}c!{\vrule width 1pt}}{16} & 
  \multicolumn{1}{!{\vrule width 1pt}c!{\vrule width 1pt}}{9467} & 
  \multicolumn{1}{!{\vrule width 1pt}c!{\vrule width 2pt}}{0.348262} \\ 
\noalign{\hrule height 2pt}
\multicolumn{1}{!{\vrule width 2pt}c!{\vrule width 1pt}}{331180650} & 
  \multicolumn{1}{!{\vrule width 1pt}c!{\vrule width 1pt}}{1705} & 
  \multicolumn{1}{!{\vrule width 1pt}c!{\vrule width 1pt}}{31} & 
  \multicolumn{1}{!{\vrule width 1pt}c!{\vrule width 1pt}}{2668} & 
  \multicolumn{1}{!{\vrule width 1pt}c!{\vrule width 2pt}}{0.360945} \\ 
\noalign{\hrule height 2pt}
 436114131 & 1540 & 6 & 1773 & 0.131416 \\ 
\hline 546694115 & 1460 & 6 & 1685 & 0.133531 \\ 
\hline 467026458 & 1058 & 36 & 1237 & 0.144705 \\ 
\hline 
\end{tabular} }
\hfill{}
\caption{Scores for the top-7 IDs .}
\label{tb:tablename}
\end{table*}

\end{document}

enter image description here

Of course, you can define macros such as:

\newcommand\Thickvrule[1]{%
  \multicolumn{1}{!{\vrule width 2pt}c!{\vrule width 1pt}}{#1}%
}

and then use

\Thickvrule{6170}

in your document.

For just some cells, a variant of \cline with the desired thickness can be defined:

\documentclass{article}
\usepackage{array}

\newlength\Origarrayrulewidth
\newcommand{\Cline}[1]{%
  \noalign{\global\setlength\Origarrayrulewidth{\arrayrulewidth}}%
  \noalign{\global\setlength\arrayrulewidth{2pt}}\cline{#1}%
  \noalign{\global\setlength\arrayrulewidth{\Origarrayrulewidth}}%
}

\newcommand\Thickvrule[1]{%
  \multicolumn{1}{!{\vrule width 2pt}c!{\vrule width 2pt}}{#1}%
}

\begin{document} 

\begin{table*}
\setlength\extrarowheight{3pt}
\large
\centering
\begin{tabular}{|c|c|c|c|c|}
\hline \bf ID & \bf Raw Score & \bf Num & \bf Total Hits & \bf Avg \\ 
\hline 217842950 & 8282 & 9 & 10059 & 0.176658 \\ 
\Cline{1-1}\cline{2-5} 
\Thickvrule{264307945} & 7700 & 13 & 11076 & 0.304803 \\ 
\Cline{1-1}\cline{2-4}\Cline{4-4}\cline{4-5}
111824111 & 6170 & 16 & \Thickvrule{9467} & 0.348262 \\ 
\cline{1-4}\Cline{4-4}\cline{4-5}
331180650 & 1705 & 31 & 2668 & 0.360945 \\ 
\hline 436114131 & 1540 & 6 & 1773 & 0.131416 \\ 
\cline{1-2}\Cline{2-2}\cline{3-5}
546694115 & \Thickvrule{1460} & 6 & 1685 & 0.133531 \\ 
\cline{1-2}\Cline{2-2}\cline{3-5}
467026458 & 1058 & 36 & 1237 & 0.144705 \\ 
\hline 
\end{tabular}
\caption{Scores for the top-7 IDs .}
\label{tb:tablename}
\end{table*}

\end{document}

enter image description here And some other macros for the case of more than one cell:

\documentclass{article}
\usepackage{array}

\newlength\Origarrayrulewidth

% horizontal rule equivalent to \cline but with 2pt width
\newcommand{\Cline}[1]{%
 \noalign{\global\setlength\Origarrayrulewidth{\arrayrulewidth}}%
 \noalign{\global\setlength\arrayrulewidth{2pt}}\cline{#1}%
 \noalign{\global\setlength\arrayrulewidth{\Origarrayrulewidth}}%
}

% draw a vertical rule of width 2pt on both sides of a cell
\newcommand\Thickvrule[1]{%
  \multicolumn{1}{!{\vrule width 2pt}c!{\vrule width 2pt}}{#1}%
}

% draw a vertical rule of width 2pt on the left side of a cell
\newcommand\Thickvrulel[1]{%
  \multicolumn{1}{!{\vrule width 2pt}c|}{#1}%
}

% draw a vertical rule of width 2pt on the right side of a cell
\newcommand\Thickvruler[1]{%
  \multicolumn{1}{|c!{\vrule width 2pt}}{#1}%
}

\begin{document} 

\begin{table*}
\setlength\extrarowheight{3pt}
\centering
\large
\begin{tabular}{|c|c|c|c|c|}
\hline \bf ID & \bf Raw Score & \bf Num & \bf Total Hits & \bf Avg \\ 
\hline 217842950 & 8282 & 9 & 10059 & 0.176658 \\ 
\Cline{1-1}\cline{2-5} 
\Thickvrule{264307945} & 7700 & 13 & 11076 & 0.304803 \\ 
\Cline{1-1}\cline{2-4}\Cline{4-4}\cline{4-5}
111824111 & 6170 & 16 & \Thickvrule{9467} & 0.348262 \\ 
\cline{1-4}\Cline{4-4}\cline{4-5}
331180650 & 1705 & 31 & 2668 & 0.360945 \\ 
\cline{1-2}\Cline{2-2}\cline{3-5}
436114131 & \Thickvrule{1540} & 6 & 1773 & 0.131416 \\ 
\cline{1-2}\Cline{2-2}\cline{3-5}
546694115 & 1460 & 6 & 1685 & 0.133531 \\
\Cline{1-5} 
\Thickvrulel{467026458} & 1058 & 36 & 1237 & \Thickvruler{0.144705} \\ 
\Cline{1-5} 
\end{tabular}
\caption{Scores for the top-7 IDs .}
\label{tb:tablename}
\end{table*}

\end{document}

enter image description here

Finally, as a side note, you should consider not using vertical rules in your tables (this is only a suggestion, of course); with the help of the booktabs package you can easily produce beautiful tables.