改变个别路径标签的样式吗?

改变个别路径标签的样式吗?

我正在使用 Tikzedt 创建路径图。

我遇到的问题是,这些彼此非常接近的线上的路径标签与其他线重叠,导致它们难以辨认。(见下图)。

我觉得应该有一种方法可以扩大我当前代码生成的每个标签周围的白色背景。

到目前为止,我在这个论坛上看到的解决方案都是在标题中放置代码,以更改所有路径标签节点或所有节点的样式。我确实不是想要这个,因为这是一个更复杂的图表的子集,其中有许多其他路径我想保持不变。

也许我需要在标题中创建一个新样式,并仅将该样式用于路径标签?我不太确定,并希望得到任何意见。

我觉得有一个简单的解决方案,但还没有找到任何可以解决此类问题的方法。

我不太熟悉 tikz 代码的复杂性(如果这还不明显的话),我目前正在根据同事发给我的模板进行构建。

请原谅任何冗余或无意义的代码,因为我不完全确定我在做什么。

在此处输入图片描述

这是我用来制作该图像的代码:

\usetikzlibrary{positioning,shapes,arrows,backgrounds,decorations.markings}
\usetikzlibrary{decorations.pathreplacing}

% Define block styles
\tikzstyle{block} = [rectangle, draw, minimum width=12mm, minimum height=10mm,fill=white,inner xsep=5pt,inner ysep=8pt] 
\tikzstyle{line} = [-latex'] 
\begin{tikzpicture}[node distance = 3cm,font=\bfseries\boldmath\large,line width=1.25pt]

%Place time point 1 Observed variables
\node [block] (Y010A) {$Y_{01r}$};

%Time point 2 observed variables
\node [block, below=10 cm of Y010A] (Y020A) {$Y_{02r}$};
\node [block, below=0.5cm of Y020A] (Y120A)  {$Y_{12r}$};
\node [block, below=0.5cm of Y120A] (Y220A)  {$Y_{22r}$};
\node [block, below=0.5cm of Y220A] (Y320A)  {$Y_{32r}$};
\node [block, below=0.5cm of Y320A] (Y420A)  {$Y_{42r}$};
\node [block, below=0.5cm of Y420A] (Y520A)  {$Y_{52r}$};

%Place reference trait factors and paths
\node[draw, circle, right=4 cm of Y010A, minimum size=1.25cm](TrA) {$T_{r}$};
\path [line] (TrA.140) edge (Y010A.30);

\path [line] (TrA.210) edge node {} (Y020A.30);
\path [line] (TrA.220) edge node[fill=white,inner sep=2pt,pos=0.1]{$\lambda_{8}$} (Y120A.30);
\path [line] (TrA.230) edge node[fill=white,inner sep=2pt,pos=0.12]{$\lambda_{9}$} (Y220A.30);
\path [line] (TrA.240) edge node[fill=white,inner sep=2pt,pos=0.14]{$\lambda_{10}$} (Y320A.30);
\path [line] (TrA.250) edge node[fill=white,inner sep=2pt,pos=0.16]{$\lambda_{11}$} (Y420A.30);
\path [line] (TrA.260) edge node[fill=white,inner sep=2pt,pos=0.18]{$\lambda_{12}$} (Y520A.30);

\end{tikzpicture}

答案1

我不知道这是否正是您所期望的,但这里有一段可能方便的代码:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,arrows,backgrounds,decorations.markings}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
% Define block styles
\tikzstyle{block} = [rectangle, draw, minimum width=12mm, minimum height=10mm,fill=white,inner xsep=5pt,inner ysep=8pt]
\tikzstyle{line} = [-latex']
\tikzstyle{path_node_wide} = [fill=white, text width=11mm]
\begin{tikzpicture}[node distance = 3cm,font=\bfseries\boldmath\large,line width=1.25pt]

%Place time point 1 Observed variables
\node [block] (Y010A) {$Y_{01r}$};

%Time point 2 observed variables
\node [block, below=10 cm of Y010A] (Y020A) {$Y_{02r}$};
\node [block, below=0.5cm of Y020A] (Y120A)  {$Y_{12r}$};
\node [block, below=0.5cm of Y120A] (Y220A)  {$Y_{22r}$};
\node [block, below=0.5cm of Y220A] (Y320A)  {$Y_{32r}$};
\node [block, below=0.5cm of Y320A] (Y420A)  {$Y_{42r}$};
\node [block, below=0.5cm of Y420A] (Y520A)  {$Y_{52r}$};

%Place reference trait factors and paths
\node[draw, circle, right=4 cm of Y010A, minimum size=1.25cm](TrA) {$T_{r}$};
\path [line] (TrA.140) edge (Y010A.30);

\path [line, path_node_wide] (TrA.210) edge node {} (Y020A.30);
\path [line] (TrA.210) edge node {} (Y020A.30);
\path [line] (TrA.220) edge node[path_node_wide, pos=0.2]{$\lambda_{8}$} (Y120A.30);
\path [line] (TrA.230) edge node[path_node_wide,pos=0.22]{$\lambda_{9}$} (Y220A.30);
\path [line] (TrA.240) edge node[path_node_wide,pos=0.24]{$\lambda_{10}$} (Y320A.30);
\path [line] (TrA.250) edge node[path_node_wide,pos=0.26]{$\lambda_{11}$} (Y420A.30);
\path [line] (TrA.260) edge node[path_node_wide,pos=0.28]{$\lambda_{12}$} (Y520A.30);

\end{tikzpicture}
\end{document}

我定义了一种新样式(path_node_wide),仅应用于所需节点。关于标签的白色背景,我明确给出,text width以便标签具有预期大小(尽管我认为可能存在更好的方法......)。我还移动了您的标签,因为我发现它们在那里更具可读性)。

您可以在这里找到结果:

在此处输入图片描述

我希望这能有点帮助。

相关内容