![TikzCD 装饰箭头(波浪形)和路径产生噩梦般的结果](https://linux22.com/image/453889/TikzCD%20%E8%A3%85%E9%A5%B0%E7%AE%AD%E5%A4%B4%EF%BC%88%E6%B3%A2%E6%B5%AA%E5%BD%A2%EF%BC%89%E5%92%8C%E8%B7%AF%E5%BE%84%E4%BA%A7%E7%94%9F%E5%99%A9%E6%A2%A6%E8%88%AC%E7%9A%84%E7%BB%93%E6%9E%9C.png)
基于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/86和https://tex.stackexchange.com/a/655154/86。
rounded corners
圆角是在构建路径时实现的,因此在构建原始路径并在装饰之前关闭该键就足够了。
第一个解决方案基于https://tex.stackexchange.com/a/38995/86rounded corners
,通过在路径构造结束时关闭选项来工作。问题在于,通过使用to path
,to 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}