0

enter image description here

I am trying to write the table but not succeeded. How can I write the attached table in LaTeX.

Please see the table. I am trying to write this table in LaTeX but not succeeded.

  • 3
    Welcome to TeX.SE! (1) Where is the attached table? (2) Please add an MWE to help us help you! –  Mar 10 '19 at 05:28
  • 3
    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. – Stefan Pinnow Mar 10 '19 at 06:25
  • 1
  • 1
    Please don't downvote below a score of -1, even if the question in its current form needs some improvement. A score of -1 is enough to show that the question needs work, anything below that is of no use. Also, if you downvote or vote to close, please leave a comment explaining why you did so, but wait at least 24 hours after asking the OP for improvements to the question before voting to close. – Mensch Mar 10 '19 at 07:44

2 Answers2

4

Your table would look more professional using booktabs.

I've used \makecell in the multi-rows for a better vertical alignment.

Next time you ask, please add a minimal example of what you tried.

Edit: I've also added TeXnician's more elegant solution with the first two columns swapped, and another solution with rows and columns switched

\documentclass{article}
\usepackage{array}
\renewcommand{\arraystretch}{1.1}
\newcolumntype{C}{>{\centering\arraybackslash}p{1em}}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{makecell}
\usepackage{caption}

\begin{document}
\begin{table}[htb]
    \centering    
    \caption{My professional table\label{tab:my_label}}
    \begin{tabular}{*{7}{c}}
    \toprule
    \multirow{2}{*}{Observation} & \multirow{2}{*}{Class} & \multicolumn{5}{c}{Binary attributes} \\
    \cmidrule(lr){3-7}
    & & $b_1$ & $b_2$ & $b_3$ & $b_4$ & $b_5$\\
    \midrule
    1 & \multirow{4}{*}{\makecell{(Positive)\\$\Omega^+$}} & 1 & 1 & 1 & 0 & 0 \\
    2 & & 1 & 1 & 1 & 1 & 1 \\
    3 & & 1 & 0 & 1 & 1 & 0 \\
    4 & & 1 & 1 & 1 & 1 & 0 \\
    \midrule
    5 & \multirow{4}{*}{\makecell{(Negative)\\$\Omega^-$}} & 1 & 0 & 1 & 0 & 0 \\
    6 & & 0 & 0 & 0 & 0 & 0 \\
    7 & & 0 & 0 & 1 & 0 & 0 \\
    8 & & 1 & 0 & 0 & 0 & 0 \\
    \bottomrule
    \end{tabular}
\end{table}
\begin{table}[htb]
    \centering    
     \caption{A professional table (\TeX nician's suggestion)\label{tab:tex_label}}
    \begin{tabular}{l*{6}{c}}
    \toprule
    Class & Observation & \multicolumn{5}{c}{Binary attributes} \\
    \cmidrule(lr){3-7}
    & & $b_1$ & $b_2$ & $b_3$ & $b_4$ & $b_5$\\
    \midrule
    (Positive) $\Omega^+$ & 1 & 1 & 1 & 1 & 0 & 0 \\
    & 2 & 1 & 1 & 1 & 1 & 1 \\
    & 3 & 1 & 0 & 1 & 1 & 0 \\
    & 4 & 1 & 1 & 1 & 1 & 0 \\
    \midrule
    (Negative) $\Omega^-$ & 5 & 1 & 0 & 1 & 0 & 0 \\
    & 6 & 0 & 0 & 0 & 0 & 0 \\
    & 7 & 0 & 0 & 1 & 0 & 0 \\
    & 8 & 1 & 0 & 0 & 0 & 0 \\
    \bottomrule
    \end{tabular}
\end{table}
\begin{table}[htb]
    \centering    
    \caption{Another kind of professional table\label{tab:other_label}}
    \begin{tabular}{c*{8}{C}}
    \toprule
     & \multicolumn{8}{c}{Class}\\
    & \multicolumn{4}{c}{(Positive) $\Omega^+$} & \multicolumn{4}{c}{(Negative) $\Omega^-$}\\
    \cmidrule(lr){2-5}\cmidrule(lr){6-9}
    \multirow{2}{*}{\makecell{Binary\\ attributes}} & \multicolumn{8}{c}{Observation}\\
     & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\
    \cmidrule(lr){1-1}\cmidrule(lr){2-5}\cmidrule(lr){6-9}
    $b_1$ & 1 & 1 & 1 & 1 & 1 & 0 & 0 & 1 \\
    $b_2$ & 1 & 1 & 0 & 1 & 0 & 0 & 0 & 0 \\
    $b_3$ & 1 & 1 & 1 & 1 & 1 & 0 & 1 & 0 \\
    $b_4$ & 0 & 1 & 1 & 1 & 0 & 0 & 0 & 0 \\
    $b_5$ & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\
    \bottomrule
    \end{tabular}
\end{table}
\end{document}

enter image description here

enter image description here

CarLaTeX
  • 62,716
1

To give you a start. I am using this answer. You will have to correct the binary numbers, I just put 1 everywhere.

\documentclass{article}
\usepackage{xcolor}
\usepackage{array}
\usepackage{colortbl}
\usepackage{booktabs}
\usepackage{multirow}
\begin{document}
\setlength{\aboverulesep}{-0.45pt} \setlength{\belowrulesep}{-0.45pt}
\begin{tabular}{*{7}{|c}|}
\hline
\rowcolor{gray!50} & & \multicolumn{5}{c|}{Binary attributes} \\[2pt]
\cmidrule[0.8pt]{3-7}
\rowcolor{gray!50}
\multirow{-2}{*}{ Observation} & 
\multirow{-2}{*}{Class}& $b_1$ & $b_2$ & $b_3$ & $b_4$ & $b_5$\\
\hline
1 & & 1 & 1 & 1 & 1 & 1 \\
2 & (Positive) & 1 & 1 & 1 & 1 & 1 \\
3 &\multirow{2}{*}{$\Omega^*$} & 1 & 1 & 1 & 1 & 1 \\
4 & & 1 & 1 & 1 & 1 & 1 \\[1pt]
\midrule
\vphantom{$1^|$}5 & & 1 & 1 & 1 & 1 & 1 \\
6 & (Negative) & 1 & 1 & 1 & 1 & 1 \\
7 &\multirow{2}{*}{$\Omega^-$} & 1 & 1 & 1 & 1 & 1 \\
8 & & 1 & 1 & 1 & 1 & 1 \\
\hline
\end{tabular}
\end{document}

enter image description here