TeX Live 2021 中的 Tikz 铁路轨道问题

TeX Live 2021 中的 Tikz 铁路轨道问题

在我升级到 TeX Live 2021 之前,我对马克·维布罗的火车轨道。然而,在 TeX Live 2021 下,我遇到了非常奇怪的行为;他答案中的代码现在排版如下。

破损的铁轨

我也有类似的奇怪行为cfr 版本的曲目

不同的破碎铁轨

我已经在 TeX Live 2019 和 2020 上测试了这些轨道,它们都很好。我该如何更新此代码以与 TeX Live 2021 一起使用?

答案1

正如 muzimushi 的评论中提到的,旧代码依赖于一个拼写错误,该错误迫使 pgf 重新保存淡入淡出。您可以使用计数器获得类似的效果:

\documentclass[tikz, border=5]{standalone}
\usetikzlibrary{decorations,fit,fadings}
\newcounter{tracks}
% Layers
\pgfdeclarelayer{sleeper}
\pgfdeclarelayer{rail}
\pgfsetlayers{sleeper,rail,main}

\pgfdeclaredecoration{tracks}{final}{%
\state{final}{%
  \pgftransformreset% <- I think is possibly vital.
  %
  % Get bounding box of decorated path as a node.
  % Must do it this way using basic layer.
  \pgftransformshift{\pgfpointanchor{current path bounding box}{south west}}%
  \pgfcoordinate{@1}\pgfpointorigin%
  \pgftransformshift{\pgfpointanchor{current path bounding box}{north east}}%
  \pgfcoordinate{@2}\pgfpointorigin%
  \node [fit=(@1)(@2), inner sep=\railsep+2*\railwidth] (@@) {};
  %
  % Create a fading for the track.
  \pgfinterruptpicture%
    \stepcounter{tracks}% 
    \begin{tikzfadingfrompicture}[name=tracks\thetracks]
    \path[draw=transparent!0, line width=\railsep+2*\railwidth,
     postaction={draw=transparent!100, line width=\railsep}]
      \pgfextra{\pgfsetpath\pgfdecoratedpath};
    \useasboundingbox (@@.south west) (@@.north east);
  \end{tikzfadingfrompicture}%
  \endpgfinterruptpicture
  %
  % Draw sleepers.
  \ifx\sleeperlayer\emptylayer\else\pgfonlayer{\sleeperlayer}\fi%
  \draw [draw=\sleepercolor,line width=\sleeperlength, dash pattern=on \sleeperwidth off \sleepersep, every sleeper/.try]
    \pgfextra{\pgfsetpath\pgfdecoratedpath};
  \ifx\sleeperlayer\emptylayer\else\endpgfonlayer\fi%
  %
  % Draw the track
  \ifx\raillayer\emptylayer\else\pgfonlayer{\raillayer}\fi%
  \fill [path fading=tracks\thetracks, fit fading=false,
    fading transform={shift=(@@.center)}, fill=\railcolor]
   (@@.south west) rectangle (@@.north east);
   \ifx\raillayer\emptylayer\else\endpgfonlayer\fi%
}
}
\def\emptylayer{}
\tikzset{%
  track/.style={
    decoration=tracks, decorate
  },
  decorations/.cd,
    rail sep/.store in=\railsep,
    rail width/.store in=\railwidth,
    rail color/.store in=\railcolor,
    rail layer/.store in=\raillayer,
    sleeper sep/.store in=\sleepersep,
    sleeper width/.store in=\sleeperwidth,
    sleeper length/.store in=\sleeperlength,
    sleeper color/.store in=\sleepercolor,
    sleeper layer/.store in=\sleeperlayer,
    rail sep=4pt,
    rail width=1pt,
    rail color=black,
    rail layer=rail,
    sleeper sep=6pt,
    sleeper width=1pt,
    sleeper length=10pt,
    sleeper color=gray,
    sleeper layer=sleeper,
}
\begin{document}
\begin{tikzpicture}
\draw [track] (-2,5) to (0,5) to[out=  0,in=270] (2,8);
\draw [track] (6,5) to (4,5) to[out=180,in=270] (2,8) to (2,10);
\end{tikzpicture}
\end{document} 

在此处输入图片描述

相关内容