1

I am trying to construct the table as sketched out below. The placements of X denote entries of the table. How do I construct such a table in latex? I am happy to start to use the multirows package as follows:

   \begin{table}[h]
   \begin{center}
   \begin{tabular}{|c|c|c|c|c|c|c|}
   \hline \\
   \multirow{2}{*}{X} & \multicolumn{2}{c|}{X} & \multicolumn{2}{|c|}{X} & \multicolumn{2}{|c|}{X}\\
   \cline{2-7}
   &X & X & X & X & X & X \\
   \hline \\
   X & & & & & X & X \\
   \hline \\
   X & X & X & & & X & X \\

However, here the column lines don't join - is there a problem with the code above? enter image description here

2

The following combination of \multirow and \multicolumn might get you started:

enter image description here

\documentclass{article}
\usepackage{multirow}

\begin{document}

\begin{tabular}{|l|c|c|}
\hline
xxxxxxx & \multicolumn{2}{c|}{x} \\
\hline
\multicolumn{1}{|r|}{xxx} & x &\multirow{2}{*}{x}\\
\cline{1-2}
\multicolumn{1}{|r|}{xxx} & x &\\
\hline
xxx & x &\multirow{2}{*}{x}\\
\cline{1-2}
xxx & x &\\
\hline
\multicolumn{1}{|r|}{xxx} & x &\multirow{2}{*}{x}\\
\cline{1-2}
\multicolumn{1}{|r|}{xxx} & x &\\
\hline
\end{tabular}

\end{document}
1
  • Thanks, actually upon upload my diagram was rotated and I never noticed. I've tried to construct the table I wish to draw (edited in my post) using what I read from your answer. However, there is an issue with all the column lines and rows joining up - do you know if I have a problem with my code or is this a separate issue? – CAF Mar 10 '20 at 22:55
2

You have \\ on both side of the \hline-command. That is wrong. Use \arraystretch and \extrarowheight to add height to the rows.

If you need more column width, you can use fixed width w-columns from the array package (wc{1cm}). Also, you add vertical rules command (|) in multicolumn only at the right side of the column definition, i.e. c|, except if the multicolumn spans the first column:

enter image description here

\documentclass{article}
\usepackage{array, multirow}

\setlength{\extrarowheight}{2pt}
\renewcommand*{\arraystretch}{1.2}

\begin{document}

   \begin{table}[tbh!]
\centering
   \begin{tabular}{|c|c|c|c|c|c|c|}
   \hline
   \multirow{2}{*}{X} & \multicolumn{2}{c|}{X} & \multicolumn{2}{c|}{X} & \multicolumn{2}{c|}{X}\\
  \cline{2-7}
   &X & X & X & X & X & X \\
   \hline
   X &   &   &   &   & X & X \\
   X & X & X &   &   & X & X \\
   X & X & X &   &   & X & X \\
   X & X & X & X & X & X & X \\
   X & X & X & X & X & X & X \\
   X & X & X & X & X &   &   \\
   X &   &   & X & X &   &   \\
   X &   &   & X & X &   &   \\
\hline

\end{tabular}
\end{table}

\end{document} 
1
  • You have terminated \hline with row terminate \\. Don't do this!
  • Your table is not complete (missed is its end)

Bot those problem are addressed in @leandriis answer (+19. Many experts here for table design usually suggest "don't lock table contents in prison of vertical and horizontal lines. A step to "liberate" cells contents you can find in Sveinung answer (+1). Further step in this direction (for completeness of answers) is in MWE below, where are removed all vertical lines and for really necessary horizontal ones are used rules from the booktabs package:

enter image description here

\documentclass{article}
\usepackage{booktabs, multirow}
\newcommand\mcc[1]{\multicolumn{2}{c}{#1}}

\begin{document}  
   \begin{table}[tbh!]
\centering % instead `\begin{center} which introduce additional vertical space
\renewcommand*{\arraystretch}{1.1}
   \begin{tabular}{ *{7}{c} }
   \toprule
\multirow{2.4}{*}{X} & \mcc{XXX} & \mcc{XXX} & \mcc{XXX}\\
   \cmidrule(l){2-3}\cmidrule(l){4-5}\cmidrule(l){6-7}
  & XX & XX & XX & XX & XX & XX \\
   \midrule
XX &    &    &    &    & XX & XX \\
XX & XX & XX &    &    & XX & XX \\
XX & XX & XX &    &    & XX & XX \\
    \addlinespace
XX & XX & XX & XX & XX & XX & XX \\
XX & XX & XX & XX & XX & XX & XX \\
XX & XX & XX & XX & XX &    &    \\
    \addlinespace
XX &    &    & XX & XX &    &    \\
XX &    &    & XX & XX &    &    \\
   \bottomrule
\end{tabular}
    \end{table}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.