How to merge cells vertically

You can use multirow If you are trying to align four rows of a particular column, put

\multirow{4}{*}{XXX}

in the first row and leave three subsequent rows below empty like

\multirow{4}{*}{XXX} &
                     &
                     &
                     &

Then the contents are vertically aligned.

\documentclass[a4paper,12pt]{article}
\usepackage[margin=2cm]{geometry}
\usepackage{adjustbox}
\usepackage{multirow}

\begin{document}
\begin{table}[h]
\centering
%     \begin{adjustbox}{width=\textwidth,center}
    % \begin{adjustbox}{center}
        \begin{tabular}{lll}
            \hline
            \multirow{4}{*}{XXX} & \multicolumn{1}{l}{XXX} & \multicolumn{1}{l}{XXX} \\\cline{2-3}
                                 & \multicolumn{1}{l}{XXX} & \multicolumn{1}{l}{XXX} \\\cline{2-3}
                                 & \multicolumn{1}{l}{XXX} & \multicolumn{1}{l}{XXX} \\\cline{2-3}
                                 & \multicolumn{1}{l}{XXX} & \multicolumn{1}{l}{XXX} \\\hline
            \ttfamily xxx & \ttfamily xxx & \ttfamily xxx \\                \hline
        \end{tabular}
%     \end{adjustbox}
%     \vspace{ - 05 mm}
    \caption{xxx}
    \label{tab:xxx}
\end{table}


\end{document}

enter image description here


Here is a stripped down version of what you want (I had to get rid of a few things because I didn't know which packages you had loaded and the code wouldn't compile without them):

\begin{table}[h]
        \begin{tabular}{lll}
            \hline
            \multicolumn{1}{l}{XXX} & \multicolumn{1}{l}{XXX} & \multicolumn{1}{l}{XXX} \\\cline{2-3}
             \ttfamily xxx & \ttfamily xxx & \ttfamily xxx \\
            \hline
        \end{tabular}
    \vspace{ -05mm}
    \caption{xxx}
    \label{tab:xxx}
\end{table}

In summary, what you need is the command \cline{2-3} at the end of a line to indicate where the line should start and finish (in this case it starts at column 2 and finishes at column 3).


You can use \multirow to do this!

\multirow{<number of rows>}{<width>}{<text>}

Make sure to include \usepackage{multirow} at the top.

Tags:

Tables