按照我的问题这里关于如何沿路径绘制文本,出现了另一个问题。如何向\command
沿路径的文本添加数学或命令?
这在这里有效:
postaction={decorate,decoration={text along path,text={|\scriptsize| Loading}}}
这些不:
postaction={decorate,decoration={text along path,text={|\scriptsize| 0\textdegree Loading}}}
postaction={decorate,decoration={text along path,text={|\scriptsize| 0$^{\circ}$ Loading}}}
我尝试用括号将命令和数学括起来,但这也不起作用。没有产生任何错误,只是编译过程pdflatex
需要很长时间并且不会结束。
有人能告诉我为什么这不起作用以及如何解决这个问题吗?
\documentclass[a4paper,10pt]{scrreprt}
\usepackage[T1]{fontenc}
% \usepackage[utf8]{inputenc}
\usepackage[latin1]{inputenc}
\usepackage{pgfplots}
\usetikzlibrary{decorations.text}
\usepackage{textcomp}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
domain=0:2,
xmin=0, xmax=2.25,
ymin=0, ymax=4.5,
samples=100,
axis y line=center,
axis x line=middle,
]
\addplot+[mark=none,samples=150] {2*0.7*(1+x)*(1-1/(1+x)^3)};
\addplot[draw=none,
postaction={decorate,decoration={text along path,
text={|\scriptsize| Loading},raise=1ex,
text align={center}
}},
domain=0.5:1.5,] {2*0.7*(1+x)*(1-1/(1+x)^3)+0.5};
\addplot+[mark=none,black,domain=0.5:1.5,->,,samples=150] {2*0.7*(1+x)*(1-1/(1+x)^3)+0.5};
\addplot[draw=none,postaction={decorate,decoration={text along path,
text={|\scriptsize| Unloading},raise=-2ex,
text align={center},
}},
domain=0.5:1.5] {2*0.7*(1+x)*(1-1/(1+x)^3)-0.5};
\addplot+[<-,mark=none, black,domain=0.5:1.5,samples=150] {2*0.7*(1+x)*(1-1/(1+x)^3)-0.5};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
因为它是一个单位,所以我会使用siunitx
:
\addplot[draw=none,
postaction={decorate,decoration={text along path,
text={|\scriptsize| {\SI{0}{\degree}} Loading},raise=1ex,
text align={center}
}},
domain=0.5:1.5,] {2*0.7*(1+x)*(1-1/(1+x)^3)+0.5};
完整代码如下:
\documentclass[a4paper,10pt]{scrreprt}
\usepackage[T1]{fontenc}
% \usepackage[utf8]{inputenc}
\usepackage[latin1]{inputenc}
\usepackage{siunitx}
\usepackage{pgfplots}
\usetikzlibrary{decorations.text}
\usepackage{textcomp}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
domain=0:2,
xmin=0, xmax=2.25,
ymin=0, ymax=4.5,
samples=100,
axis y line=center,
axis x line=middle,
]
\addplot+[mark=none,samples=150] {2*0.7*(1+x)*(1-1/(1+x)^3)};
\addplot[draw=none,
postaction={decorate,decoration={text along path,
text={|\scriptsize| {\SI{0}{\degree}} Loading},raise=1ex,
text align={center}
}},
domain=0.5:1.5,] {2*0.7*(1+x)*(1-1/(1+x)^3)+0.5};
\addplot+[mark=none,black,domain=0.5:1.5,->,,samples=150] {2*0.7*(1+x)*(1-1/(1+x)^3)+0.5};
\addplot[draw=none,postaction={decorate,decoration={text along path,
text={|\scriptsize| {\SI{0}{\degree}} Unloading},raise=-2ex,
text align={center},
}},
domain=0.5:1.5] {2*0.7*(1+x)*(1-1/(1+x)^3)-0.5};
\addplot+[<-,mark=none, black,domain=0.5:1.5,samples=150] {2*0.7*(1+x)*(1-1/(1+x)^3)-0.5};
\end{axis}
\end{tikzpicture}
\end{document}
请注意,我们必须\SI{0}{\degree}
使用括号来隐藏 tikz 解析器。
答案2
非常感谢@jarauth,这个链接帮我找到了窍门。我肯定是在用括号测试时错过了这个窍门。
这招很管用:
postaction={decorate,decoration={text along path,text={|\scriptsize| 0{\textdegree} Loading}}}