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}
JMP
  • 3,238
Muzammil
  • 105
  • 2
    A very warm welcome to TeX.SE! You should really try something, and present what you have tried as a minimum working example, a WME(http://meta.tex.stackexchange.com/questions/3343/what-makes-a-good-mwe). For instance, lots of questions can get you started http://tex.stackexchange.com/questions/238503/tip-on-how-to-make-a-visually-good-table http://tex.stackexchange.com/questions/236281/how-to-make-such-a-nice-table-in-latex http://tex.stackexchange.com/questions/58647/how-to-make-table-with-divided-column http://tex.stackexchange.com/questions/22856/how-to-merge-columns-in-a-table – A Feldman May 09 '16 at 03:28
  • Thanks you @AFeldman. I have put the code in the post. Please let me know how can I 1) put the text in center in all cells, 2) format the specific borders as in the figure, and 3) merge the two top most left cells? Thanks. – Muzammil May 09 '16 at 04:59
  • Your example should compile... – A Feldman May 09 '16 at 05:07
  • What do you mean? It does compile and give me a very close table. – Muzammil May 09 '16 at 05:11
  • When you make a WME you should have everything needed to fully compile. That included begin document, end document, and all packages required to compile. – A Feldman May 09 '16 at 05:14
  • 2
    oh I just edited the post with full code. – Muzammil May 09 '16 at 05:15
  • Ok, good. I merged the top most left cells in my answer and centered your cells. – A Feldman May 09 '16 at 05:26
  • Thanks a lot for your help, I'm really grateful. Can you also just help me on the last thing: formatting the borders? I'm really thankful to you. – Muzammil May 09 '16 at 05:30
  • Someone will come along who will know how to do that also, and then you can pick that as the answer. Off the top of my head I'm not sure how to accomplish that. – A Feldman May 09 '16 at 05:32
  • Formatted the borders in my answer. – A Feldman May 09 '16 at 20:17

2 Answers2

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}
Mico
  • 506,678
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

A Feldman
  • 3,930
  • 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 May 09 '16 at 05:18