4

Using multi row and multi column, how can I generate the following table in latex?

Required table

What I got so far:

\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{tabular}{|l|l|l|l|l|l|l|l|l|l|l|l|}\hline
  \multirow{1}{*}{Test}  &  & Image 1 & I2 & I3 & I4 & I5 & I6 & I7 & I8 & I9 & I10 \\ \cline{1-12}
  \multirow{2}{*}{1}
  & \multirow{1}{*}{A} & x & x & x & x & x & x & x & x & x & x \\ \cline{2-12}
  & \multirow{1}{*}{B} & x & x & x & x & x & x & x & x & x & x \\ \cline{1-12}
  \multirow{2}{*}{2}
  & \multirow{1}{*}{A} & x & x & x & x & x & x & x & x & x & x \\ \cline{2-12}
  & \multirow{1}{*}{B} & x & x & x & x & x & x & x & x & x & x \\ \cline{1-12}
  \multirow{2}{*}{3}
  & \multirow{1}{*}{A} & x & x & x & x & x & x & x & x & x & x \\ \cline{2-12}
  & \multirow{1}{*}{B} & x & x & x & x & x & x & x & x & x & x \\ \cline{1-12}
  \multirow{2}{*}{4}
  & \multirow{1}{*}{A} & x & x & x & x & x & x & x & x & x & x \\ \cline{2-12}
  & \multirow{1}{*}{B} & x & x & x & x & x & x & x & x & x & x \\ \cline{1-12}
  \multirow{2}{*}{5}
  & \multirow{1}{*}{A} & x & x & x & x & x & x & x & x & x & x \\ \cline{2-12}
  & \multirow{1}{*}{B} & x & x & x & x & x & x & x & x & x & x \\ \cline{1-12}
  \multirow{2}{*}{6}
  & \multirow{1}{*}{A} & x & x & x & x & x & x & x & x & x & x \\ \cline{2-12}
  & \multirow{1}{*}{B} & x & x & x & x & x & x & x & x & x & x \\ \cline{1-12}
  \multirow{2}{*}{7}
  & \multirow{1}{*}{A} & x & x & x & x & x & x & x & x & x & x \\ \cline{2-12}
  & \multirow{1}{*}{B} & x & x & x & x & x & x & x & x & x & x \\ \cline{1-12}
\end{tabular}
\end{document}
10

2 Answers 2

1
\documentclass[10pt,letterpaper]{article}

\usepackage{multirow}
\usepackage{hhline}
\usepackage{ctable}
\begin{document}
    \begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|}\hline\hline\omit\vline
        \strut\multirow{1}{*}{ Test\phantom{\LARGE H}} 
        & \multirow{1}{*}{} & Image 1\phantom{\LARGE H}%
 & I2 & I3 & I4 & I5 & I6 & I7 & I8%
     & I9 & I10 \\ \hline\hline
        \multirow{2}{*}{1}
        & \multirow{1}{*}{A} & x & x & x & x & x & x & x & x & x & x \\%
     \cline{2-12}
        & \multirow{1}{*}{B} & x & x & x & x & x & x & x & x & x & x \\%
     \specialrule{.2em}{.1em}{.1em}
        \multirow{2}{*}{2}
        & \multirow{1}{*}{A} & x & x & x & x & x & x & x & x & x & x \\%
          \cline{2-12}
        & \multirow{1}{*}{B} & x & x & x & x & x & x & x & x & x & x \\%
          \specialrule{.2em}{.1em}{.1em}
        \multirow{2}{*}{3}
        & \multirow{1}{*}{A} & x & x & x & x & x & x & x & x & x & x \\%
          \cline{2-12}
        & \multirow{1}{*}{B} & x & x & x & x & x & x & x & x & x & x \\%
          \specialrule{.2em}{.1em}{.1em}
        \multirow{2}{*}{4}
        & \multirow{1}{*}{A} & x & x & x & x & x & x & x & x & x & x \\%
          \cline{2-12}
        & \multirow{1}{*}{B} & x & x & x & x & x & x & x & x & x & x \\%
          \specialrule{.2em}{.1em}{.1em}
        \multirow{2}{*}{5}
        & \multirow{1}{*}{A} & x & x & x & x & x & x & x & x & x & x \\%
          \cline{2-12}
        & \multirow{1}{*}{B} & x & x & x & x & x & x & x & x & x & x \\%
          \specialrule{.2em}{.1em}{.1em}
        \multirow{2}{*}{6}
        & \multirow{1}{*}{A} & x & x & x & x & x & x & x & x & x & x \\%
          \cline{2-12}
        & \multirow{1}{*}{B} & x & x & x & x & x & x & x & x & x & x \\%
          \specialrule{.2em}{.1em}{.1em}
        \multirow{2}{*}{7}
        & \multirow{1}{*}{A} & x & x & x & x & x & x & x & x & x & x \\%
          \cline{2-12}
        & \multirow{1}{*}{B} & x & x & x & x & x & x & x & x & x & x \\%
              \hline\hline
    \end{tabular}
