2

Can someone help with code this table in LaTeX?

enter image description here

1

2 Answers 2

4

A couple of solutions, with or without vertical rules:

\documentclass[a4paper]{article}
\usepackage{amsmath}
\usepackage{array}
\usepackage{multirow}
\newcolumntype{L}{>{$}l<{$}}
\newcolumntype{C}{>{$}c<{$}}
\renewcommand*{\arraystretch}{1.4}
\usepackage{caption}

\begin{document}
Table~\ref{yours} is as your image.
\begin{table}
    \centering
    \caption{Categorical classification of variables\label{yours}}
    \begin{tabular}{|LL|LL|C|C|}
        \cline{5-6}
        \multicolumn{4}{c|}{}& \multicolumn{2}{C|}{Y_{i}}\\
        \hline
        \multicolumn{4}{|c|}{}&\text{Yes $(1)$}& \text{No $(0)$} \\
        \hline
        \multicolumn{2}{|c|}{}&\multicolumn{1}{c}{}& 1 & a & b \\
        \cline{4-6}
        \multirow{2}{*}{$X_{i}$} & 0 & X_{i_{1}} & 2 & c & d \\
        \cline{2-6}
        & 1 & X_{i_{2}} & 1 & e & f \\
        \cline{4-6} 
        &&& 2 & g & h \\ 
        \hline
    \end{tabular}
\end{table}
Table~\ref{mine} is without vertical rules.
\begin{table}
    \centering
    \caption{Categorical classification of variables\label{mine}}
    \begin{tabular}{LLLLCC}
        \multicolumn{4}{c}{}& \multicolumn{2}{C}{Y_{i}}\\
        \cline{5-6}
        \multicolumn{4}{c}{}&\text{Yes $(1)$}& \text{No $(0)$} \\
        \hline
        \multicolumn{2}{c}{}&\multicolumn{1}{c}{}& 1 & a & b \\
        \cline{4-6}
        \multirow{2}{*}{$X_{i}$} & 0 & X_{i_{1}} & 2 & c & d \\
        \cline{2-6}
        & 1 & X_{i_{2}} & 1 & e & f \\
        \cline{4-6} 
        &&& 2 & g & h \\ 
        \hline
    \end{tabular}
\end{table}
\end{document}

enter image description here

If the cell content is plain text instead of in math mode, just change L and C (the new column types I created) into l and c.

0
1

A simple way is to use the package multirow (http://ftp.fau.de/ctan/macros/latex/contrib/multirow/multirow.pdf) and if needed tabularx. It provides the possibilities to combine cells in a row or column.

Edit: A code example (sry for forgetting that). It's not the hole table but it should give a feeling what to do with multicolumn and multirow.

\documentclass{scrartcl}
\usepackage{multirow}

\begin{document}
  \begin{tabular}{ll|ll|}
    \cline{3-4}
  & & \multicolumn{2}{c|}{$Y$}\\
  \multirow{3}{*}{X} & & &a\\\cline{4-4}
  & & &b \\ \cline{4-4}
  & & &c \\ \cline{4-4}
  \end{tabular}
\end{document}
1
  • 4
    That sounds like a good idea. And even though the the question does not have a lot of code in it, your answer could definitely benefit from expansion and a code example. At the moment it feels more like a comment.
    – moewe
    Nov 17, 2017 at 9:26

You must log in to answer this question.

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