
Estou usando a biblioteca de decorações para colocar texto ao longo de um caminho. Mas o texto não aparece no caminho, mas sim no nó, como devo corrigi-lo? Além disso, o caminho pontilhado não é simétrico. Existe uma maneira de torná-lo limpo e parecer simétrico? Como faço linhas sólidas de comprimento igual?
\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}
Responder1
Várias mudanças.
- Você deve usar
\tikzset
em vez de\tikzstyle
. Veja o código abaixo para a sintaxe. - Use
anchor=
para medir o espaçamento da borda do nó em vez do centro. - Use a
decorations.text
biblioteca. - Para tornar o caminho do texto simétrico, desenhe-o na mesma altura da parte inferior do retângulo e estenda-o até o círculo.
\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}
Responder2
Não está totalmente claro o que você está procurando. Eu acho que para algo assim:
ou seja, esse texto está na primeira seta sólida reta e não na curva tracejada.
\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}
Para rótulos acima da seta é usada \quotes
a biblioteca, para linha tracejada para opção de borda bend left=60
. Explorada é chains
a biblioteca, que é carregada no preâmbulo do documento. Os estilos de nós são definidos como opções em tikzpicture
. Com isso são removidas \tikzstyle
definições obsoletas utilizadas em seu MWE.