我在定位一个箭头时遇到了问题。HA 的箭头应该指向 (JC-JS) 的中心,但 (JC-JS) 不起作用。我在网上找不到解决方案。有人能帮我吗(查看代码和图片,我在代码中对错误的地方做了注释)。最好的情况是,如果 HA 的高度恰好位于 JC 和 JS 的高度之间,我该怎么做?祝你有美好的一天!Tobias
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\usetikzlibrary{positioning}
\begin{document}
\begin{figure}[h!]
\label{illustration}
\centering
\caption{bla}
\begin{tikzpicture}
[node distance=1cm and 4.4cm,
ar/.style={->,>=latex},
mynode/.style=
{draw,
text width=4.4cm,
minimum height=1cm,
align=center
}
]
\node[mynode] (JC) {JC};
\node[mynode,right=of JC] (RA) {RA};
\draw[ar] (JC) -> node[below] {bla} coordinate(JC-RA) (RA);
\node[mynode, text width=2cm, above=of JC-RA] (HE) {HE};
\node[mynode, text width=4cm, below=1.3 of JC-RA, dashed] (JS) {JS};
\node[mynode, draw=none, text width=4cm, below=0 of JS] (H4) {bla};
\node[mynode, text width=2cm, left=2 of JS] (HA) {HA};
\draw[ar] (HE.south) -> (JC-RA);
\draw[ar] (HA.north east) -> (JC-RA); %this arrow should be directed at the center of (JC-JS) just like the arrow before, but instead of JC-RA, it should be (JC-JS), but that doesn't work
\draw[ar] (JC.south) -> (JS.west);
\draw[ar] (JS.east) -> node[below=0.1cm, right] {bla} (RA.south);
\end{tikzpicture}
\end{figure}
\end{document}
解决方案,感谢 John Kormylo --->
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\usetikzlibrary{positioning}
\begin{figure}[h!]
\label{illustration}
\centering
\caption{bla}
\begin{tikzpicture}
[node distance=1cm and 4.4cm,
ar/.style={->,>=latex},
mynode/.style=
{draw,
text width=4.4cm,
minimum height=1cm,
align=center
}
]
\node[mynode] (JC) {JC};
\node[mynode,right=of JC] (RA) {RA};
\draw[ar] (JC) -> node[below] {} coordinate(JC-RA) (RA);
\node[mynode, text width=1.6cm, above=of JC-RA] (HE) {HE};
\node[mynode, text width=4cm, below=1.3 of JC-RA, dashed] (JS) {JS};
\node[mynode, text width=1.6cm, left=2.3 of JS] (HA) {HA};
\draw[ar] (HE.south) -> (JC-RA);
\draw[ar] (JC.south) -> node[above] {} (JS.west) coordinate[midway] (JCJS);
\draw[ar] (HA.east) -> node[below] {} (JCJS);
\draw[ar] (JS.east) -> node[above] {} (RA.south);
\end{tikzpicture}
\end{figure}
\end{document}
答案1
我还稍微清理了一下代码。
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\usetikzlibrary{positioning}
\begin{document}
\begin{figure}[h!]
\centering
\caption{bla}\label{illustration}
\begin{tikzpicture}
[node distance=1cm and 4.4cm,
ar/.style={->,>=latex},
mynode/.style=
{draw,
text width=4.4cm,
minimum height=1cm,
align=center
}
]
\node[mynode] (JC) {JC};
\node[mynode,right=of JC] (RA) {RA};
\draw[ar] (JC) -> (RA) coordinate[midway](JC-RA) ;
\node[mynode, text width=1.6cm, above=of JC-RA] (HE) {HE};
\node[mynode, text width=4cm, below=1.3 of JC-RA, dashed] (JS) {JS};
\node[mynode, text width=1.6cm, left=2.3 of JS] (HA) {HA};
\draw[ar] (HE.south) -> (JC-RA);
\draw[ar] (JC.south) -> (JS.west) coordinate[midway] (JCJS);
\draw[ar] (HA.east) -> (JCJS);
\draw[ar] (JS.east) -> (RA.south);
\end{tikzpicture}
\end{figure}
\end{document}
另一种方法是使用 calc tikzlibrary 来定义坐标($(JC.south)!.5!(JS.west)$)
,但原始解决方案更简单。