Change border of a few cells in a table

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.


This is more of a rant rather than an answer.

I do wish LaTeX had a table mechanism that separated content from presentation. For example, this is how one would achieve the same effect in ConTeXt:

\startsetups table:highlight
  \setupTABLE[each][each][align=middle,loffset=2pt, roffset=2pt]
  \setupTABLE[row][first][style=bold]
  \setupTABLE[row][3,4]  [rulethickness=2pt]
\stopsetups

\starttext
\startTABLE[setups=table:highlight]
  \NC ID        \NC Raw Score \NC Num \NC Total Hits \NC    Avg   \NC \NR
  \NC 217842950 \NC 8282      \NC   9 \NC      10059 \NC 0.176658 \NC \NR 
  \NC 264307945 \NC 7700      \NC  13 \NC      11076 \NC 0.304803 \NC \NR
  \NC 436114131 \NC 1540      \NC   6 \NC       1773 \NC 0.131416 \NC \NR 
  \NC 546694115 \NC 1460      \NC   6 \NC       1685 \NC 0.133531 \NC \NR 
  \NC 467026458 \NC 1058      \NC  36 \NC       1237 \NC 0.144705 \NC \NR
\stopTABLE
\stoptext

enter image description here

Behind the scenes, ConTeXt is doing something similar to Gonzalo Medina's solution. But it provides a nice key-value driven interface that hides the details from the user.

Tags:

Tables