# Control of text position using the decorations.text library in Tikz

I have a two properties that I have been struggling to implement in the decorations.text library for the following image. My two questions are:

1) How do I control the text position along the line? Normally I would use something like the following - I can control the position of the text using pos=0.2 but it doesn't appear to work in the decorations.text library.

\draw [dashed] (\mylt,\mytop) .. controls (\mylt+4cm,\mytop-2cm) and (\mylt+8cm,\mytop-2cm) .. (\mylt+15cm,\mytop-2cm) node [pos=0.2, above, sloped] (TextNode) {Overall influence curve};


2) Can I offset the text from the line slightly? It looks a bit squashed.

Minimal working example below:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
\newlength{\mylt}
\newlength{\mytop}
\setlength{\mylt}{1.5cm}
\setlength{\mytop}{-1cm}
\draw [dashed, postaction={decorate,decoration={text along path,text align=center,text={Overall influence curve}}}] (\mylt,\mytop) .. controls (\mylt+4cm,\mytop-2cm) and (\mylt+8cm,\mytop-2cm) .. (\mylt+15cm,\mytop-2cm);
\end{tikzpicture}
\end{document}


David

You can control position along the line with align option. You can define some left indent or right indent values to indicate where to start or end the text.

I don't know how to set a vertical offset but may be you can \draw a vertically shifted line and later \path the decorated text over the same non shifted line.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
\newlength{\mylt}
\newlength{\mytop}
\setlength{\mylt}{1.5cm}
\setlength{\mytop}{-1cm}
\draw [dashed, postaction={decorate,decoration={text along path,text align=center,text={Overall influence curve}}}] (\mylt,\mytop) .. controls (\mylt+4cm,\mytop-2cm) and (\mylt+8cm,\mytop-2cm) .. (\mylt+15cm,\mytop-2cm);

\begin{scope}[yshift=1cm]
\draw [dashed, postaction={decorate,decoration={text along path,text align={left, left indent=1cm}, text={Overall influence curve}}}] (\mylt,\mytop) .. controls (\mylt+4cm,\mytop-2cm) and (\mylt+8cm,\mytop-2cm) .. (\mylt+15cm,\mytop-2cm);
\end{scope}

\begin{scope}[yshift=2cm]
\draw[yshift=-3mm] (\mylt,\mytop) .. controls (\mylt+4cm,\mytop-2cm) and (\mylt+8cm,\mytop-2cm) .. (\mylt+15cm,\mytop-2cm);
\path [postaction={decorate,decoration={text along path,text align={right,right indent=4cm}, text={Overall influence curve}}}] (\mylt,\mytop) .. controls (\mylt+4cm,\mytop-2cm) and (\mylt+8cm,\mytop-2cm) .. (\mylt+15cm,\mytop-2cm);
\end{scope}
\end{tikzpicture}
\end{document}


Update: Vertical shift

As jlovegren suggested, raise option insidedecoration could be used to introduce the desired separation between path and text. Previous code with different raise options and simplified third scope looks like:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
\newlength{\mylt}
\newlength{\mytop}
\setlength{\mylt}{1.5cm}
\setlength{\mytop}{-1cm}
\draw [dashed, postaction={decorate,decoration={text along path,text align=center,text={Overall influence curve},raise=1mm}}] (\mylt,\mytop) .. controls (\mylt+4cm,\mytop-2cm) and (\mylt+8cm,\mytop-2cm) .. (\mylt+15cm,\mytop-2cm);

\begin{scope}[yshift=1cm]
\draw [dashed, postaction={decorate,decoration={text along path,text align={left, left indent=1cm}, text={Overall influence curve}, raise=-5mm}}] (\mylt,\mytop) .. controls (\mylt+4cm,\mytop-2cm) and (\mylt+8cm,\mytop-2cm) .. (\mylt+15cm,\mytop-2cm);
\end{scope}

\begin{scope}[yshift=2cm]
\draw [postaction={decorate,decoration={text along path,text align={right,right indent=4cm}, text={Overall influence curve}, raise=3mm}}] (\mylt,\mytop) .. controls (\mylt+4cm,\mytop-2cm) and (\mylt+8cm,\mytop-2cm) .. (\mylt+15cm,\mytop-2cm);
\end{scope}
\end{tikzpicture}
\end{document}


And the result is:

• Hi Ignasi, thank you that was exactly what I was looking for! I like the use of the scope command as well; haven't seen that before. – David Mar 3 '15 at 12:27
• For the vertical offset, you can do something like decoration={...,raise=2pt,...}. – jlovegren Aug 1 '16 at 6:04
• @jlovegren Thank you. I've updated the answer with your suggestion. – Ignasi Aug 1 '16 at 8:57

You could instead use text effects along path which allows you to apply effects on a character-by-character basis, such as shifting the text above or below the line of the curve or to the left or right. For example:

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
\newlength{\mylt}
\newlength{\mytop}
\setlength{\mylt}{1.5cm}
\setlength{\mytop}{-1cm}
\draw
[dashed,
postaction={
decorate,
decoration={
text effects along path,
text align=center,
text={Overall influence curve},
text effects/.cd,
characters={text along path, yshift=5pt}
}
}
] (\mylt,\mytop) .. controls (\mylt+4cm,\mytop-2cm) and (\mylt+8cm,\mytop-2cm) .. (\mylt+15cm,\mytop-2cm);
\scoped[yshift=-10mm]{
\draw
[dashed,
postaction={
decorate,
decoration={
text effects along path,
text align=left,
text={Overall influence curve},
text effects/.cd,
characters={text along path, yshift=10pt, xshift=20mm}
}
}
] (\mylt,\mytop) .. controls (\mylt+4cm,\mytop-2cm) and (\mylt+8cm,\mytop-2cm) .. (\mylt+15cm,\mytop-2cm);}
\scoped[yshift=-20mm]{
\draw
[dashed,
postaction={
decorate,
decoration={
text effects along path,
text align=right,
text={Overall influence curve},
text effects/.cd,
characters={text along path, yshift=-15pt, xshift=-20mm}
}
}
] (\mylt,\mytop) .. controls (\mylt+4cm,\mytop-2cm) and (\mylt+8cm,\mytop-2cm) .. (\mylt+15cm,\mytop-2cm);}
\end{tikzpicture}
\end{document}