TikZ 路径标签方向问题

TikZ 路径标签方向问题

我是 LaTeX 的新手。我想像下图这样对矩形进行分组和命名,所以我尝试了这个。

\documentclass{standalone}
\usepackage{tikz}
  \usetikzlibrary{shapes,arrows,fit,calc,positioning,decorations.text}
  \tikzset{box/.style={draw, rectangle, thick, text centered, minimum height=3em, minimum width = 6cm, text width = 5cm}}
  \tikzset{line/.style={draw, thick, -latex'}}
\begin{document}
\resizebox {\columnwidth} {!} {
    \begin{tikzpicture}[auto]
        \node [box]                     (1) {Node};
        \node [box, below=0.5cm of 1]   (2) {Node};
        \node [box, below=0.5cm of 2]   (3) {Node};
        \node [box, below=0.5cm of 3]   (4) {Node};

        \path [line] (1)  --  (2);
        \path [line] (2)  --  (3);
        \path [line] (3)  --  (4);
        \draw [thick, postaction={decorate, decoration={raise=-2ex, text along path, text align=center,text={PATH LABEL}}}] (4.west) -- ++(-15pt, 0) |- (1.west);

    \end{tikzpicture}
    }
\end{document}

上面的代码产生了这个 但我想旋转装饰(路径标签)里面的文本并使其看起来像这样。

此外,如果加薪幅度为正数,标签将出现在左侧,但我无法在 pdf 中看到它。我可以在 时看到它raise = 0ex

有没有更好的方法来写代码?

答案1

这是一个非常简单但简单且可行的建议。

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows,positioning}
\tikzset{box/.style={draw, rectangle, thick, text centered, minimum height=3em, minimum width = 6cm, text width = 5cm}}
\tikzset{line/.style={draw, thick, -latex'}}
\begin{document}
\begin{tikzpicture}[auto]
    \node [box]                     (1) {Node};
    \node [box, below=0.5cm of 1]   (2) {Node};
    \node [box, below=0.5cm of 2]   (3) {Node};
    \node [box, below=0.5cm of 3]   (4) {Node};

    \path [line] (1)  --  (2);
    \path [line] (2)  --  (3);
    \path [line] (3)  --  (4);
    \draw [thick] (4.west) -- ++(-15pt, 0) |- (1.west) node[pos=0.25,left,align=center]{
    P\\[-0.2ex] A\\[-0.2ex] T\\[-0.2ex]H\\[-0.2ex] \\[-0.2ex]L\\[-0.2ex] A\\[-0.2ex] B\\[-0.2ex] E\\[-0.2ex] L
    };  
\end{tikzpicture}
\end{document}

在此处输入图片描述

或者更复杂的版本:只需替换text along pathtext effects along path。(我不知道\columnwidth在文档中这样standalone做有多大意义。)

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning,decorations.text}
\tikzset{box/.style={draw, rectangle, thick, text centered, minimum height=3em, minimum width = 6cm, text width = 5cm}}
\tikzset{line/.style={draw, thick, -latex'}}
\begin{document}
\resizebox{\columnwidth}{!}{\begin{tikzpicture}[auto]
        \node [box]                     (1) {Node};
        \node [box, below=0.5cm of 1]   (2) {Node};
        \node [box, below=0.5cm of 2]   (3) {Node};
        \node [box, below=0.5cm of 3]   (4) {Node};

        \path [line] (1)  --  (2);
        \path [line] (2)  --  (3);
        \path [line] (3)  --  (4);
        \draw 
        [thick] (1.west) -- ++(-15pt, 0) coordinate(aux) |- (4.west);
        \path[decorate, decoration={raise=-2ex,
        text effects along path, 
        text align=center,
        text={PATH LABEL}}] (aux) -- (aux|-4.center);
    \end{tikzpicture}}
\end{document}

在此处输入图片描述

相关内容