4

How do I go about creating the following table in tikz?

table

\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{16}{*}{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.}\\
            &Inner index 3.4 & \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.5 & \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.6 & \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}
whoami
  • 49
  • 6
  • 8
    Welcome to TeX-SE! Could you please explain why you want to redraw the table in TikZ? –  Mar 20 '19 at 18:06
  • Thanks, @marmot I've been told that it allows for greater freedom, and since I'm having trouble doing things like vertically centering the first two columns, I thought I'd give this a try. – whoami Mar 20 '19 at 18:08
  • 4
    I would like to argue that using something like makecell will make it much more straightforward to vertically center the stuff. Of course, there are things for which you may want to use TikZ but IMHO not for that. –  Mar 20 '19 at 18:34
  • @marmot Wishing I had this in TikZ now: https://tex.stackexchange.com/questions/480602/saving-table-as-png – whoami Mar 21 '19 at 00:27

1 Answers1

2

If the effort you need for creating such tables in tabular or tabularx is 10, the effort you need for creating them in TikZ or any other drawing packages is at least 100. Anyway this is your table in a TikZ version.

Note: Customizing it is a very hard problem IMHO, because you will probably have to break all loops... Therefore, please make tables in a usual way!

\documentclass[tikz]{standalone}
\def\innersep{.3333em}
\begin{document}
\begin{tikzpicture}[every node/.style={line width=0pt,text centered}]
\node[minimum height=6*\baselineskip+2*\innersep] (c1-r1) {Output index 1}; % The origin
\draw (c1-r1.south) node[below,minimum height=6*\baselineskip+2*\innersep] (c1-r2) {Output index 2};
\draw (c1-r2.south) node[below,minimum height=18*\baselineskip+6*\innersep] (c1-r3) {Output index 3};
\foreach \i in {1,2} {
    \draw (c1-r\i.north east) node[below right,minimum height=3*\baselineskip+\innersep] (c2-r\i-1) {Inner index \i.1};
    \draw (c1-r\i.south east) node[above right,minimum height=3*\baselineskip+\innersep] (c2-r\i-2) {Inner index \i.2};
    \foreach \j/\k in {2/3,3/4} {
        \draw (c\j-r\i-1.east) node[right,minimum height=3*\baselineskip-\innersep,text width=4cm,align=left] (c\k-r\i-1) {Text data placeholder. May be long enough that it needs to be wrapped.};
        \draw (c\j-r\i-2.east) node[right,minimum height=3*\baselineskip-\innersep,text width=4cm,align=left] (c\k-r\i-2) {Text data placeholder. May be long enough that it needs to be wrapped.};
    }
}
\draw (c1-r3.north east) node[below right,minimum height=3*\baselineskip+\innersep] (c2-r3-1) {Inner index 3.1};
\foreach \i/\j in {2/3,3/4} {
    \draw (c\i-r3-1.east) node[right,minimum height=3*\baselineskip-\innersep,text width=4cm,align=left] (c\j-r3-1) {Text data placeholder. May be long enough that it needs to be wrapped.};
}
\foreach \i/\j in {2/1,3/2,4/3,5/4,6/5} {
    \draw (c2-r3-\j.south) node[below,minimum height=3*\baselineskip+\innersep] (c2-r3-\i) {Inner index 3.\i};
    \draw (c2-r3-\i.east) node[right,minimum height=3*\baselineskip+\innersep,text width=8cm+2*\innersep,align=left] (c3-r3-\i) {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.};
}
% Lines
\foreach \i in {1,2,3} \draw (c1-r\i.north west)--(c4-r\i-1.north east);
\draw (c1-r3.south west)--(c3-r3-6.south east);
\end{tikzpicture}
\end{document}

enter image description here