![使用阴影箭头将 tikz-forest 外部化](https://linux22.com/image/370896/%E4%BD%BF%E7%94%A8%E9%98%B4%E5%BD%B1%E7%AE%AD%E5%A4%B4%E5%B0%86%20tikz-forest%20%E5%A4%96%E9%83%A8%E5%8C%96.png)
我刚刚发现externalize
并想在我的文档中使用它,文档中包含许多带有阴影箭头的树。箭头的阴影是用我在这个网站上找到的一些“黑客”方法绘制的(不幸的是,我目前似乎找不到源代码)。它在我的文档中使用时运行良好——尽管速度很慢——但在外部化时会失败。
我收到这个错误
! Extra }, or forgotten \endgroup.
\pgf@externalend ->\unskip \egroup \egroup
{\def \pgf@external@trim {0}\def ...
l.88 \end{forest}
不幸的是,我不是 Tex 专家,似乎无法弄清楚出了什么问题。以下是 MWE:
\documentclass[a4paper,12pt, twoside,dvipsnames]{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize[mode=list and make, prefix=ext-tikz/]
\usepackage[external]{forest}
\usetikzlibrary{fadings, arrows.meta}
\makeatletter
\newif\iftikz@shading@path
\tikzset{
% There are three circumstances in which the fading sep is needed:
% 1. Arrows which do not update the bounding box (which is most of them).
% 2. Line caps/joins and mitres that extend outside the natural bounding
% box of the path (these are not calculated by PGF).
% 3. Other reasons that haven't been anticipated.
fading xsep/.store in=\pgfpathfadingxsep,
fading ysep/.store in=\pgfpathfadingysep,
fading sep/.style={fading xsep=#1, fading ysep=#1},
fading sep=0.0cm,
shading path/.code={%
% Prevent this stuff happning recursively.
\iftikz@shading@path%
\else%
\tikz@shading@pathtrue%
% \tikz@addmode installs the `modes' (e.g., fill, draw, shade)
% to be applied to the path. It isn't usualy for doing more
% changes to the path's construction.
\tikz@addmode{%
\pgfgetpath\pgf@currentfadingpath%
% Get the boudning box of the current path size including the fading sep
\pgfextract@process\pgf@fadingpath@southwest{\pgfpointadd{\pgfqpoint{\pgf@pathminx}{\pgf@pathminy}}%
{\pgfpoint{-\pgfpathfadingxsep}{-\pgfpathfadingysep}}}%%
\pgfextract@process\pgf@fadingpath@northeast{\pgfpointadd{\pgfqpoint{\pgf@pathmaxx}{\pgf@pathmaxy}}%
{\pgfpoint{\pgfpathfadingxsep}{\pgfpathfadingysep}}}%
% Clear the path
\pgfsetpath\pgfutil@empty%
% Interrupt the path and picture to create a fading.
\pgfinterruptpath%
\pgfinterruptpicture%
\begin{tikzfadingfrompicture}[name=.]
\path [shade=none,fill=none, #1] \pgfextra{%
% Set the softpath. Any transformations in #1 will have no effect.
% This will *not* update the bounding box...
\pgfsetpath\pgf@currentfadingpath%
% ...so it is done manually.
\pgf@fadingpath@southwest
\expandafter\pgf@protocolsizes{\the\pgf@x}{\the\pgf@y}%
\pgf@fadingpath@northeast%
\expandafter\pgf@protocolsizes{\the\pgf@x}{\the\pgf@y}%
};
% Now get the bounding of the picture.
\xdef\pgf@fadingboundingbox@southwest{\noexpand\pgfqpoint{\the\pgf@picminx}{\the\pgf@picminy}}%
\xdef\pgf@fadingboundingbox@northeast{\noexpand\pgfqpoint{\the\pgf@picmaxx}{\the\pgf@picmaxy}}%
%
\end{tikzfadingfrompicture}%
\endpgfinterruptpicture%
\endpgfinterruptpath%
% Install a rectangle that covers the shaded/faded path picture.
\pgfpathrectanglecorners{\pgf@fadingboundingbox@southwest}{\pgf@fadingboundingbox@northeast}%
% Make the fading happen.
\def\tikz@path@fading{.}%
\tikz@mode@fade@pathtrue%
\tikz@fade@adjustfalse%10pt
% Shift the fading to the mid point of the rectangle
\pgfpointscale{0.5}{\pgfpointadd{\pgf@fadingboundingbox@southwest}{\pgf@fadingboundingbox@northeast}}%
\edef\tikz@fade@transform{shift={(\the\pgf@x,\the\pgf@y)}}%
}%
\fi%
}
}
\begin{document}
\begingroup
\centering
\begin{forest}
[, phantom, for children={fit=band}, s sep'+=60pt
[ 2, name=l1 ]
[ 2, name=r1 ]
]
\path [left color=orange, right color=MidnightBlue, shading path={draw=transparent!0, dashed, -Latex}] (l1) .. controls ++(0,-1) and ++(0,-1) .. (r1);
\end{forest}
\endgroup
\end{document}
我尝试尽可能地精简示例,但代码仍然很多。该tikzset
部分是从此站点复制而来,老实说,我不知道它有什么用处 - 但除非forest
将其外部化,否则它还是可以工作的。
编辑:该问题似乎仅限于forest
,此 tikzpicture 可以毫无问题地外部化:
\begin{tikzpicture}
\path [left color=orange, right color=MidnightBlue, shading path={draw=transparent!0, dashed, -Latex}] (0,1) .. controls ++(0,-1) and ++(0,-1) .. (1,1);
\end{tikzpicture}