3

I'm trying to have some text repeated along a path. I tried what was prescribed in the PGF manual under /pgf/decoration/text effects/repeat text, but, as you can see, it doesn't have the effect I want:

Undesired effect

I'd like something like below, but repeated around the path:

Somewhat desired effect

MWE

\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{decorations.text}

\begin{document}

\begin{tikzpicture} [block/.style={draw, rectangle, minimum size=5cm, align=center}]

\node [block,
       postaction={decoration={text effects along path, text={BOX BOUNDARY\ },
           text effects/.cd,
               repeat text,
               character count=\m, character total=\n,
               characters={text along path, scale=0.5+\m/\n/2}},
           decorate}]
       (box){};

\end{tikzpicture}

\end{document}

2 Answers2

6

Apparently, it does not work with a node. Can you use a rectangle? (you can always add your node without text on top of the rectangle)

\documentclass[tikz, border=1 cm]{standalone}
\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
\draw[%
postaction={decoration={text effects along path, text={BOX BOUNDARY\ },
text effects/.cd,
repeat text,
character count=\m, character total=\n,
characters={text along path, scale=0.5+\m/\n/2}},
decorate},
] (0,0) rectangle (5,5);           
\end{tikzpicture}
\end{document}

Rectangle with repeated text

  • 1
    I'm curious to see if it works on a node with the keys rotate=5,rotate=-5 set on that node. – Andrew Stacey Sep 17 '21 at 23:12
  • 1
    @Andrew Stacey: It does not work. I also tried \path (<coordinates>) node... instead of \node as mentioned here: https://tex.stackexchange.com/a/445918/8650 ,..., combinations of pre/post-actions and direct decoration, and more - I could not make it work. – hpekristiansen Sep 17 '21 at 23:40
  • It seems to be something to do with how a node path is used - I suspect some interaction between the TikZ and PGF parts that is different to a normal path. I'm intrigued. – Andrew Stacey Sep 19 '21 at 20:36
3

There's definitely something odd happening with decorations and node paths. I don't know the whys and wherefores, but here's a method that works by repeating the node path out of the context of the node. This uses my spath3 library to avoid having to specify the path twice (which, incidentally, shows that it is nothing to do with the path and must therefore be to do with how the path around the node is used).

Note that I currently need to use the overlay option on the decoration path. This is because a rectangular node constructs a particular type of path that no other TikZ construction uses so I didn't account for it when coding spath3. I'm currently working on fixing that, but in the meantime the bounding box calculation is off.

\documentclass[border=1cm]{standalone}
% \url{https://tex.stackexchange.com/q/615779/86}
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{decorations.text,spath3}

\begin{document}

\begin{tikzpicture} [block/.style={draw, rectangle, minimum size=5cm, align=center}]

\node [block,
  spath/save=node path,
]
(box){};

\path[
  overlay, % Needed temporarily
  spath/use=node path,
  decoration={
    text effects along path,
    text={BOX BOUNDARY\ },
    text effects/.cd,
    repeat text,
    character count=\m, character total=\n,
    characters={text along path, scale=0.5+\m/\n/2}
  },
  decorate,
];

\end{tikzpicture}

\end{document}

Decorated node path

Andrew Stacey
  • 153,724
  • 43
  • 389
  • 751