我想画一个“复杂”的图形,如下所示。
需要做什么:
- 放大
\hdashline
以适合孔宽(以红色绘制) :
从第一行删除虚线( )(每只手完成)
梅威瑟:
\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 行),这也应该有效
需要做什么:
- 删除第一行的虚线(
:
)(上图中的绿色矩形) - 不知何故
\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}
附录:
我仍然不确定你的表格应该是什么样子。现在,在编辑了你的问题之后,我猜测,节点第二部分中的表格可以有任意数量的行,并且你喜欢在符号处按行对齐方程式=
。例如像这样:
在这种情况下,我的第一个建议并没有给出预期的结果。您需要进行以下更改:
- 改用
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}