我正在创建一个螺旋,灵感来自 Mark Wibrow 的回答使用 TikZ 制作螺旋状文本。
但是,我遇到了一个问题。我想在螺旋中放置一个使用法语字符和符号(例如 à、é 等)的文本。具体来说,我想放置文本“On a été à Paris”。
正如您在下面看到的,我尝试添加
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
到序言部分,但不幸的是它给出了一个错误。控制台显示错误是“Extra \else”和“\pgf@lib@dec@text@char ->\else”。这可能与 TikZ 包有关,但我不确定。
这可能是什么问题?有人能解决这个问题吗?
我当前正在使用的代码(虽然它不起作用,但只要您省略上述三个包它就可以工作)如下:
\documentclass{standalone}
\usepackage{tikz}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usetikzlibrary{decorations.text}
\makeatletter
\let\pgf@lib@dec@text@dobox@original=\pgf@lib@dec@text@dobox%
\def\pgf@lib@dec@text@dobox{%
\pgf@lib@dec@text@dobox@original%
\ifpgfdecorationtextalongpathscaletext%
\pgfmathparse{\pgf@lib@dec@text@endscale+(\pgf@lib@dec@text@startscale-\pgf@lib@dec@text@endscale)*\pgfdecoratedremainingdistance/\pgfdecoratedpathlength}%
\setbox\pgf@lib@dec@text@box=\hbox{\scalebox{\pgfmathresult}{\box\pgf@lib@dec@text@box}}%
\fi%
}
\newif\ifpgfdecorationtextalongpathscaletext
\def\pgf@lib@dec@text@startscale{1}
\def\pgf@lib@dec@text@endscale{1}
\pgfkeys{/pgf/decoration/.cd,
text path start scale/.code={%
\pgfdecorationtextalongpathscaletexttrue%
\def\pgf@lib@dec@text@startscale{#1}%
},
text path end scale/.code={%
\pgfdecorationtextalongpathscaletexttrue%
\def\pgf@lib@dec@text@endscale{#1}%
}
}
\begin{document}
\begin{tikzpicture}[
decoration={
reverse path,
text along path,
text path start scale=1.5,
text path end scale=0,
text={On a \'et\'e \`a Paris.}}
]
\draw [decorate]
(0,0)
\foreach \i [evaluate={\r=(\i/2000)^2;}] in {0,5,...,2880}{ -- (\i:\r)};
\useasboundingbox (-2.75,-2.75) rectangle (2.75,2.75);
\end{tikzpicture}
\end{document}
答案1
您必须使用(参见 pgfmanual,v3.0.1a,第 597 页):
text={On a {é}t{é} {à} Paris.}
或者:
text={On a {\'e}t{\'e} {\`a} Paris.}
结果:
代码:
\documentclass{standalone}
\usepackage{tikz}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usetikzlibrary{decorations.text}
\makeatletter
\let\pgf@lib@dec@text@dobox@original=\pgf@lib@dec@text@dobox%
\def\pgf@lib@dec@text@dobox{%
\pgf@lib@dec@text@dobox@original%
\ifpgfdecorationtextalongpathscaletext%
\pgfmathparse{\pgf@lib@dec@text@endscale+(\pgf@lib@dec@text@startscale-\pgf@lib@dec@text@endscale)*\pgfdecoratedremainingdistance/\pgfdecoratedpathlength}%
\setbox\pgf@lib@dec@text@box=\hbox{\scalebox{\pgfmathresult}{\box\pgf@lib@dec@text@box}}%
\fi%
}
\newif\ifpgfdecorationtextalongpathscaletext
\def\pgf@lib@dec@text@startscale{1}
\def\pgf@lib@dec@text@endscale{1}
\pgfkeys{/pgf/decoration/.cd,
text path start scale/.code={%
\pgfdecorationtextalongpathscaletexttrue%
\def\pgf@lib@dec@text@startscale{#1}%
},
text path end scale/.code={%
\pgfdecorationtextalongpathscaletexttrue%
\def\pgf@lib@dec@text@endscale{#1}%
}
}
\begin{document}
\begin{tikzpicture}[
decoration={
reverse path,
text along path,
text path start scale=1.5,
text path end scale=0,
text={On a {é}t{é} {à} Paris. On a vu la tour Eiffel, %
les jardins du Louvre, %
le mus{é}e d'Orsay et la Seine.},
}
]
\draw [decorate] (0,0) \foreach \i [evaluate={\r=(\i/2000)^2;}] in
{0,5,...,2880}{ -- (\i:\r)}; \useasboundingbox (-2.75,-2.75) rectangle
(2.75,2.75);
\end{tikzpicture}
\end{document}