
我正在使用 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
標籤的預期大小(儘管我認為可能存在更好的方法...)。我還稍微移動了你的標籤,因為我發現它們在那個地方更具可讀性)。
您可能會在這裡找到結果:
我希望它能有所幫助。