我需要一条部分虚线。我已经用一条水平线实现了这一点,方法是插入一个节点删除该部分线,然后绘制一条新线。但是,对于弯曲的线,我认为我必须计算交点,但它并不像我预期的那样工作。我想知道是否有更简单、更直接的方法来做到这一点。
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{shapes, positioning, arrows, calc, intersections}
\tikzset{hidden node/.style={circle,draw,minimum size=.8cm,inner sep=0pt}, }
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}
\begin{document}
\makeatletter
\tikzset{
dot diameter/.store in=\dot@diameter,
dot diameter=3pt,
dot spacing/.store in=\dot@spacing,
dot spacing=10pt,
dots/.style={
line width=\dot@diameter,
line cap=round,
dash pattern=on 0pt off \dot@spacing
}
}
\makeatother
\begin{tikzpicture}
\node[hidden node] (noiseVar) at (5,4) {$\sigma^2_n$};
\node[hidden node] (noise) at (0,4) {$\varepsilon$};
\node[hidden node] (x) at (0,0) {$x$};
\draw[line width=2] (noiseVar) to node (midf) [pos=.3, fill=white, minimum width = .8cm] {} (noise);
\draw[dot diameter = 2pt, dot spacing = .3cm, dots] (midf.east) to (midf.west);
\draw[->,>=stealth',shorten >=1pt, name path=varToNoise] (noiseVar) to node (midn) [pos=.3, fill=white, minimum width = .8cm, minimum height = .8cm] {} (x);
\path[name path=midneast] (midn.north east) to (midn.south east);
\path[name path=midnwest] (midn.north west) to (midn.south west);
\node[coordinate, name intersections = {of = {varToNoise} and midneast}] (E) at (intersection-1) {};
\node[coordinate, name intersections = {of = {varToNoise} and midnwest}] (W) at (intersection-1) {};
draw [dot diameter = 2pt, dot spacing = .3cm, dots ] (E) to (W);
\end{tikzpicture}
\end{document}
答案1
您漏掉了最后一行的一个\
in 。draw
draw [dot diameter = 2pt, dot spacing = .3cm, dots ] (E) to (W);
然后它就会按照你的方式运行。
虽然intersection
不需要,但是您必须sloped
向节点添加选项midn
:
\draw[->,>=stealth',shorten >=1pt, name path=varToNoise] (noiseVar) to
node (midn) [pos=.3, fill=white, minimum width = .8cm, minimum height = .8cm,sloped] {} (x);
完整代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes, positioning, arrows, calc, intersections}
\tikzset{hidden node/.style={circle,draw,minimum size=.8cm,inner sep=0pt}, }
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}
\begin{document}
\makeatletter
\tikzset{
dot diameter/.store in=\dot@diameter,
dot diameter=3pt,
dot spacing/.store in=\dot@spacing,
dot spacing=10pt,
dots/.style={
line width=\dot@diameter,
line cap=round,
dash pattern=on 0pt off \dot@spacing
}
}
\makeatother
\begin{tikzpicture}
\node[hidden node] (noiseVar) at (5,4) {$\sigma²_n$};
\node[hidden node] (noise) at (0,4) {$\varepsilon$};
\node[hidden node] (x) at (0,0) {$x$};
\draw[line width=2] (noiseVar) to node (midf) [pos=.3, fill=white, minimum width = .8cm] {} (noise);
\draw[dot diameter = 2pt, dot spacing = .3cm, dots] (midf.east) to (midf.west);
\draw[->,>=stealth',shorten >=1pt, name path=varToNoise] (noiseVar) to node (midn) [pos=.3, fill=white, minimum width = .8cm, minimum height = .8cm,sloped] {} (x);
%\path[name path=midneast] (midn.north east) to (midn.south east);
%\path[name path=midnwest] (midn.north west) to (midn.south west);
%\node[coordinate, name intersections = {of = {varToNoise} and midneast}] (E) at (intersection-1) {};
%\node[coordinate, name intersections = {of = {varToNoise} and midnwest}] (W) at (intersection-1) {};
\draw [dot diameter = 2pt, dot spacing = .3cm, dots ] (midn.west) to (midn.east);
\end{tikzpicture}
\end{document}