將矩形分割與陣列結合起來

將矩形分割與陣列結合起來

我想畫一個「複雜」的圖形,如下圖。

需要做什麼:

  1. 放大\hdashline以適合孔寬度(以紅色繪製)
  2. :從第一行刪除虛線 ( )(每手完成)

微量元素:

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes.multipart}

\usepackage{amsmath}
\usepackage{arydshln}

\begin{document}

\begin{tikzpicture}
\node[rectangle split,rectangle split parts=2, draw, inner sep=+0pt] {
$\begin{array}{l|l|l}
n & loooooooooooooong & m\\
\end{array}$
\nodepart{two}
$\begin{array}{l@{{}={}}l:l@{{}={}}l}
a & 0  & b & 0\\
\hdashline
c & 0 & d & 0\\
\end{array}$};
\end{tikzpicture}

\end{document}

輸出

更新:

如果第二個陣列包含多於兩行(例如 3 或 4),這也應該有效

需要做什麼:

  1. 刪除虛線(:)(上圖的綠色矩形)
  2. 不知怎的,\draw[dashed,green]\hliney 座標不完全相同
  3. 幫助者以某種方式添加空格
  4. 替換硬編碼的線寬

代碼:

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes.multipart,calc}

\usepackage{amsmath}
\usepackage{arydshln}

\begin{document}

\begin{tikzpicture}
\node (n) [rectangle split,rectangle split parts=2, draw, inner sep=+0pt] {
$\begin{array}{l|l|l}
n & loooooooooooooong & m\\
\end{array}$
\nodepart{two}
$\begin{array}{l@{{}={}}l:l@{{}={}}l}
a & 0  & b & 0\\
\hline %only for position control
c & 0 & d & 0\\
c & 0 & d & 0\\
c & 0 & d & 0\\
\end{array}$};

%helper
\node[inner sep=0] (two north west) at ($(n.text split west)-(0,0.2pt)$) {}; %hardcoded
\node[inner sep=0] (two south west) at ($(n.south west)+(0,0.4pt)$) {}; %hardcoded
\node[inner sep=0] (two north east) at ($(n.text split east)-(0,0.2pt)$) {}; %hardcoded
\node[inner sep=0] (two south east) at ($(n.south east)+(0,0.4pt)$) {}; %hardcoded

\draw[dashed,green] ($(two south west)!0.75!(two north west)$) -- ($(two south east)!0.75!(two north east)$);

\end{tikzpicture}

\end{document}

我使用助手,因為a!0.75!b+c似乎被解釋為(a!0.75!b)+c我無法做類似的事情a!0.75!(b+c)

答案1

像這樣:

在此輸入影像描述

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}
\usepackage{amsmath}
\usepackage{arydshln}

\begin{document}
    \begin{tikzpicture}
\node (n) [rectangle split,rectangle split parts=2, draw,
           inner ysep=0pt] {
$    \begin{array}{ c|c|c }
n & loooooooooooooong & m\\
     \end{array}$
\nodepart{two}
$    \begin{array}{ r:l }
a = 0   & b = 0\\
c = 0   & d = 0\\
\end{array}$
    };
\draw[dashed] (n.two west) -- (n.two east); % <-- horizontal dashed line
    \end{tikzpicture}
\end{document}

附錄: 我仍然不確定你的桌子應該是什麼樣子。現在,編輯您的問題後,我猜測,節點第二部分中的表可以有任意數量的行,並且您希望在符號處的行中對齊方程式=。例如這樣:

在此輸入影像描述

在這種情況下,我的第一個建議沒有給出預期的結果。您需要在其中進行以下更改:

  • 使用tabularx環境代替array
  • 為了在符號˙= tabularx`處對齊方程式the需要四列
  • 定義節點的寬度

    \documentclass{standalone}
    \usepackage{tikz}
    \usetikzlibrary{shapes.multipart}
    \usepackage{tabularx}
    \usepackage{arydshln}
    \newlength\tabwidth     % for defining node width
    
    \begin{document}
        \begin{tikzpicture}
    \settowidth\tabwidth{$\begin{array}{l|l|l}      % calculating node width
                            n & loooooooooooooong & m\\
                          \end{array}$}
    \node (n) [rectangle split,rectangle split parts=2, draw, inner sep=0pt] {
    $\begin{array}{l|l|l}
    n & loooooooooooooong & m\\
    \end{array}$
    \nodepart{two}
    \begin{tabularx}{\tabwidth}{@{}                 % table width is equal to node width
        >{\raggedleft\arraybackslash $}X<{$}@{$\,=\,$}
        >{\raggedright\arraybackslash$}X<{$}:
        >{\raggedleft\arraybackslash $}X<{$}@{$\,=\,$}
        >{\raggedright\arraybackslash$}X<{$}
                                 @{}}
        a & 0 & b & 1234\\
        \hdashline
      abc & 0 & d & 0\\
        \hdashline
     abcd & 0 & d & 0\\
        \hdashline
        c & 0 & d & 0\\
    \end{tabularx}
        };
        \end{tikzpicture}
    \end{document}
    

答案2

這更像是一則評論,但評論太長了。人們可以在沒有硬編碼距離的情況下繪製線條。

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes.multipart,calc}

\usepackage{amsmath}
\usepackage{arydshln}

\begin{document}

\begin{tikzpicture}
\node (n) [rectangle split,rectangle split parts=2, draw, inner sep=+0pt] {
$\begin{array}{l|l|l}
n & loooooooooooooong & m\\
\end{array}$
\nodepart{two}
$\begin{array}{l@{{}={}}l:l@{{}={}}l}
a & 0  & b & 0\\
\hline %only for position control
c & 0 & d & 0\\
c & 0 & d & 0\\
c & 0 & d & 0\\
\end{array}$};
\pgfmathtruncatemacro{\NumRows}{4}
\foreach \X in {1,...,\numexpr\NumRows-1} % \numexpr trick from https://tex.stackexchange.com/a/477077/121799
{\coordinate (aux-\X) at ($(n.text split)!\X/\NumRows!(n.south)$);
\draw [blue,dashed] (aux-\X-|n.west) -- (aux-\X-|n.east);
}
\end{tikzpicture}
\end{document}

在此輸入影像描述

相關內容