0

enter image description here

I am trying to create the table below, someone please help.

3
  • 2
    Welcome to TeX SX! There's no table below…
    – Bernard
    Aug 22, 2016 at 17:38
  • 2
    @Bernard: It's actually in the middle now ;-)
    – user31729
    Aug 22, 2016 at 17:42
  • 1
    A very basic question without a minimal effort to go through any introductory material.
    – Diaa
    Aug 22, 2016 at 18:08

2 Answers 2

3

This post will probably be closed as it is a duplicate of a lot of others answers, doesn't show any research-effort and is basicly a question regarded as "Do my work for me".

You should have a look at same basic LaTeX-examples, books etc. Have a look at Getting Started with TeX, LaTeX, and Friends (Tug.org) for multiple great starter-tips.

Anyway, here is part of what you were looking for:

Output

enter image description here

Code

\documentclass{article}
\usepackage{booktabs}
\begin{document}

  \begin{table}
    \begin{tabular}{ccccc}
        \toprule
        & \multicolumn{2}{c}{Y} &   \multicolumn{2}{c}{Y} \\
        \addlinespace
        & X & X & X & X \\
        \midrule
        A & 1 & 2 & 5 & 6 \\
        B & 2 & 4 & 7 & 8 \\
        \bottomrule
      \end{tabular}
    \end{table}

  \end{document}
2

I guess you're trying to learn how to use the \multicolumn directive correctly. The following code presents three possible solutions.

The solutions try to adhere to the format suggested in screenshot you've posted. Do note that tables which feature lots of vertical and horizontal lines are quite unappealing visually. Moreover, they tend to be needlessly hard to fathom by your readers. Consider @RunarTrollet's approach instead.

enter image description here

\documentclass{article}
\usepackage{array} % for \newcolumntype and \extrarowheight macros
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\begin{document}

\begin{table}
\setlength\extrarowheight{2.5pt} % for a (slightly!) more "open" look...

%% Version 1: Use five "c" columns
\begin{tabular}{|*{5}{c|}}
\cline{2-5}
\multicolumn{1}{c|}{} & \multicolumn{2}{c|}{Y} & \multicolumn{2}{c|}{Y} \\
\cline{2-5}
\multicolumn{1}{c|}{} & X & X & X & X \\
\hline
A & 1 & 2 & 5 & 6 \\
\hline
B & 2 & 4 & 7 & 8\\
\hline
\end{tabular}

%% Version 2: Use five "C" columns, each column is 1cm wide
\bigskip\bigskip
\begin{tabular}{|*{5}{C{1cm}|}}
\cline{2-5}
\multicolumn{1}{c|}{} & \multicolumn{2}{c|}{Y} & \multicolumn{2}{c|}{Y} \\
\cline{2-5}
\multicolumn{1}{c|}{} & X & X & X & X \\
\hline
A & 1 & 2 & 5 & 6 \\
\hline
B & 2 & 4 & 7 & 8\\
\hline
\end{tabular}

%% Version 3: Use five "C" columns, each column is 2cm wide
\bigskip\bigskip
\begin{tabular}{|*{5}{C{2cm}|}}
\cline{2-5}
\multicolumn{1}{c|}{} & \multicolumn{2}{c|}{Y} & \multicolumn{2}{c|}{Y} \\
\cline{2-5}
\multicolumn{1}{c|}{} & X & X & X & X \\
\hline
A & 1 & 2 & 5 & 6 \\
\hline
B & 2 & 4 & 7 & 8\\
\hline
\end{tabular}

\end{table}
\end{document}
2
  • I tried various examples but got some weird tables but this works. Thanks. Aug 22, 2016 at 18:46
  • 2
    @GregorywantstolearnR, you should probably accept this answer if it solved your problem.
    – Runar
    Aug 25, 2016 at 18:49

You must log in to answer this question.

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