1

I'm a newbie to LaTeX. I wanted to group and name the rectangles like the image below so I tried this.

\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}

Above code produces this But I want to rotate the text inside the decoration (path label) and make it look like this.

Also, if the raise is something positive, the label will come on the left but I won't be able to see it in the pdf. I can see it when raise = 0ex.

Is there a better way to write the code?

  • If you want to see the text if raise is positive, you should add option margin=... to the document class. – user156344 Mar 24 at 14:01
3

A very unsophisticated though simple and working proposal.

\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}

enter image description here

Or a more sophisticated version: simply replace text along path by text effects along path. (I do not know how much sense \columnwidth in a standalone document makes.)

\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}

enter image description here

  • You can use pre length to shift the text on the original path like this \draw[decoration={text effects along path, raise=-2ex, pre length=5mm, text={PATH LABEL}},postaction={decorate}] (1.west) -- ++(-15pt, 0) |- (4.west); – Kpym Mar 24 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.