如果线的某部分经过一个节点,是否可以自动改变该部分线的线条样式?
我正在尝试重新创建该图表:
请注意,当箭头穿过“节点”时,线条会变成虚线。虚线和实线都会发生这种情况。可以在 TikZ 中对此进行编码吗?
以下是 MWE:
此外,有什么方法可以防止线在到达/离开节点时重叠?请注意 MWE 中的三条实线在“HABITAT”处重叠。
\documentclass[a4paper]{article}
\usepackage{tikz}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[line width = 0.4mm]
\tikzset{
nodestyle/.style={
circle,
inner sep=0pt,
text width=1.8cm,
align=center,
% draw=black,
}}
% NODES
\node (H) [nodestyle] at (2,0) {HABITAT};
\node (B) [nodestyle] at (8,0) {BIOME};
\node (SU) [nodestyle] at (5,2) {Subsistence};
\node (SH) [nodestyle] at (2.5,3.5) {Shelter/\\Clothing};
\node (TC) [nodestyle] at (7.5,3.5) {Technology};
\node (TP) [nodestyle] at (0,5) {Transport};
\node (TD) [nodestyle] at (10,5) {Trade};
\node (SO) [nodestyle] at (5,6) {Social\\organisation};
\node (LW) [nodestyle] at (2.8,7.5) {Language/\\Writing};
\node (W) [nodestyle] at (7.2,7.5) {War};
\node (A) [nodestyle] at (0,9) {Art};
\node (LM) [nodestyle] at (10,9) {Law/\\Morals};
\node (M) [nodestyle] at (1.75,11.5) {Magic};
\node (SC) [nodestyle] at (8.25,11.5) {Science/\\Cosmology};
\node (R) [nodestyle] at (5,12.5) {Religion};
% ARROWS FROM (H)
\draw [->,dashed] (H)--(TP);
\draw [->,dashed] (H)--(A);
\draw [->,dashed] (H)--(M);
\draw [->,dashed] (H)--(LW);
\draw [->,dashed] (H)--(SH);
\draw [->,dashed] (H)--(R);
\draw [->,dashed] (H)--(SC);
\draw [->,dashed] (H)--(W);
\draw [->,dashed] (H)--(LM);
\draw [<->] (H)--(TC);
\draw [<->] (H)--(SU);
\draw [<->] (H)--(TD);
\draw [<->] (H)--(B);
\end{tikzpicture}
\caption{Diagram illustrating interrelations of different aspects of culture}
\end{figure}
\end{document}
答案1
只是为了好玩。节点的边界使用 命名path pictures
,线条绘制在背景上,如果它们穿过节点,则在前景中重新绘制点。正如我所说,您需要耐心等待,编译需要几秒钟。
\documentclass[a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{calc,intersections,backgrounds}
\newcounter{mynode}
\setcounter{mynode}{0}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[line width = 0.4mm]
\tikzset{
nodestyle/.style={
circle,
inner sep=0pt,
text width=1.8cm,
align=center,
fill=white,
path picture={\stepcounter{mynode}
\path[name path global=node circle \themynode] let \p1=($(path picture bounding box.north)-(path picture bounding
box.center)$)
in (path picture bounding box.center) circle (\y1);
;
},
% draw=black,
}}
% NODES
\node (H) [nodestyle] at (2,0) {HABITAT};
\node (B) [nodestyle] at (8,0) {BIOME};
\node (SU) [nodestyle] at (5,2) {Subsistence};
\node (SH) [nodestyle] at (2.5,3.5) {Shelter/\\Clothing};
\node (TC) [nodestyle] at (7.5,3.5) {Technology};
\node (TP) [nodestyle] at (0,5) {Transport};
\node (TD) [nodestyle] at (10,5) {Trade};
\node (SO) [nodestyle] at (5,6) {Social\\organisation};
\node (LW) [nodestyle] at (2.8,7.5) {Language/\\Writing};
\node (W) [nodestyle] at (7.2,7.5) {War};
\node (A) [nodestyle] at (0,9) {Art};
\node (LM) [nodestyle] at (10,9) {Law/\\Morals};
\node (M) [nodestyle] at (1.75,11.5) {Magic};
\node (SC) [nodestyle] at (8.25,11.5) {Science/\\Cosmology};
\node (R) [nodestyle] at (5,12.5) {Religion};
% ARROWS FROM (H)
\begin{scope}[on background layer]
\draw [name path global=arr1,->,dashed] (H)--(TP);
\draw [name path global=arr2,->,dashed] (H)--(A);
\draw [name path global=arr3,->,dashed] (H)--(M);
\draw [name path global=arr4,->,dashed] (H)--(LW);
\draw [name path global=arr5,->,dashed] (H)--(SH);
\draw [name path global=arr6,->,dashed] (H)--(R);
\draw [name path global=arr7,->,dashed] (H)--(SC);
\draw [name path global=arr8,->,dashed] (H)--(W);
\draw [name path global=arr9,->,dashed] (H)--(LM);
\draw [name path global=arr10,<->] (H)--(TC);
\draw [name path global=arr11,<->] (H)--(SU);
\draw [name path global=arr12,<->] (H)--(TD);
\draw [name path global=arr13,<->] (H)--(B);
\end{scope}
\foreach \X in {1,...,13}
{
\foreach \Y in {1,...,\themynode}
{
\draw[dotted,name intersections={of={arr\X} and {node circle \Y},
total=\n}] \ifnum\n=2
(intersection-1) -- (intersection-2)
\fi;
}
}
\end{tikzpicture}
\caption{Diagram illustrating interrelations of different aspects of culture}
\end{figure}
\end{document}
有趣的是,根据这个数字science
,和cosmology
是分开的东西。;-)