49

Is it possible to create a table like this one?

enter image description here

The usual structure of tables I use looks like this:

\begin{table}[H]
    \begin{adjustbox}{width=\textwidth,center}
    % \begin{adjustbox}{center}
        \begin{tabular}{lll}
            \hline
            \multicolumn{1}{l}{\head{XXX}} & \multicolumn{1}{l}{\head{XXX}} & \multicolumn{1}{l}{\head{XXX}} \\
            \hline
            \ttfamily xxx & \ttfamily xxx & \ttfamily xxx \\
            \hline
        \end{tabular}
    \end{adjustbox}
    \vspace{ - 05 mm}
    \caption{xxx}
    \label{tab:xxx}
\end{table}
  • 1
    Isn't what you want actually to merge cells vertically? – Vivi Sep 17 '12 at 20:07
  • Ahh, you are right. Just changed. :D – eualin Sep 17 '12 at 20:09
  • You may want to check the examples in wikibooks on merging cells. You may want to use the multirow command for cells spanning multiple rows. – mythealias Sep 17 '12 at 20:57
57

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

  • How can I do it with the TexStudio tables wizard? – skan Dec 1 '16 at 17:26
3

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).

  • OK. I think I got it. But how to align the left-hand side element to the centre? – eualin Sep 17 '12 at 20:31
  • Align it vertically to the centre you mean? This construct doesn't give a way to do that. I think you can tweak it to give the result you want, but in the example you gave this doesn't even make sense. I suggest you give a better example in your question (more rows so that alignment is an issue), but to be honest, I am pretty sure there is a way to actually merge the cells, instead of just dealing with the lines, I just don't know it. – Vivi Sep 17 '12 at 20:50
1

You can use \multirow to do this!

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

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

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.