
デコレーション ライブラリを使用して、パスに沿ってテキストを配置しています。しかし、テキストはパス上に表示されず、ノード内に表示されます。どうすれば修正できますか? また、点線のパスが対称ではありません。きれいに対称に見えるようにする方法はありますか? 等長の実線を作成するにはどうすればよいでしょうか?
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\usetikzlibrary{positioning}
\usetikzlibrary{calc,shapes.multipart,chains}
\begin{document}
\tikzstyle{block} = [rectangle, draw, fill=blue!20,
text width=5em, text centered, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=3cm,
minimum height=2em]
\begin{tikzpicture}[node distance = 2cm, auto]
% Place nodes
\node [block] (init) {model};
\node [cloud, left of=init] (expert) {$\mathbf{\Lambda}$ };
\node [cloud, right of=init] (system) {Predict};
\path [line,dashed] ([yshift=3ex]{init}) to[out=-90,in=-90,looseness=2.2] ([yshift=-.5ex]{expert}) node [midway, above, sloped] (TextNode) {path text};
\path [line] (init) -- (system);
\path [line] (expert) -- (init);
\end{tikzpicture}
\end{document}
答え1
いくつかの変更。
\tikzset
の代わりにを使用する必要があります\tikzstyle
。構文については以下のコードを参照してください。anchor=
ノードの中心ではなく端からの間隔を測定するために使用します。- 図書館を利用してください
decorations.text
。 - テキスト パスを対称にするには、テキスト パスを長方形の底部と同じ高さに描画してから、円まで延長します。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning, shapes.geometric, arrows, decorations.text}
\tikzset{block/.style={rectangle, draw, fill=blue!20, text width=5em,
text centered, rounded corners, minimum height=4em},
cloud/.style={draw, ellipse,fill=red!20, node distance=3cm, minimum height=2em},
line/.style={draw, -latex'}
}
\begin{document}
\begin{tikzpicture}[node distance = 2cm, auto]
% Place nodes
\node [block] (init) {model};
\node [cloud, left of=init, anchor=east] (expert) {$\mathbf{\Lambda}$ };
\node [cloud, right of=init, anchor=west] (system) {Predict};
\path [line] (init) -- (system);
\path [line] (expert) -- (init);
\draw [line, dashed]
[postaction={decoration={text along path, reverse path, text align=center, text={path text}}, decorate}]
(init) to[out=-90, in=-90, looseness=2.2] ([yshift=-2em]expert) to (expert);
\end{tikzpicture}
\end{document}
答え2
あなたが探しているものがまったく明確ではありません。おそらく、次のようなものだと思います。
つまり、テキストは破線曲線上ではなく、最初の直線の実線矢印上にあります。
\documentclass[margin=3mm]{standalone}%{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
calc, chains,
positioning,
quotes,
shapes, shapes.multipart}
\begin{document}
\begin{tikzpicture}[auto,
node distance = 22mm,
start chain = going right,
arr/.style = {-Stealth},
base/.style = {draw, semithick, minimum size=2.2em, font=\sffamily},
block/.style = {base, text width=5em, align=center, rounded corners, fill=blue!20},
cloud/.style = {base, ellipse, fill=red!20}
]
\begin{scope}[nodes={on chain, join=by arr}]
\node [cloud] (expert) {$\mathbf{\Lambda}$};
\node [block] (init) {model};
\node [cloud] (system) {Predict};
\end{scope}
\path (expert) to ["path text"] (init);
\draw[arr, dashed] (init) to [out=240, in=300] (expert);
\end{tikzpicture}
\end{document}
矢印の上のラベルには ライブラリ が使用され\quotes
、破線にはエッジ オプション が使用されますbend left=60
。chains
ドキュメントのプリアンブルにロードされる ライブラリ が利用されます。 ノード スタイルは のオプションとして定義されます。 これにより、MWE で使用されているtikzpicture
古い定義が削除されます。\tikzstyle