当我尝试改进我的答案时,就会出现这个问题这个问题。
你可以很好地编译此代码
\documentclass[tikz]{standalone}
\usetikzlibrary{bending,decorations.text}
\begin{document}
\begin{tikzpicture}
\sffamily
\node (a) at (-2,0) {probability};
\node[align=center] (b) at (2,0) {percent\\change};
\draw[-latex,postaction={decorate,decoration={raise=1ex,text along path,text align=center,text={multiply by 100}}}] (a) to[out=60,in=120] (b);
\end{tikzpicture}
\end{document}
但不要编译此代码!
\documentclass[tikz]{standalone}
\usetikzlibrary{bending,decorations.text}
\begin{document}
\begin{tikzpicture}
\sffamily
\node (a) at (-2,0) {probability};
\node[align=center] (b) at (2,0) {percent\\change};
\draw[-latex,postaction={decorate,decoration={raise=1ex,text along path,text align=center,text={multiply by 100\%}}}] (a) to[out=60,in=120] (b);
\end{tikzpicture}
\end{document}
我已经等了200多秒
为什么?我只是想添加一个百分号(\%
)!
我认为 Ti钾Z 理解我的\%
,%
但删除\
会引发许多错误。
我甚至使用了siunitx
,但得到了相同的结果。
\documentclass[tikz]{standalone}
\usetikzlibrary{bending,decorations.text}
\usepackage{siunitx}
\begin{document}
\begin{tikzpicture}
\sffamily
\node (a) at (-2,0) {probability};
\node[align=center] (b) at (2,0) {percent\\change};
\draw[-latex,postaction={decorate,decoration={raise=1ex,text along path,text align=center,text={multiply by \SI{100}{\percent}}}}] (a) to[out=60,in=120] (b);
\end{tikzpicture}
\end{document}
发生什么了?
答案1
您只需将其包装\%
到即可{...}
。
\documentclass[tikz]{standalone}
\usetikzlibrary{bending,decorations.text}
\begin{document}
\begin{tikzpicture}
\sffamily
\node (a) at (-2,0) {probability};
\node[align=center] (b) at (2,0) {percent\\change};
\draw[-latex,postaction={decorate,decoration={raise=1ex,text along path,text
align=center,text={multiply by 100{\%}}}}] (a) to[out=60,in=120] (b);
\end{tikzpicture}
\end{document}
答案2
您可以通过将%
字符更改为不再是注释字符来完成此工作\catcode
:
\documentclass[tikz]{standalone}
\usetikzlibrary{bending,decorations.text}
\begin{document}
\begin{tikzpicture}
\sffamily
\node (a) at (-2,0) {probability};
\node[align=center] (b) at (2,0) {percent\\change};
\begin{scope}
\catcode`\%=12
\draw[-latex,postaction={decorate,decoration={raise=1ex,text along path,text
align=center,text={multiply by 100%}}}] (a) to[out=60,in=120] (b);
\end{scope}
\end{tikzpicture}
\end{document}