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.

How to render a double bottom border on a single table cell? In the example table,

\begin{table}[htbp]
\begin{tabular}{|l|r|r|}
\hline
Item  & Sales & Total \\ \hline
Item 1 & 10 &  \\ \hline
Item 1 & 10 & 20 \\ \hline
Item 1 & 10 &  \\ \hline
Item 2 & 10 &  \\ \hline
Item 2 & 10 & 30 \\ \hline
\end{tabular}
\end{table}

I would like to place a double border under the cells containing 20 and 30 to delimit a group sub total?

share|improve this question

2 Answers 2

up vote 10 down vote accepted

Typically one could use hhline to modify the horizontal rule within a tabular, allowing a mixture of single and double lines. However, the output in your case is not very desirable. Here's an alternative, showing a modified version of your input (using booktabs) first with \hhline and then without (and some other tricks):

enter image description here

\documentclass{article}
\usepackage{booktabs,hhline}% http://ctan.org/pkg/{booktabs,hhline}
\begin{document}
\begin{tabular}{lrr}
  \toprule
  Item  & Sales & Total \\
  \midrule
  Item 1 & 10 &    \\
  Item 1 & 10 & 20 \\ \hhline{--=}
  Item 1 & 10 &    \\
  Item 2 & 10 &    \\
  Item 2 & 10 & 30 \\ \hhline{--=}
\end{tabular}

\bigskip

\begin{tabular}{lrr}
  \toprule
  Item  & Sales & Total \\
  \midrule
  Item 1 & 10 &    \\
  Item 1 & 10 & 20 \\ \hline \\[\dimexpr-\normalbaselineskip+\arrayrulewidth+1pt]
    \cline{3-3}
  Item 1 & 10 &    \\
  Item 2 & 10 &    \\
  Item 2 & 10 & 30 \\ \hline \\[\dimexpr-\normalbaselineskip+\arrayrulewidth+1pt]
    \cline{3-3}
\end{tabular}
\end{document}

The second option inserts a regular \hline followed by a 1pt gap and \cline{3-3} (modify 1pt for a different gap). More specifically, \dimexpr allows for an expression of dimensions, jumping back (vertically upward) a full baseline skip (-\normalbaselineskip) and then forward (vertically downward) the default width of the rule (\arrayrulewidth, typically 0.4pt) plus 1pt.

I'm sure another technique would also suffice; this just seemed the most straight forward. This is mainly based on style, so there are other options as well.

The later option needs some additional hacking when using vertical borders also,

enter image description here

\documentclass{article}
\begin{document}
\begin{tabular}{|l|r|r|}
  Item  & Sales & Total \\
  Item 1 & 10 &    \\
  Item 1 & 10 & 20 \\ \hline 
  & & \\[\dimexpr-\normalbaselineskip+\arrayrulewidth+1pt] \cline{3-3}
  Item 1 & 10 &    \\
  Item 2 & 10 &    \\
  Item 2 & 10 & 30 \\ \hline 
  \multicolumn{1}{l}{} & \multicolumn{1}{l}{} & \multicolumn{1}{l}{} 
  \\[\dimexpr-\normalbaselineskip+\arrayrulewidth+1pt] \cline{3-3}
\end{tabular}
\end{document}
share|improve this answer
    
The second option, works great in long table environment also. @werner you might just want to explain what \\[\dimexpr-\normalbaselineskip+\arrayrulewidth+1pt] does? –  entropy Dec 28 '12 at 19:05
    
@entropy Here, \normalbaselineskip is the height of the textline you add by \\. Using \dimexpr we calculate a good negative height to input to get the desired output. –  tohecz Dec 28 '12 at 19:11

hhline is designed to make such partial lines easy to produce:

enter image description here

\documentclass{article}

\usepackage{hhline}

\begin{document}

\begin{table}[htbp]
\begin{tabular}{|l|r|r|}
\hline
Item  & Sales & Total \\ \hline
Item 1 & 10 &  \\ \hline
Item 1 & 10 & 20 \\ \hhline{|-|-|=|}
Item 1 & 10 &  \\ \hline
Item 2 & 10 &  \\ \hline
Item 2 & 10 & 30 \\ \hhline{|-|-|=|}
\end{tabular}
\end{table}

\end{document}
share|improve this answer

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.