tikz
当文本长度超过要装饰的路径时,我有几个关于文本装饰的问题:
- 为什么装饰不从行首开始(而在行尾正确截断)?
raise
如果使用负片,为什么当文本弯曲时字母之间的水平空间太多/太小?
看这里:
\documentclass[a4paper]{book}
\usepackage{tikz}
\usetikzlibrary{decorations.text,shapes}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix[column sep=7em,row sep=7ex]{%
\draw[postaction={decorate,decoration={text along path,text align=center,
text={Why doesn't this begin at the beginning of the line?}}}]
(0,0) to (1,0);
&
\draw[postaction={decorate,decoration={text along path,text align=center,
text={Idem as the previous one}}}]
(0,0) to[bend right] (1,0);
&
\draw[postaction={decorate,decoration={text along path,text align=center,
text={Idem as the previous one}}}]
(0,0) to[bend left] (1,0);
\\
\draw[postaction={decorate,decoration={text along path,text align=center,raise=-3ex,
text={Idem as the previous one}}}]
(0,0) to (1,0);
&
\draw[postaction={decorate,decoration={text along path,text align=center,raise=-3ex,
text={Moreover, why is there so much space between the bended letters?}}}]
(0,0) to[bend right] (1,0);
&
\draw[postaction={decorate,decoration={text along path,text align=center,raise=-3ex,
text={Moreover, why is there so little space between the bended letters?}}}]
(0,0) to[bend left] (1,0);
\\
};
\end{tikzpicture}
\end{document}
编辑:
符号 1 解释了为什么会发生这种情况,但我仍然不明白原因。
下面的行为难道不是更加连贯吗?
甚至是下面这个?
仅仅是因为自动完成这件事太难了吗?
PS = 之所以出现这个问题,是因为我想解释一下我在这篇文章的评论中使用“水平挤压”的意思cfr 的答案。
答案1
1.
如果文本太长,PGF 将插入负左缩进(和/或右缩进,取决于align=right
// center
)left
。因此看起来文本开始得更早。
然而,PGF 保持一个长度,\pgfdecoratedremainingdistance
称为输入路径上的剩余距离. (手册第 1001 页)根据装饰的设计,它是一个有限状态自动机,如果\pgfdecoratedremainingdistance
小于 1pt,它将终止。(pgfmoduledecorations.code.tex
第 789 行)
一旦自动机终止,PGF 将确定此路径,并且没有机会打印剩余的文本。(也许您可以通过使此长度为正来欺骗 PGF。但真正的问题是:您要去哪里?)
2.
因为间距/位置是相对于 x 轴为路径本身的坐标系进行的。无论您降低或升高角色,它们的宽度都保持不变。
对于已编辑的部分
1
添加此
\makeatletter
\pgfutil@namedef{pgf@decorate@@text along path@left indent@options}{
width={max(\pgf@lib@dec@text@indent@left,0)},next state=scan
}
2
添加这个
\makeatletter
\pgfkeys{
/pgf/decoration automaton/width/.code={
\ifx\pgf@lib@dec@text@indent@left\undefined
\def\pgf@decorate@width{#1}\pgf@decorate@switch@if#1 to final\pgf@stop
\else
% deceive the automaton by making the remaining distance longer
\advance\pgfdecoratedremainingdistance-\pgf@lib@dec@text@indent@left
\def\pgf@decorate@width{#1}\pgf@decorate@switch@if#1 to final\pgf@stop
\advance\pgfdecoratedremainingdistance\pgf@lib@dec@text@indent@left
\fi
}
}
\def\pgf@decorate@@movealongpath{%
\advance\pgfdecoratedinputsegmentcompleteddistance\pgf@decorate@distancetomove%
\advance\pgfdecoratedinputsegmentremainingdistance-\pgf@decorate@distancetomove%
\ifdim\pgfdecoratedinputsegmentremainingdistance>0pt\relax%
\let\pgf@next\pgf@decorate@@@movealongpath%
\else%
\begingroup
% check if we are at the last path
\pgf@decorate@processnextinputsegmentobject%
\ifx\pgf@decorate@currentinputsegmentobjects\pgfutil@empty%
% if yes, then insist to keep decorating on this path
\let\pgf@next\pgf@decorate@@@@movealongpath%
\else%
% if no, process the next segment again outside the group
\def\pgf@next{
\pgf@decorate@processnextinputsegmentobject
\pgf@decorate@@movealongpath
}
\fi%
\pgfmath@smuggleone\pgf@next
\endgroup
\fi%
\pgf@next%
}
\def\pgf@decorate@@@@movealongpath{
\pgf@decorate@movealonginputsegment{\the\pgf@decorate@distancetomove}%
\pgf@decorate@distancetomove0pt\relax
}
3
我认为这很明显