使用text effects
会使预期的行为无效,因为text align = {left indent = {0.25\dimexpr\pgfdecoratedpathlength\relax}}
应该在距离起点 25% 的路径长度处开始排版文本,那么如何使两者协同工作呢?
\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot[mark = none,
decoration = {
text = {My text},
text align = {
left indent = {0.25\dimexpr\pgfdecoratedpathlength\relax}
},
raise = -0.5ex,
text effects along path,
text effects/characters = {text along path, fill = white},
},
postaction = {decorate},
]
{x^2};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
根据软件包的建议pgfplots
:考虑\pgfplotsset{compat=1.18}
在序言中写入或使用另一个版本。
这个答案不能解决问题,left indent
但是使用了一种解决方法,即将文本放在单独的图中domain=-3.275:5
。
\documentclass[border=6pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot[] {x^2};
\addplot[
domain=-3.275:5,
decoration={
text effects along path,
text effects/characters={
text along path,
fill=white
},
text=My text,
text align=left,
raise=-0.5ex
},
decorate
]
{x^2};
\end{axis}
\end{tikzpicture}
\end{document}