2

I have two tables which are side-by-side and am having difficulty centering the first table underneath the "X" and centering the second table underneath the "Y". I'm getting the feeling I'm a little off the mark with my approach but any suggestions would be greatly appreciated.

\documentclass{article}
\begin{document}
  \begin{table}[!ht]
    \begin{center}
        \begin{tabular}{cc}
            \multicolumn{2}{c}{XYZ} \\
            X & Y \\
            \hline \\       
            \begin{tabular}{|c|c|c|}
                \hline          
                1 & 2 & 3 \\
                \hline
                4 & 5 & 6 \\
                \hline
                7 & 8 & 9 \\
                \hline 
            \end{tabular}               
            \begin{tabular}{|c|c|}
                \hline          
                1 & 4 \\
                \hline
                2 & 5 \\
                \hline      
                3 & 6 \\
                \hline              
            \end{tabular}
        \end{tabular}
    \end{center}
\end{table}
\end{document}
1
  • 1
    You to to add an & between the two tabulars. Jul 13, 2014 at 17:35

2 Answers 2

2

perhaps you have missed & between the two inner tabeles , You want a table like this enter image description here

and you change

\documentclass{article}
\begin{document}
  \begin{table}[!ht]
    \begin{center}
        \begin{tabular}{cc}
            \multicolumn{2}{c}{XYZ} \\
            X & Y \\
            \hline \\       
            \begin{tabular}{|c|c|c|}
                \hline          
                1 & 2 & 3 \\
                \hline
                4 & 5 & 6 \\
                \hline
                7 & 8 & 9 \\
                \hline 
            \end{tabular}    
            & %This is what it must be added          
            \begin{tabular}{|c|c|}
                \hline          
                1 & 4 \\
                \hline
                2 & 5 \\
                \hline      
                3 & 6 \\
                \hline              
            \end{tabular}
        \end{tabular}
    \end{center}
\end{table}
\end{document}
0

Here is a shorter code, with only one tabular environment, using booktabs and hhline:

    \documentclass{article}

    \usepackage{array, booktabs, hhline}

    \begin{document}

    \begin{table}[!ht]
    \centering
    \begin{tabular}{|c|c|c| >{\qquad}c|c|c|}
        \multicolumn{6}{c}{XYZ} \\
        \multicolumn{3}{c}{X} & \multicolumn{1}{c} {}& \multicolumn{2}{c}{Y} \\
        \midrule
        \noalign{\vskip 2ex}
        \hhline{---~|--}
            1 & 2 & 3 &   & 1 & 4\\
        \hhline{---~|--}
            4 & 5 & 6 &   & 2 & 5 \\
        \hhline{---~|--}
            7 & 8 & 9  &  &3 & 6 \\
        \hhline{---~|--}
    \end{tabular}
    \end{table}

    \end{document} 

enter image description here

You must log in to answer this question.

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