在这个 MWE 中,我希望虚线图案关于右侧中心对称。
此外,经过一些实验后,代码仍然不起作用,所以我想知道它出了什么问题。
\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\tikzset{domain/.style={
append after command={
\pgfextra{
\draw[dash pattern={on 7pt off 2pt on 1pt off 2pt}] (\tikzlastnode.north east) -- (\tikzlastnode.south east);
\draw[] (\tikzlastnode.south east) -| (\tikzlastnode.north west) -- (\tikzlastnode.north east);
}}}}
\begin{tikzpicture}
\node at (3,0) [domain, minimum size = 3cm] (eq) {$y=mx+c$};
\draw[black, thick, ->] (eq.west) -- ++(-40pt,0pt) node[above ,align=center, ]{text};
\end{tikzpicture}
\end{document}
答案1
您需要选择一个除 之外的名称domain
,因为该名称已被使用。我不确定您为什么特别希望破折号居中,但这里有一种方法:
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\tikzset{my domain/.style={
append after command={
\pgfextra{
\draw (\tikzlastnode.east) +(0,.5pt) -- +(0,-1pt) +(0,-2pt) |- (\tikzlastnode.south west) |- (\tikzlastnode.north east) -- ([yshift=1.5pt]\tikzlastnode.east);
}}}}
\begin{tikzpicture}
\node at (3,0) [my domain] (eq) {$y=mx+c$};
\draw[black, thick, ->] (eq.west) -- ++(-40pt,0pt) node[above ,align=center, ]{text};
\end{tikzpicture}
\end{document}
编辑
如果需要显示整个图案以适应更大的节点,只需将图纸切成两部分:
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\tikzset{my domain/.style={
append after command={
\pgfextra{
\draw (\tikzlastnode.east) ++(0,.5pt) -- ++(0,-1pt) ++(0,-2pt) edge [dash pattern=on 7pt off 2pt on 1pt off 2pt] (\tikzlastnode.south east) (\tikzlastnode.south east) -| (\tikzlastnode.north west) -- (\tikzlastnode.north east);
\draw [dash pattern=on 7pt off 2pt on 1pt off 2pt] (\tikzlastnode.east) ++(0,2.5pt) -- (\tikzlastnode.north east);
}}}}
\begin{tikzpicture}
\node at (3,0) [my domain, align=center] (eq) {$y=mx+c$\\a\\b};
\draw[black, thick, ->] (eq.west) -- ++(-40pt,0pt) node[above ,align=center, ]{text};
\draw[black, thick, ->] (eq.east) -- ++(40pt,0pt) node[above ,align=center, ]{text};
\end{tikzpicture}
\end{document}