1

I have some trouble creating the a table in my LateX document, do you have any suggestions on how to do it? I have the following table but I need to have a "Value" and "Relative Error" header like in the second example below (with "Relative Error" and "Variance Reduction"). Below each header, I then need "DCE" and "MDCE", how can I do this?

\begin{table}[ht]
\caption{Results}
\centering
\begin{tabular}{c c c c}
\hline\hline
$n$ & True Value & DCE & MDCE  \\ [0.5ex]
\hline
1&50&837&970 \\
2&47&877&230 \\
3&31&25 &415 \\
4 & 35 & 144 & 2356 \\
5 & 45 & 300 & 556 \\ [1ex]
\hline
\end{tabular}
\label{table:tab1}
\end{table}

enter image description here

Desired Table

Thanks in advance!

4
  • 1
    Welcome to TeX.SX! On this site, a question should typically revolve around an abstract issue (e.g. "How do I get a double horizontal line in a table?") rather than a concrete application (e.g. "How do I make this table?"). Questions that look like "Please do this complicated thing for me" tend to get closed because they are either "off topic", "too broad", or "unclear". Please try to make your question clear and simple by giving a minimal working example (MWE): you'll stand a greater chance of getting help.
    – Thorsten
    Commented Apr 14, 2016 at 8:31
  • Look at package siunitx --- it's basically straightforward.
    – Rmano
    Commented Apr 14, 2016 at 8:35
  • Thank you, I will rephrase my question. In the documentation of siunitx, I don't see the possibility of having two header rows like in the above example?
    – Limbo
    Commented Apr 14, 2016 at 8:41
  • You can easily – the problem is it isn't clear where it should be placed, as you have only 4 columns, and no semantic difference (for us) between these columns.
    – Bernard
    Commented Apr 14, 2016 at 8:56

1 Answer 1

2

As Bernard stated above, it is not really clear how this table should look like. But I give you an example which should give you answers on how to solve everything on your own.

The first thing you are asking for are \multicolumns. Nothing exotic... you can find a lot on this on our homepage here. You define the number of columns and the positioning as l, c, or r.

In your case, it would make sense to put a \cline below those mutli-column headers. I strongly recommend to use the package booktabs as this will help you on the spacing part (and you already got rid of the vertical lines, so you are ready to set nice tables like below...). The command is called \cmidrule here. You can change the shortening options, if you like. E.g. \cmidrule(r){1-2}\cmidrule(l){3-4}...

For the double rows, you can just put several \midrules together. Two \toprules would be too thick, I think. In order to keep your tables clear and free from tweaking, I have put your new definition of the "top-rule" into the preamble. If you get tired of double lines later on, just remove that part.

% arara: pdflatex

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{caption}
\renewcommand*{\toprule}{\midrule\midrule}

\begin{document}
\begin{table}[ht]
    \caption{Results}
    \centering
    \begin{tabular}{%
            S[table-format=1.0]
            S[table-format=2.0]
            S[table-format=3.0]
            S[table-format=4.0]
            }
        \toprule
        \multicolumn{2}{c}{Value} & \multicolumn{2}{c}{Relative Error (\si{\percent})}\\
        \cmidrule(rl){1-2} \cmidrule(rl){3-4}
        $n$ & {True Value} & {DCE} & {MDCE}  \\
        \midrule
        1&50&837&970 \\
        2&47&877&230 \\
        3&31&25 &415 \\
        4 & 35 & 144 & 2356 \\
        5 & 45 & 300 & 556 \\ 
        \bottomrule
    \end{tabular}
    \label{table:tab1}
\end{table}
\end{document}

enter image description here

6
  • This is exactly what I was looking for - thank you! :)
    – Limbo
    Commented Apr 14, 2016 at 8:59
  • No double rules, please! ;-) Besides, the \midrule\midrule method is wrong.
    – egreg
    Commented Apr 14, 2016 at 8:59
  • @egreg I've delivered what the customer wants... :-) (What would be the correct syntax for the double \midrule I didn't dare to search for such thing... The spacing above and below looks correct so I see no problem.
    – LaRiFaRi
    Commented Apr 14, 2016 at 9:03
  • @Limbo I am glad to hear that. You are welcome. Take a look into the manual of booktabs! It gives good advice on the typography of tables.
    – LaRiFaRi
    Commented Apr 14, 2016 at 9:04
  • @LaRiFaRi I guess that \toprule should be used for the first rule.
    – egreg
    Commented Apr 14, 2016 at 9:10

You must log in to answer this question.

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