我发现我无法将装饰应用于使用“to”路径操作绘制的(大多数)曲线。这是一个有效示例:
\documentclass[a4paper, reqno]{amsart}
\usepackage{tikz}
\usetikzlibrary{decorations.markings, topaths}
\makeatletter
\tikzset{nomorepostaction/.code = \let\tikz@postactions\pgfutil@empty}
\makeatother
\tikzset{bigdiagramarrow/.style = {
decoration = {markings, mark = at position 1 with {\arrow[thick]{latex}}},
postaction = {nomorepostaction, decorate}
}}
\begin{document}
\begin{tikzpicture}
\node [draw] (A) at (0, 0) {$A$};
\node [draw] (B) at (0, 1) {$B$};
\node [draw] (C) at (2, 1) {$C$};
\draw [bigdiagramarrow] (A) -- (B);
\draw [out = 0, in = 180, bigdiagramarrow] (A) to (C);
\end{tikzpicture}
\end{document}
以下是我编译后得到的结果:
可以看到,使用路径操作绘制的路径末端会绘制一个箭头--
,但是使用路径操作绘制的路径末端却没有绘制箭头to
。
奇怪的是,在我遇到此问题的文档中,我发现使用“to”路径操作创建的一些曲线将显示装饰。更准确地说,我实际尝试排版的文档中的 12 条曲线中有 3 条显示了装饰。每次我编译文档时都是这 3 条。我不知道这 3 条与其他曲线有什么不同。
一开始看起来这个问题可能相关,但据我所知,我似乎没有遇到相同的“陷阱”,因为我没有将选项传递给路径to
操作而是传递给\draw
宏。
注意:nomorepostaction
关键来自 Ulrich Schwarz 对这个问题。
答案1
我找到了两种或多或少合适的方法来改变箭头的大小(这不是解决当前实际问题的方法,也就是说at position 1
不是计算正确的):
- 不太合适:
- 新箭头:
_latex
- 新风格
arrow line width
:长度(新的\pgflinewidth
) - 并且
arrow ultra thin
,,arrow very thin
…,arrow ultra thick
设置arrow line width
- 新箭头:
- 更合适:
- 重新定义一个宏,本地(!)为箭头设置新的线宽。
- 新风格
arrow line width
:因素 - 并且
arrow ultra thin
,,arrow very thin
…,arrow ultra thick
设置arrow line width
(它们甚至可以结合在一起。)
不太合适:新箭头
我选择定义一个_latex
与 相同的新箭头,latex
只是将其\pgflinewidth
替换为\pgflinewidth@arrow
。
长度\pgflinewidth@arrow
是默认的\pgflinewidth
,因此箭头会照常工作,除非arrow line width
明确使用任意长度的键。(遗憾的是,thick
等等不能使用,但 arrow thick
。
可以进行改进的是,人们可以通过找到一个好的钩子在\pgflinewidth
本地设置来使用已经存在的箭头而无需进行任何改变。
有许多其他方法来改变箭头大小:是否可以更改 TikZ/PGF 中箭头的大小?
代码
\documentclass[tikz,border=2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\makeatletter
\tikzset{nomorepostaction/.code = \let\tikz@postactions\pgfutil@empty}
\newdimen\pgflinewidth@arrow
\pgfarrowsdeclare{_latex}{_latex}
{
\pgfutil@tempdima=0.28pt%
\pgfutil@tempdimb=\pgflinewidth@arrow%
\ifdim\pgfinnerlinewidth>0pt%
\pgfmathsetlength\pgfutil@tempdimb{.6\[email protected]*\pgfinnerlinewidth}%
\fi%
\advance\pgfutil@tempdima by.3\pgfutil@tempdimb%
\pgfarrowsleftextend{+-1\pgfutil@tempdima}
\pgfarrowsrightextend{+9\pgfutil@tempdima}
}
{
\pgfutil@tempdima=0.28pt%
\pgfutil@tempdimb=\pgflinewidth@arrow%
\ifdim\pgfinnerlinewidth>0pt%
\pgfmathsetlength\pgfutil@tempdimb{.6\[email protected]*\pgfinnerlinewidth}%
\fi%
\advance\pgfutil@tempdima by.3\pgfutil@tempdimb%
\pgfpathmoveto{\pgfqpoint{9\pgfutil@tempdima}{0pt}}
\pgfpathcurveto
{\pgfqpoint{6.3333\pgfutil@tempdima}{.5\pgfutil@tempdima}}
{\pgfqpoint{2\pgfutil@tempdima}{2\pgfutil@tempdima}}
{\pgfqpoint{-1\pgfutil@tempdima}{3.75\pgfutil@tempdima}}
\pgfpathlineto{\pgfqpoint{-1\pgfutil@tempdima}{-3.75\pgfutil@tempdima}}
\pgfpathcurveto
{\pgfqpoint{2\pgfutil@tempdima}{-2\pgfutil@tempdima}}
{\pgfqpoint{6.3333\pgfutil@tempdima}{-.5\pgfutil@tempdima}}
{\pgfqpoint{9\pgfutil@tempdima}{0pt}}
\pgfusepathqfill
}
\tikzset{
bigdiagramarrow/.style = {
-_latex,
arrow thick
},
arrow line width/.code={
\pgfmathsetlength\pgflinewidth@arrow{#1}
},
arrow line width/.initial=\pgflinewidth,
arrow ultra thin/.style={arrow line width=0.1pt},
arrow very thin/.style={arrow line width=0.2pt},
arrow thin/.style={arrow line width=0.4pt},
arrow semithick/.style={arrow line width=0.6pt},
arrow thick/.style={arrow line width=0.8pt},
arrow very thick/.style={arrow line width=1.2pt},
arrow ultra thick/.style={arrow line width=1.6pt},
}
\makeatother
\begin{document}
\begin{tikzpicture}
\node [draw] (A) at (0, 0) {$A$};
\node [draw] (B) at (0, 1) {$B$};
\node [draw] (C) at (2, 1) {$C$};
\draw [bigdiagramarrow] (A) to (B);
\draw [out = 0, in = 180][bigdiagramarrow] (A) to (C);
\end{tikzpicture}
\end{document}
输出
更合适:
代码
\documentclass[tikz,border=2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\makeatletter
\tikzset{nomorepostaction/.code = \let\tikz@postactions\pgfutil@empty}
\def\pgf@arrowset#1#2{%
\pgfutil@ifundefined{pgf@arrow@code@#2}
{\PackageError{pgf}{Arrow #1 type ``#2'' unknown}{}}
{%
\edef\pgf@arrow@temp{#2}%
\ifx\pgf@arrow@temp\pgfutil@empty% ah. clear!
\expandafter\let\csname pgf@#1arrow\endcsname=\pgfutil@empty%
\expandafter\let\csname pgf@shorten@#1\endcsname=\pgfutil@empty%
\else%
%\pgf@arrow@prepare{#2}%
\expandafter\def\csname pgf@#1arrow\endcsname{\multiply\pgflinewidth by \pgflinewidth@arrow\relax\pgf@arrow@call{#2}}%
\expandafter\edef\csname pgf@shorten@#1\endcsname{\multiply\pgflinewidth by \noexpand\pgflinewidth@arrow\relax\expandafter\noexpand\csname pgf@arrow@right@#2\endcsname}%
\fi%
}%
}
\tikzset{
bigdiagramarrow/.style = {
-latex,
arrow thick
},
arrow line width/.code={
\pgfmathsetmacro\pgflinewidth@arrow{#1}
},
arrow line width=1,
arrow ultra thin/.style={arrow line width=0.25},
arrow very thin/.style={arrow line width=0.5},
arrow thin/.style={arrow line width=1},
arrow semithick/.style={arrow line width=1.5},
arrow thick/.style={arrow line width=2},
arrow very thick/.style={arrow line width=3},
arrow ultra thick/.style={arrow line width=4},
}
\makeatother
\begin{document}
\begin{tikzpicture}
\node [draw] (A) at (0, 0) {$A$};
\node [draw] (B) at (0, 1) {$B$};
\node [draw] (C) at (2, 1) {$C$};
\draw [bigdiagramarrow] (A) to (B);
\draw [out = 0, in = 180][bigdiagramarrow] (A) to (C);
\end{tikzpicture}
\end{document}
输出
答案2
既然有复杂的方法,为什么要采用简单的方法呢?
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node [draw] (A) at (0, 0) {$A$};
\node [draw] (B) at (0, 1) {$B$};
\node [draw] (C) at (2, 1) {$C$};
\draw [-latex] (A) -- (B);
\draw [out = 0, in = 180, -latex] (A) to (C);
\end{tikzpicture}
\end{document}