경로를 따라 텍스트 배치

경로를 따라 텍스트 배치

저는 경로를 따라 텍스트를 배치하기 위해 장식 라이브러리를 사용하고 있습니다. 그런데 텍스트가 경로에 나타나지 않고 대신 노드에 나타나는데 어떻게 수정해야 합니까? 그리고 점선 경로가 대칭이 아닌데 깔끔하게 대칭으로 보이게 할 수 있는 방법이 없을까요? 길이가 같은 실선을 어떻게 만들 수 있나요?

\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. Exploited는 chains문서 프리앰블에 로드되는 라이브러리 입니다 . 노드 스타일은 에서 옵션으로 정의됩니다 tikzpicture. 이를 통해 \tikzstyleMWE에서 사용되는 더 이상 사용되지 않는 정의가 제거됩니다.

관련 정보