# Table with merged cells, multi-index and text wrap

I'd like to have a table that looks like this. Here's a link to open the image in another tab.

What matters to me is the structure. The formatting is just to show what I'd like to stand out from the rest in some way.

How do I:

1. Make sure text is wrapped when the data has over a specific length.
2. Use a multicolumn for the bottom right cells, as per the image?

Here's what I have:

\documentclass[11pt]{article}
\usepackage{multirow}
\begin{document}
% Text data placeholder. May be long enough that it needs to be wrapped.
\begin{table}[ht]
\begin{center}
\begin{tabular}{cccc}
\hline
\multirow{2}{*}{Outer index 1} & Inner index 1.1 & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
& Inner index 1.2 & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
\hline
\multirow{2}{*}{Outer index 2} & Inner index 2.1 & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
& Inner index 2.2 & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
\hline
\multirow{6}{*}{Outer index 3} &  Inner index 3.1 & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
&Inner index 3.2 & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
&Inner index 3.3 & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
&Inner index 3.4 & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
&Inner index 3.5 & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
&Inner index 3.5 & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
&Inner index 3.6 & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
\hline
\end{tabular}
\end{center}
\end{table}

\end{document}


• Welcome to TeX.SE! I think multicolumn is what you want. Anyway, please add a minimal working example. – user156344 Mar 20 at 13:06
• Welcome to TeX.SX! Could you please add a minimal working example (MWE) of what you have acmoplished so far to illustrate your problem? – leandriis Mar 20 at 13:06
• @whoami: Please add the code directly to your question (by using the edit button). Content from external sites might be removed in the future which makes a question that relies on externally shown code unusable for future readers. – leandriis Mar 20 at 14:38
• @leandriis My code wasn't a minimal example yet, that's why I didn't add it to the question. I now have a minimal example and I'm about to add it. Thank you for your guideance. – whoami Mar 20 at 14:39
• @whoami: I have removed the pgfplotstable and threeparttable tags from your question as you do not use the corresponding packages in your MWE. – leandriis Mar 20 at 15:34

The following includes:

• tabularx for X type columns and a table that fits the textwidth
• \multicolumn for the cells spanning 2 columns
• adjusted values of \multirow to vertically center the text in the first column
• replaced center environment by \centering as the former adds additional white space around the table
• used horizontal lines from the booktabs package for improved spacing.

\documentclass[11pt]{article}

\usepackage{multirow}
\usepackage{geometry}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{ragged2e}
\begin{document}

\begin{table}[ht]
\centering
\begin{tabularx}{\textwidth}{cc>{\RaggedRight\arraybackslash}X>{\RaggedRight\arraybackslash}X}
\toprule
\multirow{6}{*}{Outer index 1} & Inner index 1.1 & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
& Inner index 1.2 & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
\midrule
\multirow{6}{*}{Outer index 2} & Inner index 2.1 & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
& Inner index 2.2 & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
\midrule
\multirow{9}{*}{Outer index 3} &  Inner index 3.1 & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
&Inner index 3.2 & \multicolumn{2}{>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth\relax\RaggedRight\arraybackslash}X}{Text data placeholder. May be long enough that it needs to be wrapped.  Text data placeholder. May be long enough that it needs to be wrapped.}\\
&Inner index 3.3 & \multicolumn{2}{>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth\relax\RaggedRight\arraybackslash}X}{ Text data placeholder. May be long enough that it needs to be wrapped.  Text data placeholder. May be long enough that it needs to be wrapped.}\\
\bottomrule
\end{tabularx}
\end{table}

\end{document}


Here, I have also used multirow for the contents of the second column:

\documentclass[11pt]{article}

\usepackage{multirow}
\usepackage{geometry}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{ragged2e}
\begin{document}

\begin{table}[ht]
\centering
\begin{tabularx}{\textwidth}{cc>{\RaggedRight\arraybackslash}X>{\RaggedRight\arraybackslash}X}
\toprule
\multirow{6}{*}{Outer index 1} & \multirow{3}{*}{Inner index 1.1} & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
& \multirow{3}{*}{Inner index 1.2} & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
\midrule
\multirow{6}{*}{Outer index 2} & \multirow{3}{*}{Inner index 2.1} & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
& \multirow{3}{*}{Inner index 2.2} & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
\midrule
\multirow{9}{*}{Outer index 3} &  \multirow{3}{*}{Inner index 3.1} & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
& \multirow{3}{*}{Inner index 3.2} & \multicolumn{2}{>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth\relax\RaggedRight\arraybackslash}X}{Text data placeholder. May be long enough that it needs to be wrapped.  Text data placeholder. May be long enough that it needs to be wrapped.}\\
& \multirow{3}{*}{Inner index 3.3} & \multicolumn{2}{>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth\relax\RaggedRight\arraybackslash}X}{ Text data placeholder. May be long enough that it needs to be wrapped.  Text data placeholder. May be long enough that it needs to be wrapped.}\\
\bottomrule
\end{tabularx}
\end{table}

\end{document}


In oder to vertically center the text in the second column, you could also use the makecell package in combination with vertically centered X type columns as shown in the following MWE:

\documentclass[11pt]{article}

\usepackage{multirow}
\usepackage{geometry}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{ragged2e}
\usepackage{makecell}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\begin{document}

\begin{table}[ht]
\centering
\begin{tabularx}{\textwidth}{cc>{\RaggedRight\arraybackslash}X>{\RaggedRight\arraybackslash}X}
\toprule
\multirow{6}{*}{Outer index 1} & \makecell[cc]{Inner index 1.1} & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
& \makecell[cc]{Inner index 1.2} & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
\midrule
\multirow{6}{*}{Outer index 2} & \makecell[cc]{Inner index 2.1} & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
& \makecell[cc]{Inner index 2.2} & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
\midrule
\multirow{9}{*}{Outer index 3} &  \makecell[cc]{Inner index 3.1} & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
& \makecell[cc]{Inner index 3.2} & \multicolumn{2}{>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth\relax\RaggedRight\arraybackslash}X}{Text data placeholder. May be long enough that it needs to be wrapped.  Text data placeholder. May be long enough that it needs to be wrapped.}\\
& \makecell[cc]{Inner index 3.3} & \multicolumn{2}{>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth\relax\RaggedRight\arraybackslash}X}{ Text data placeholder. May be long enough that it needs to be wrapped.  Text data placeholder. May be long enough that it needs to be wrapped.}\\
\bottomrule
\end{tabularx}
\end{table}

\end{document}

• Thanks! Is there a way to vertically center the first two columns? – whoami Mar 20 at 16:29
• For the contents of the second column use \multirow{3}{*}{<your text>}. If you add more rows you might need to adjust the number in the first argument of multirow in the first column accordingly. – leandriis Mar 20 at 16:32
• Isn't that what is already being done? They aren't centered for me. – whoami Mar 20 at 17:51
• @whoami: I have added a second MWE showing how to vertically center the contents of the second column. I have also added images of the output I obtain from the two different examples. – leandriis Mar 20 at 18:37
• Thanks. But won't this potentially fail to be centered when the text is different? Because the text I'm using is different and I don't want to rely on my very bad eyes to assess what value centers the indices. – whoami Mar 20 at 19:01