TikZ 装饰路径和定点算术库

TikZ 装饰路径和定点算术库

背景:我尝试将多个装饰应用于 TikZ 图片中的路径。在此特定情况下,我的尝试失败,因为超出了 PGF 可以计算的最大尺寸。

这并不是我遇到麻烦的路径(因为该路径深深嵌入在复杂的 中tikzpicture),但它很相似,并在响应评论中的请求时说明了问题。我不确定我试图做的事情是否有点疯狂,但无论如何:

\documentclass[tikz]{standalone}
\usepackage{fp}
\usetikzlibrary{calc,decorations.pathmorphing,decorations.text,fixedpointarithmetic}
\begin{document}

  \begin{tikzpicture}
    [
    nant/.append style={draw=#1, double=#1!25, double distance between line centers=5.5pt, line width=.5pt, decorate, decoration={snake, segment length=10pt, amplitude=.5pt}},
    ]
    \node (n1) [draw] {Some Information};
    \node (n2) [anchor=south east, yshift=7.5pt, draw] at (n1.north east) {Terminology};
    \node (n3) [anchor=north east, draw, xshift=-25mm] at (n1.south west) {Something};
    \coordinate (nant4) at ($(n1.north east |- n2.south)!1/2!(n1.north east)$);
    \coordinate (nant3) at ($(n1.north west |- nant4) + (5pt,0)$);
    \coordinate (nant2) at ($(n3.east) + (35pt,10pt)$);
    \coordinate (nant1) at ($(n3.east |- nant2) + (10pt,-7.5pt)$);
    \path [nant=blue,postaction={decoration={text along path, text={|\scriptsize\scshape|the flow of stuff ||}, text color=blue, raise=-.5pt}, decorate}] (nant1) to [out=0, in=-135] (nant2) to [out=45, in=180] (nant3) -- (nant4);
%   \path [nant=blue] (nant1) to [out=0, in=-135] (nant2) to [out=45, in=180] (nant3) -- (nant4);
%   \path [postaction={decoration={text along path, text={|\scriptsize\scshape|the flow of stuff ||}, text color=blue, raise=-.5pt}, decorate}] ($(nant2) + (0,-4pt)$) to [out=45, in=180] ($(nant3) + (0,-1.25pt)$) -- ($(nant4) + (0,-1.25pt)$);
  \end{tikzpicture}

\end{document}

注释行显示了我用来近似我想要的结果的方法,以防万一不清楚预期的结果是什么,并省去别人提出建议的麻烦。

由...来指导Alain Matthes 的回答,我尝试使用fixedpointarithmetic图片中特定路径的库。但是,这似乎会导致pdflatex无限期挂起。(我知道这个库会减慢速度,但我认为它不应该花这么长时间。至少,当它不挂起时,它会在合理的时间内工作。)

简化一下,我想出了这个最小(非)工作示例:

\documentclass[tikz]{standalone}
\usepackage{fp}
\usetikzlibrary{calc,decorations.pathmorphing,decorations.text,fixedpointarithmetic}
\begin{document}

  \begin{tikzpicture}
    [
    nant/.append style={draw=#1, double=#1!25, double distance between line centers=5.5pt, line width=.5pt, decorate, decoration={snake, segment length=10pt, amplitude=.5pt}},
    ]
    \path [nant=red] (0,5) -- (10,10);
    \path [nant=blue] (0,0) to [out=190, in=30] (10,5);
    \path [fixed point arithmetic, nant=green] (0,10) -- (10,15);
    \path [fixed point arithmetic, nant=black] (0,0) to [out=190, in=30] (10,5);
  \end{tikzpicture}

\end{document}

如果我注释掉第四条路径,前三条路径可以很好地绘制,但第四条路径会导致挂起。鉴于 PGF 的数学解析器可以处理这条路径而无需使用固定点,因此这大概不是容量问题。因此,尝试绘制曲线路径似乎有些问题,而不是直线。

我在这里做错了什么?手册没有过多提到不能使用定点的情况,所以我不知道要寻找什么或从哪里开始。任何诊断建议都将不胜感激。

答案1

您的text along path装饰已应用于路径变形为装饰snake(由许多小段组成的线)。分别绘制两个装饰(第一种解决方案)或通过 apreaction和 a postaction(第二种解决方案)绘制装饰,无需使用库即可获得良好的结果fixedpointarithmetic

笔记:fixedpointarithmetic在中使用库tikzpicture,您必须定义/pgf/fixed point arithmetic(如我在以下代码中的注释)。

在此处输入图片描述

第一种解决方案(两条路径)

\documentclass[tikz]{standalone}
%\usepackage{fp}
\usetikzlibrary{calc,decorations.pathmorphing,decorations.text}%,fixedpointarithmetic}
\begin{document}

  \begin{tikzpicture}%[/pgf/fixed point arithmetic]
    \tikzset{
    nant/.append style={draw=#1, double=#1!25, double distance between line centers=5.5pt,
      line width=.5pt, decorate, decoration={snake, segment length=10pt, amplitude=.5pt}},
    }
    \node (n1) [draw] {Some Information};
    \node (n2) [anchor=south east, yshift=7.5pt, draw] at (n1.north east) {Terminology};
    \node (n3) [anchor=north east, draw, xshift=-25mm] at (n1.south west) {Something};
    \coordinate (nant4) at ($(n1.north east |- n2.south)!1/2!(n1.north east)$);
    \coordinate (nant3) at ($(n1.north west |- nant4) + (5pt,0)$);
    \coordinate (nant2) at ($(n3.east) + (35pt,10pt)$);
    \coordinate (nant1) at ($(n3.east |- nant2) + (10pt,-7.5pt)$);
    \path [nant=blue]
    (nant1) to [out=0, in=-135] (nant2) to [out=45, in=180] (nant3) -- (nant4);
    \path [decoration={text along path,text={|\scriptsize\scshape|the flow of stuff ||},
      text color=blue, raise=-.5pt}, decorate]
    (nant1) to [out=0, in=-135] (nant2) to [out=45, in=180] (nant3) -- (nant4);
  \end{tikzpicture}

\end{document}

第二种解决方案(带有preaction和 的单路径postaction

\documentclass[tikz]{standalone}
%\usepackage{fp}
\usetikzlibrary{calc,decorations.pathmorphing,decorations.text}%,fixedpointarithmetic}
\begin{document}

  \begin{tikzpicture}%[/pgf/fixed point arithmetic]
    \tikzset{
    nant/.append style={draw=#1, double=#1!25, double distance between line centers=5.5pt,
      line width=.5pt, decorate, decoration={snake, segment length=10pt, amplitude=.5pt}},
    }
    \node (n1) [draw] {Some Information};
    \node (n2) [anchor=south east, yshift=7.5pt, draw] at (n1.north east) {Terminology};
    \node (n3) [anchor=north east, draw, xshift=-25mm] at (n1.south west) {Something};
    \coordinate (nant4) at ($(n1.north east |- n2.south)!1/2!(n1.north east)$);
    \coordinate (nant3) at ($(n1.north west |- nant4) + (5pt,0)$);
    \coordinate (nant2) at ($(n3.east) + (35pt,10pt)$);
    \coordinate (nant1) at ($(n3.east |- nant2) + (10pt,-7.5pt)$);
    \path[preaction={nant=blue},
    postaction={decoration={text along path,text={|\scriptsize\scshape|the flow of stuff ||},
        text color=blue, raise=-.5pt}, decorate}]
    (nant1) to [out=0, in=-135] (nant2) to [out=45, in=180] (nant3) -- (nant4);
  \end{tikzpicture}

\end{document}

答案2

按照您的建议,添加后我可以毫无问题地编译您的代码fixed point arithmetic。编译需要在我 5 年前的 PC 上进行:

  • XeLaTeX 70 秒(pdf 大小 8Kb)
  • PDFLaTeX 需 72 秒(pdf 大小 27Kb)
  • LuaLaTeX 耗时 94 秒(pdf 大小 27Kb)

在现代手机上可能会更快;)

在此处输入图片描述

更新:以下是您的 MnWE (30 秒) 的结果:

在此处输入图片描述

相关内容