下図のような「複雑な」図形を描きたいです。
何をする必要があるか:
\hdashline
穴の幅に合わせて拡大します(赤で描かれています)- 最初の行から破線(
:
)を削除します(片手ずつ行います)
MWE:
\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}
アップデート:
2番目の配列に2行以上(例えば3行や4行)が含まれている場合も、この方法は機能するはずです。
何をする必要があるか:
:
最初の行(上図の緑の四角形)から破線( )を削除します。- どういうわけか、
\draw[dashed,green]
とは\hline
まったく同じy座標を持っていない - ヘルパーはなぜか空白を追加する
- ハードコードされた線幅を置き換える
コード:
\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}
補遺:
まだ、テーブルがどのように表示されるかわかりません。質問を編集した後、ノードの 2 番目の部分のテーブルには任意の数の行を含めることができ、行の記号に整列した方程式を配置したいのだと思います=
。たとえば、次のようになります。
この場合、私の最初の提案では望ましい結果は得られません。次の変更を加える必要があります。
tabularx
代わりに環境を使用するarray
the
等式を符号˙= tabularx`で整列させるには4つの列が必要ですノードの幅を定義する
\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}