3

I'm little new in LateX. What I want to achieve is to make overbrace over two columns in 3-column table. I mean that I don't want to make overbrace over whole neither one column.

For now I got this:

\begin{tabular}{c | p{2cm} | c@{,} l}
\multicolumn{2}{c}{$overbrace{Col1 | Col2}$} & \multicolumn{2}{c}{Col3} \\
R1C1 & R1C2 & 1&24123
R2C1 & R2C2 & 12&3123
\end{tabular}

I think that solution could be simple but I can't get it. Have any ideas?

1

2 Answers 2

1

Here’s one way you could do it. I’ve simplified the structure of your table a bit, just to make what follows clearer. (BTW, you were missing a \\ at the end of your first row.)

% name a new length:
\newlength{\TwoColumnWidth}

% set it to the width of the first two columns:
\settowidth{\TwoColumnWidth}{%
\begin{tabular}{ll}
R1C1 & R1C2\\
R2C1 & R2C2\\
\end{tabular}}

% create a zero-width box on the left of your table:
\makebox[0pt][l]{%
% put the contents of the box high enough to sit above the table:
\raisebox{2ex}{%
% fill the box with your overbrace of the previously specified length:
$\overbrace{\hspace{\TwoColumnWidth}}$}}%
% and then put your table in (making sure to align it at the top `[t]`):
\begin{tabular}[t]{llll}
R1C1 & R1C2 & 1&24123\\
R2C1 & R2C2 & 12&3123
\end{tabular}

enter image description here


Two other comments:

Many publishing houses avoid vertical lines in tables. Strict left margins make them redundant. For a better quality of table, check out booktabs.sty, which, in fact, makes vertical lines slightly unreliable.

For your particular table, I think things look better if you kill the default spacing around the edge of the columns relevant to the overbrace. I.e., using:

\settowidth{\TwoColumnWidth}{\begin{tabular}{@{}ll@{}}

and

\begin{tabular}[t]{@{}llll}

enter image description here


Later edit

I don’t know whether it’s relevant for your purposes, but I’ll just comment on a difference between your initial sketch (which BeUndead followed up on) and my response. Essentially, it has to do with the baseline of the top row of the table relative to the text. Going about as I’ve suggested keeps the same baseline for the text and for the top row of the table. Putting the brace in the top row of the table aligns the brace with the normal text. Not sure if that matters for you:

enter image description here

If you put the brace in the table, you still probably want to reduce the space underneath it, using a square-bracketed height after \\:

\multicolumn2{@{}c@{}}{$\overbrace{\hspace{\TwoColumnWidth}}$}\\[-.8ex]%
0

Here's another way to do it, might need you to mess around a little bit when you use it, but shouldn't be too difficult:

\documentclass{article}

    \usepackage{multirow}

\begin{document}

    \begin{table}[h]
        \centering
        \begin{tabular}{ c|c|c|c }
            \multicolumn{2}{c}{$\overbrace{\rule{2.6cm}{0pt}}$}  &  \multicolumn{2}{c}{}  \\
            Col1  &  Col2  &  \multicolumn{2}{c}{Col3}  \\
            R1C1  &  R1C2  &  R1C3  &  R1C4  \\
            R2C1  &  R2C2  &  R2C3  &  R2C4
        \end{tabular}
    \end{table}

\end{document}

Which would give something along the lines of (ignore ugly over brace, poor choice of zoom-level on document my end):

Overbrace over multiple columns

Not the answer you're looking for? Browse other questions tagged .