Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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)

share|improve this question
1  
Can you show some minimal code that you tried so far. It will save us from some extra typing and guessing work. –  Harish Kumar May 23 '12 at 0:04
    
Thick lines are covered in How can I reproduce this table with thick lines?. –  Peter Grill May 23 '12 at 0:14
    
You can use the method I described in my answer. –  Gonzalo Medina May 23 '12 at 0:18
add comment

2 Answers

up vote 7 down vote accepted

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.

share|improve this answer
    
oh, those last two examples really need a bit more "air" above the contents of the cells; the thick rules are touching, or even slightly overprinting, the digits. it would also be more attractive (though more complicated) to divide the thickness of the horizontal rules between the cells above and below; this is most obvious when the rule doesn't extend across the entire table. –  barbara beeton May 23 '12 at 13:28
    
@barbarabeeton right again ;-) I added some extra vertical space to the rows. I'll prepare an example using you other suggestion (the one about dividing the thickness of the rule). –  Gonzalo Medina May 23 '12 at 17:14
    
This is exactly what I am looking for. One last thing though, how does one center the above table in the document? –  ngramsky May 24 '12 at 2:37
    
@ngramsky: use \centering right after the \begin{table*} line; I'll add it to my code. –  Gonzalo Medina May 24 '12 at 2:39
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.