\end{document}

![enter image description here

1
  • thanks.. but how to merge the empty cell at the top left with the cell 'test'. Also, how can I format the borders as I have shown in the initial figure? Thanks
    – Muzammil
    Commented May 9, 2016 at 5:18
2

To make the label "Test" span two columns, write \multicolumn{2}{|c|}{Test}.

To reduce some of the code clutter, I recommend you replace all seven instances of \multirow{1}{*}{A} with A, and that you also replace all instances of \multirow{1}{*}{B} with B. And, please write \hline instead of \cline{1-12}.

Assuming that the cells in columns 3 through 12 will eventually be filled with more material than just X's, it will almost certainly be necessary to typeset the table "sideways," i.e., in landscape mode, on a page by itself.

I would honestly not bother replicating the look of the double lines present in the screenshot you've posted. Instead, I would work hard to get rid of all vertical lines and most horizontal lines.

\documentclass{article}
\usepackage{multirow,rotating}
\begin{document}

\begin{sidewaystable}  % if necesssary
\renewcommand\arraystretch{1.25}
\centering
\begin{tabular}{|*{12}{c|}}
\hline
\multicolumn{2}{|c|}{Test}  
    & Image 1 & Image 2 & Image 3 & Image 4 & Image 5 
    & Image 6 & Image 7 & Image 8 & Image 9 & Image 10 \\ \hline
\multirow{2}{*}{1}
  & A & x & x & x & x & x & x & x & x & x & x \\ \cline{2-12}
  & B & x & x & x & x & x & x & x & x & x & x \\ \hline
\multirow{2}{*}{2}
  & A & x & x & x & x & x & x & x & x & x & x \\ \cline{2-12}
  & B & x & x & x & x & x & x & x & x & x & x \\ \hline
\multirow{2}{*}{3}
  & A & x & x & x & x & x & x & x & x & x & x \\ \cline{2-12}
  & B & x & x & x & x & x & x & x & x & x & x \\ \hline
\multirow{2}{*}{4}
  & A & x & x & x & x & x & x & x & x & x & x \\ \cline{2-12}
  & B & x & x & x & x & x & x & x & x & x & x \\ \hline
\multirow{2}{*}{5}
  & A & x & x & x & x & x & x & x & x & x & x \\ \cline{2-12}
  & B & x & x & x & x & x & x & x & x & x & x \\ \hline
\multirow{2}{*}{6}
  & A & x & x & x & x & x & x & x & x & x & x \\ \cline{2-12}
  & B & x & x & x & x & x & x & x & x & x & x \\ \hline
\multirow{2}{*}{7}
  & A & x & x & x & x & x & x & x & x & x & x \\ \cline{2-12}
  & B & x & x & x & x & x & x & x & x & x & x \\ \hline
\end{tabular}
\end{sidewaystable} % if necessary
\end{document}
1
  • Oh okay so I'll skip the boarders.. thanks a lot for your help
    – Muzammil
    Commented May 9, 2016 at 6:28

You must log in to answer this question.

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