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.

I want to build a table like this:

table

I have tried a code but it doesn't work properly:

\begin{table}[htp]
\caption{The temporal outlier detection accuracy of hourly mean values with respect to the MFs in 2007-09-30}
    \label{tab:todh30}
            \centering
                \footnotesize\setlength{\tabcolsep}{2.5pt}
\begin{tabular}{|c|c|c|c|c|c|c|c|c|}
\hline
Node ID   & \multicolumn{2}{c|}{Density-based} \\ \cline{2-3} & \multicolumn{2}{c|}{Mahalanobis distance-based} \\ \cline{2-3} & \multicolumn{2}{c|}{Running average-based} \\ \cline{2-3}
    & DR\%  &  FPR\% \\  \hline & DR\%  &  FPR\% \\ \hline  & DR\%  &  FPR\% \\ \hline
25   & 100    & 71      \\  \hline  & 100    & 71      \\  \hline  & 100    & 60      \\ \hline
28 & 100    & 57     \\ \hline   & 100    & 57      \\ \hline  & 66    & 60      \\ \hline
29   & 100    & 62      \\ \hline   & 100    & 57      \\  \hline  & 100    & 50      \\ \hline
31   & 100    & 57      \\  \hline & 50    & 66      \\ \hline   & 66   & 60      \\ \hline
32   & 100    & 71      \\  \hline  & 100    & 66      \\  \hline & 100    & 66      \\ \hline
    \end{tabular}
\end{table}
share|improve this question

closed as too localized by doncherry, Guido, T. Verron, Stefan Kottwitz Feb 1 '13 at 7:04

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
It would be best if you could show what you've tried so far... have you looked at the questions tagged with table? –  cmhughes Jan 24 '13 at 23:20

2 Answers 2

up vote 2 down vote accepted

I made a small example which shows the basic commands that you'll need.

Explanations

  • tabular is the standard environment for tables in LaTeX that does not require extra packages
  • the second argument is number and also the type of columns, in this case |c|c|c|, which means that we have 3 centered lines seperated by a vertical line (|).
  • \hline inserts a line over the whole table width
  • \cline inserts a line under a range of given columns, here \cline{2-3}, so we have a line under all colums from 2 to 3 (2 and 3 included)
  • probably the most important: \multicolumn{2}{c|}{some text}:
    • the first argument gives the number of columns over which the cell will stretch
    • the second argument specifies the type of column (as before), in case your wondering why you need c| just try it without | then it should be clear
    • the last argument is the text you wish to have in this particular cell
  • IMPORTANT with \\ you end the line and enter a new line, so don't use it if you still want to add colums, instead of rows

Code

\documentclass{article}

\begin{document}

\begin{tabular}{|c|c|c|}
\hline
n   & \multicolumn{2}{c|}{Running average-based} \\ \cline{2-3}
    & DR\%  &  FPR\% \\ \hline
6   & 19    & 1      \\ \hline
TOD & 72    & 11     \\ \hline
\end{tabular}

\end{document}

Result

image

Here also a improved version of your code.

\documentclass{article}

\begin{document}

\begin{table}[htp]
\caption{The temporal outlier detection accuracy of hourly mean values with respect to the MFs in 2007-09-30}
\label{tab:todh30}
\centering
\footnotesize\setlength{\tabcolsep}{2.5pt}
\begin{tabular}{|c|c|c|c|c|c|c|c|c|}
\hline
Node ID   & \multicolumn{2}{c|}{Density-based}  & \multicolumn{2}{c|}{Mahalanobis distance-based}  & \multicolumn{2}{c|}{Running average-based} \\ \cline{2-7}

   & DR\%   &  FPR\%  & DR\%   &  FPR\%  & DR\%   &  FPR\%  \\ \hline
25 & 100    & 71      & 100    & 71      & 100    & 60      \\ \hline
28 & 100    & 57      & 100    & 57      & 66     & 60      \\ \hline
29 & 100    & 62      & 100    & 57      & 100    & 50      \\ \hline
31 & 100    & 57      & 50     & 66      & 66     & 60      \\ \hline
32 & 100    & 71      & 100    & 66      & 100    & 66      \\ \hline
\end{tabular}
\end{table}

\end{document}

Resulting in

image2

share|improve this answer
    
I have tried your code, but i had problem with it. Plz guide me on the matter. –  ali amidi Jan 25 '13 at 0:46
    
I added some explanations which hopefully provide guidance. –  xfoo Jan 25 '13 at 7:26
    
@aliamidi I also added an improved version of the code you gave in your question, now it should work as you can see in the second image. –  xfoo Jan 25 '13 at 7:46

This can be a good starting point and you can modify it based on your needs:

\documentclass{article}

\begin{document}
    \begin{tabular}{|l||l|l||l|l|}
    \hline
     &\multicolumn{2}{l|}{A}&\multicolumn{2}{l|}{B}\\
    \cline{2-5}
     n&A1&\textbf{A2}&B1&\textbf{B2}\\
    \hline\hline
    0&3&\textbf{7}&11&\textbf{15}\\
    1&4&\textbf{8}&12&\textbf{16}\\
    2&5&\textbf{9}&13&\textbf{17}\\
    3&6&\textbf{10}&14& \\
    \hline
    \end{tabular}
\end{document}

enter image description here

Credits to http://www.maths.tcd.ie for their template.

share|improve this answer

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