TikzCD 装饰箭头(波浪形)和路径产生噩梦般的结果

TikzCD 装饰箭头(波浪形)和路径产生噩梦般的结果

基于xy-pic 中的波浪箭头蛇形引理代码https://ctan.math.washington.edu/tex-archive/graphics/pgf/contrib/tikz-cd/tikz-cd-doc.pdf

% minimal working example (MWE)
\documentclass{article}


\usepackage{tikz-cd}
\usetikzlibrary{decorations.pathmorphing}

\begin{document}

\begin{center}
\begin{tikzcd}[
  arrows={decorate, decoration={snake,segment length = 1.6mm,amplitude=0.2mm}}
]
(L_1,\ldots, L_r) \arrow{r} & \big((D_1,n_1),\ldots, (D_r,n_r)\big) \arrow{r} & (D_1^{n_i}, \ldots, D_r^{n_r}) \simeq (L_{\sigma(1)},\ldots, L_{\sigma(r)}) \arrow[l,rounded corners, to path={ -- ([xshift=2ex]\tikztostart.east)
|- ([yshift=1ex]\tikztotarget.north) -- (\tikztotarget)}]
\end{tikzcd}
\end{center}

\end{document}

这产生了 在此处输入图片描述

如果我添加decorate=false最后一个箭头,它会产生更漂亮的效果 在此处输入图片描述

但是,我还是想知道是否有办法射出decorate我的to path箭而不会出什么问题。

答案1

以下是一些解决方案,基于https://tex.stackexchange.com/a/38995/86https://tex.stackexchange.com/a/655154/86

rounded corners圆角是在构建路径时实现的,因此在构建原始路径并在装饰之前关闭该键就足够了。

第一个解决方案基于https://tex.stackexchange.com/a/38995/86rounded corners,通过在路径构造结束时关闭选项来工作。问题在于,通过使用to pathto path构造中给出的任何选项都在组内执行,因此在处理路径时会被遗忘。一种选择是制作所需sharp corners键的全局版本,但也可以使用一些\aftergroup技巧来避免使事情变得全局化。这依赖于圆角键具有内置条件的事实,该条件用于确定是否应考虑圆角。

然后还有另一种方法可以利用 的分组to path:将rounded corners选项放在 的定义内to path。由于 是to path此路径构造的唯一元素,这意味着rounded corners选项在整个路径构造过程中都适用,但在应用蛇形装饰时不存在。

最后一种解决方案基于https://tex.stackexchange.com/a/655154/86rounded corners,通过在装饰开始前关闭来实现。

