从 table 到 tikz

从 table 到 tikz

我如何在 tikz 中创建下表?

桌子

\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}

答案1

tabular如果在或中创建此类表所需的工作量tabularx为 10,则在 Ti 中创建此类表所需的工作量Z 或任何其他绘图包至少为 100。无论如何,这是你的表在 TiZ 版本。

笔记:我认为定制它是一个非常困难的问题,因为您可能必须打破所有循环......因此,请以通常的方式制作表格!

\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}

在此处输入图片描述

相关内容