# Horizontal line through table cell

I have a very long, thin table that I'm folding onto itself to make a wider, shorter version. The table has a couple horizontal rules to separate data categories. For example, the original table is like:

-----------------------
| Column A | Column B |
-----------------------
| Data A1  | Data B1  |
| Data A2  | Data B2  |
| ------------------- |
| Data A3  | Data B3  |
...


and I'm wanting it like:

---------------------------------------------------
| Column A | Column B |     | Column A | Column B |
---------------------------------------------------
| Data A1  | Data B1  |     | Data A51 | Data B51 |
| Data A2  | Data B2  |     | Data A52 | Data B52 |
| ------------------- |     | Data A53 | Data B53 |
| Data A3  | Data B3  |     | Data A54 | Data B54 |
...


The problem is I cannot get the desired behavior with the horizontal rules. If I use something like \cmidrule{1-2}, there is a blank row in the right two columns:

---------------------------------------------------
| Column A | Column B |     | Column A | Column B |
---------------------------------------------------
| Data A1  | Data B1  |     | Data A51 | Data B51 |
| Data A2  | Data B2  |     | Data A52 | Data B52 |
| -------------------                             |
| Data A3  | Data B3  |     | Data A53 | Data B53 |
...


I've tried playing with \vspace{-3mm} but I can't find values and a placement that gets the right results. I've also considered not using \cmidrule and fill the left two cells with a horizontal line. Something like

\multicolumn{2}{c}{--------} & Data A53 & Data B53 \\


However, I can't figure out how to make this horizontal line.

-
Welcome to TeX.SX. A tip: If you indent lines by 4 spaces, then they're marked as a code sample. You can also highlight the code and click the "code" button ({}) or hit Ctrl+K. – Claudio Fiandrino Mar 28 '13 at 16:14

You could use \hrulefill in place of your ---- (but the vertical spacing may be rather strange, compared to \cmidrule) or you could use \cline{1-2} which will open up a gap in the other columns. Or (perhaps simplest) you could just use two separate tabular environments side by side.

If you want to control the vertical position of the rule you can use \leaders for example

\leaders\hbox{\rule[0.4em]{.1pt}{0.4pt}}\hfill\mbox{}


The \mbox{} is needed to protect the leaders from \unskip which the tabular code adds to remove white space from the end of the entry.

-
Thanks. Your tip about \hrulefill was close to working for me, but your were right about the vertical spacing being off. It led me to discover \rule which I use as \multicolmn{2}{l}{\rule[0.4em]{7.4cm}{0.4pt}}. The only downside is I have to find the right width manually. It'd be nice to find a way for this to automatically fill the multicolumn. – drs Mar 29 '13 at 16:14
@drs \leaders\hbox{\rule[0.4em]{.1pt}{0.4pt}}\hfill – David Carlisle Mar 29 '13 at 16:26
This doesn't seem to work in a table cell. When wrapping with \leaders\hbox ... \hfill, the rule isn't drawn at all. – drs Mar 31 '13 at 16:18
@drs sorry you need to protect it from \unskip use: \leaders\hbox{\rule[0.4em]{.1pt}{0.4pt}}\hfill\mbox{} – David Carlisle Mar 31 '13 at 16:25
Yes, this worked perfectly. If you want to modify you're answer with this instruction, I'll accept it. For reference, the full commands look like: \multicolumn{2}{@{\extracolsep{\fill}}c@{\hskip 1cm}}{\leaders\hbox{\rule[0.2em]{.1pt}{0.4pt}}\hfill\mbox{}} for rules in the left two columns and \multicolumn{2}{@{\extracolsep{\fill}}c}{\leaders\hbox{\rule[0.2em]{.1pt}{0.4pt‌​}}\hfill\mbox{}} for rules in the right two columns. The \extracolseps and \hskips are necessarily because I have extra spacing between the 2nd and 3rd columns of the table. – drs Mar 31 '13 at 16:48