\documentclass{article}
%\url{https://tex.stackexchange.com/q/655090/86}

\usepackage{tikz-cd}
\usetikzlibrary{decorations.pathmorphing}

\makeatletter
% This is the key that disables rounded corners outside the group.
\tikzset{
  disable rounded corners/.code={
    \aftergroup\pgf@arccornersfalse
  },
  decorate with sharp corners/.style={
    /pgf/every decoration/.append style={
      /tikz/sharp corners
    }
  }
}
\makeatother

\begin{document}

% Version without decoration to show that the rounded corners *is* applied
\begin{center}
\begin{tikzcd}[
  arrows={
%    decorate,
    decoration={snake,segment length = 1.6mm,amplitude=0.2mm}
  }
]
(L_1,\ldots, L_r) \arrow{r} & \big((D_1,n_1),\ldots, (D_r,n_r)\big) \arrow{r} & (D_1^{n_i}, \ldots, D_r^{n_r}) \simeq (L_{\sigma(1)},\ldots, L_{\sigma(r)}) \arrow[l, rounded corners, to path={ -- ([xshift=2ex]\tikztostart.east)
|- ([yshift=1ex]\tikztotarget.north) -- (\tikztotarget) [disable rounded corners]}]
\end{tikzcd}
\end{center}

% Version with decoration to show that it isn't "wild"
\begin{center}
\begin{tikzcd}[
  arrows={
    decorate,
    decoration={snake,segment length = 1.6mm,amplitude=0.2mm}}
]
(L_1,\ldots, L_r) \arrow{r} & \big((D_1,n_1),\ldots, (D_r,n_r)\big) \arrow{r} & (D_1^{n_i}, \ldots, D_r^{n_r}) \simeq (L_{\sigma(1)},\ldots, L_{\sigma(r)}) \arrow[l, rounded corners, to path={ -- ([xshift=2ex]\tikztostart.east)
|- ([yshift=1ex]\tikztotarget.north) -- (\tikztotarget) [disable rounded corners]}]
\end{tikzcd}
\end{center}

% Version with `rounded corners` inside the group, no decoration
\begin{center}
\begin{tikzcd}[
  arrows={
%    decorate,
    decoration={snake,segment length = 1.6mm,amplitude=0.2mm}}
]
(L_1,\ldots, L_r) \arrow{r} & \big((D_1,n_1),\ldots, (D_r,n_r)\big) \arrow{r} & (D_1^{n_i}, \ldots, D_r^{n_r}) \simeq (L_{\sigma(1)},\ldots, L_{\sigma(r)}) \arrow[l, to path={[rounded corners] -- ([xshift=2ex]\tikztostart.east)
|- ([yshift=1ex]\tikztotarget.north) -- (\tikztotarget)}]
\end{tikzcd}
\end{center}

% Version with `rounded corners` inside the group
\begin{center}
\begin{tikzcd}[
  arrows={
    decorate,
    decoration={snake,segment length = 1.6mm,amplitude=0.2mm}}
]
(L_1,\ldots, L_r) \arrow{r} & \big((D_1,n_1),\ldots, (D_r,n_r)\big) \arrow{r} & (D_1^{n_i}, \ldots, D_r^{n_r}) \simeq (L_{\sigma(1)},\ldots, L_{\sigma(r)}) \arrow[l, to path={[rounded corners] -- ([xshift=2ex]\tikztostart.east)
|- ([yshift=1ex]\tikztotarget.north) -- (\tikztotarget)}]
\end{tikzcd}
\end{center}

% Version which disables rounded corners just before the decoration starts
\begin{center}
\begin{tikzcd}[
  arrows={
    decorate,
    decorate with sharp corners,
    decoration={
      snake,segment length = 1.6mm,amplitude=0.2mm}}
]
(L_1,\ldots, L_r) \arrow{r} & \big((D_1,n_1),\ldots, (D_r,n_r)\big) \arrow{r} & (D_1^{n_i}, \ldots, D_r^{n_r}) \simeq (L_{\sigma(1)},\ldots, L_{\sigma(r)}) \arrow[l, rounded corners, to path={ -- ([xshift=2ex]\tikztostart.east)
|- ([yshift=1ex]\tikztotarget.north) -- (\tikztotarget)}]
\end{tikzcd}
\end{center}


\end{document}

路径上有圆角和蛇形装饰

(当我只有一个解决方案时,图片就生成了 - 但所有装饰版本看起来都一样。)

答案2

正如@Qrrbrbirlbel 所评论的,rounded corners与 配合使用效果不佳snake。但您可以绘制arc带有蛇形装饰的 。一种选择是删除有问题的箭头,并TikZ使用 将其替换为普通命令execute at end picture=

在此处输入图片描述

使用|[alias=<name>]|为所需的单元格命名,然后使用\draw箭头。

我曾经tikzset制作一个名为的样式,snakearrow因为它需要被引用两次(一次在 tikzcd 中,一次用于命令\draw)。

最后,我添加了post length=.5mm一些东西让箭头的末端看起来更美观。

以下是代码:

\documentclass{article}

\usepackage{tikz-cd}
\usetikzlibrary{decorations.pathmorphing}

\tikzset{snakearrow/.style={decorate, decoration={snake, segment length = 1.6mm, amplitude=0.2mm, post length=.5mm}}}

\begin{document}

\begin{center}
\begin{tikzcd}[
   arrows={snakearrow},
   execute at end picture={\draw[->, snakearrow](Z1.east) arc (-90:90:.25)--([yshift=1.25mm, xshift=2mm]Z2.north) arc (90:180:.2);}
]
(L_1,\ldots, L_r) \arrow{r} & |[alias=Z2]|\big((D_1,n_1),\ldots, (D_r,n_r)\big) \arrow{r} & |[alias=Z1]|(D_1^{n_i}, \ldots, D_r^{n_r}) \simeq (L_{\sigma(1)},\ldots, L_{\sigma(r)})
\end{tikzcd}
\end{center}

\end{document}

相关内容