1

Edit: I have removed the two horizontal lines using \cline(2-9)

Below is the code I have used for my table and the result.

\documentclass{article}
\begin{document}
\begin{center}
\begin{tabular}{c|c|c|c|c|c|c|c|c}
                      1,000 Group
                    & \multicolumn{2}{p{3cm}|} {\centering Cophenetic \\ Correlation}
                    & \multicolumn{2}{p{3cm}|} {\centering Global \\ Comparison}
                    & \multicolumn{2}{p{3cm}|} {\centering Baker's \\ Gamma} 
                    & \multicolumn{2}{p{3cm}} {\centering Fowlkes \\ -Mallows} \\
    \hline
    & \multicolumn{8}{p{15cm}} {\centering 10,000 Group} \\
    \hline
    & G1 & G2 & G1 & G2 & G1 & G2 & G1 & G2 \\
    \hline
    Group 1 & 1 & 2 \\
    Group 2 & 1 & 2 \\
    Group 3 \\
\end{tabular}
\end{center}
\end{document}

enter image description here

I would like to change the following:

  1. Remove the two horizontal lines below '1,000 Group' and centre the text vertically.
  2. Centre '10,000 group ' properly? So far I have just used a random number to centre it.
  3. Make the cells G1 and G2 equally split between each main column.
  • 2
    Is there any reason, in the real document, for choosing p{3cm}? – Bernard Aug 15 '18 at 16:47
  • To center '10,000 group' you can use a \multicolumn{8}{c} – BambOo Aug 15 '18 at 16:53
  • To make cells G1 and G2 equal you have to specify the widths of the main columns since you merge them afterwards for your headers. Do {c|p{1.5cm}|p{1.5cm}|p{1.5cm}|p{1.5cm}|p{1.5cm}|p{1.5cm}|p{1.5cm}|p{1.5cm}} instead of {c|c|c|c|c|c|c|c|c} in your tabular options. It's a bit raw though – BambOo Aug 15 '18 at 16:55
  • @Bernard I wanted to make the width length of all the columns the same – Ali Aug 15 '18 at 17:00
  • @BambOo works very well. How about vertically centering '1,000 Group' along the 4 rows? – Ali Aug 15 '18 at 17:12
1

Based on @Bernard's answer, with additional booktabs features

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[]{geometry}
\usepackage{tabularx, makecell, booktabs}

\begin{document}

%\begin{center}
\setcellgapes{3pt}\makegapedcells
\begin{tabularx}{0.75\linewidth}{c|*{7}{>{\centering\arraybackslash}X}>{\centering\arraybackslash}X}\toprule
                      10,000 Group
                    & \multicolumn{2}{c} {\makecell{Cophenetic \\ Correlation}}
                    & \multicolumn{2}{c} {\makecell{Global \\ Comparison}}
                    & \multicolumn{2}{c}{\makecell{Baker's \\ Gamma}}
                    & \multicolumn{2}{c}{\makecell{Fowlkes \\ -Mallows}} \\ \midrule
    %\hline
    & \multicolumn{8}{c} {10,000 Group} \\ 

    & G1 & G2 & G1 & G2 & G1 & G2 & G1 & G2 \\ \cmidrule(lr){2-9}

    Group 1 & 1 & 2 \\
    Group 2 & 1 & 2 \\
    Group 3 \\ \bottomrule
\end{tabularx}
%\end{center}

\end{document} 

enter image description here

4

Here is a simple solution with tabularx and makecell. However, you shouldn't use vertical and horizontal rules in general. You should take at look at package booktabs provides more professional-looking horizontal rules, with varying thickness and some vertical padding.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[showframe]{geometry}
\usepackage{tabularx, makecell}

\begin{document}

\begin{center}
\setcellgapes{3pt}\makegapedcells
\begin{tabularx}{0.75\linewidth}{c|*{8}{>{\centering\arraybackslash}X|}}
                      1,000 Group
                    & \multicolumn{2}{c|} {\makecell[b]{Cophenetic \\ Correlation}}
                    & \multicolumn{2}{c|} {\makecell[b]{Global \\ Comparison}}
                    & \multicolumn{2}{c|}{\makecell[b]{Baker's \\ Gamma}}
                    & \multicolumn{2}{c|}{\makecell[b]{Fowlkes \\ -Mallows}} \\
    \cline{2-9}
    & \multicolumn{8}{c|} {10,000 Group} \\
    \cline{2-9}
    Group 1 & 1 & 2 \\
    Group 2 & 1 & 2 \\
    Group 3 \\
\end{tabularx}
\end{center}

\end{document} 

enter image description here

  • I shouldn't have crossed out the 'remove two horizontal lines under '10,000 Group' in the question. I confused you guys. Apologies. What I meant to do was say I've managed to remove them. Your answer is good but if you can add \cline(2-8) to remove them and then centre 10,000 Group vertically along the 4 rows that would be of much help – Ali Aug 15 '18 at 17:16

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.