Control of text position using the decorations.text library in Tikz
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:
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}