tikz-cd 中的 3D 箭头

tikz-cd 中的 3D 箭头

有没有办法在 tikz-cd 上实现“3D 倾斜”效果?我的意思是下图中的右箭头,这是我使用以下代码制作的另一个 tex.SE 答案在此处输入图片描述 输出结果仍存在许多问题,例如 α⊗id_id_T 标签弯曲且未对齐,角度不正确,并且必须使用幻影箭头手动添加 T⊗α(第一张图,从 2-2 到 1-3)和 α(第二张图,从 4-2 到 3-3)标签,因为将它们与 2 箭头一起倾斜会使其难以阅读......

以下是上图的代码:

\newsavebox{\BoxOne}
\savebox{\BoxOne}{
    \begin{tikzcd}[row sep=4.5em, column sep=4.5em, background color=backgroundColor, ampersand replacement=\&]
        {}
        \arrow[d, "\alpha\tcirc\biid_{\biid_{\monadT}}"{rotate=-140,description}, Rightarrow]
        \\
        {}
    \end{tikzcd}
}
\newsavebox{\BoxThree}
\savebox{\BoxThree}{
    \begin{tikzcd}[row sep=3.6em, column sep=3.6em, background color=backgroundColor, ampersand replacement=\&]
        {}
        \arrow[d, Leftarrow]
        \\
        {}
    \end{tikzcd}
}
    \begin{tikzcd}[row sep={4.5em,between origins}, column sep={4.5em,between origins}, background color=backgroundColor, ampersand replacement=\&]
        \monadT^{4}
        \arrow[rr, "\monadT^{2}\tcirc\mu"description]
        \arrow[dd, "\mu\tcirc\monadT^{2}"'description]
        \arrow[rd, "\monadT\tcirc(\mu\tcirc\monadT)"{name=1,description}]
        \&
        \&
        \monadT^{3}
        \arrow[rd, "\monadT\tcirc\mu"description]
        \&
        \\
        \&
        \monadT^{3}
        \arrow[rr, "\monadT\tcirc\mu"description]
        \arrow[dd, "\mu\tcirc\monadT"description]
        \&
        \&
        \monadT^{2}
        \arrow[dd, "\mu"description]
        \\
        \monadT^{3}
        \arrow[rd, "\mu\tcirc\monadT"{name=2,description}]
        \&
        \&
        \&
        \\
        \&
        \monadT^{2}
        \arrow[rr, "\mu"'description]
        \&\&
        \monadT^{1}
        % 2-Arrows
        \arrow[from=3-1,to=2-2,"\rotslant{-30}{-30}{\rotatebox{140}{\usebox{\BoxOne}}}",phantom,yshift=-0.25em]
        \arrow[from=2-2,to=1-3,"\rotslant{-22.5}{+22.5}{\rotatebox{0}{\usebox{\BoxThree}}}",phantom]
        \arrow[from=2-2,to=1-3,"\scalebox{0.75}{$\monadT\tcirc\alpha$}"description,phantom]
        \arrow[from=4-2,to=2-4,"\alpha"description,Rightarrow,shorten=3.0em]
    \end{tikzcd}
&=
\newsavebox{\BoxTwo}
\savebox{\BoxTwo}{
    \begin{tikzcd}[row sep=3.6em, column sep=3.6em, background color=backgroundColor, ampersand replacement=\&]
        {}
        \arrow[d, "\alpha"{rotate=-140,description}, Rightarrow]
        \\
        {}
    \end{tikzcd}
}
\newsavebox{\BoxThree}
\savebox{\BoxThree}{
    \begin{tikzcd}[row sep=3.6em, column sep=3.6em, background color=backgroundColor, ampersand replacement=\&]
        {}
        \arrow[d, Leftarrow]
        \\
        {}
    \end{tikzcd}
}
\begin{tikzcd}[row sep={4.5em,between origins}, column sep={4.5em,between origins}, background color=backgroundColor, ampersand replacement=\&]
    \monadT^{4}
    \arrow[rr, "\monadT^{2}\tcirc\mu"description]
    \arrow[dd, "\mu\tcirc\monadT^{2}"'description]
    \&
    \&
    \monadT^{3}
    \arrow[dd, "\mu\tcirc\monadT"description,dashed]
    \arrow[rd, "\monadT\tcirc\mu"description]
    \&
    \\
    \&
    \&
    \&
    \monadT^{2}
    \arrow[dd, "\mu"]
    \\
    \monadT^{3}
    \arrow[rr, "\monadT\tcirc\mu"description,dashed]
    \arrow[rd, "\mu\tcirc\monadT"{name=2,description}]
    \&
    \&
    \monadT^{2}
    \arrow[rd, "\mu"description,dashed]
    \&
    \\
    \&
    \monadT^{2}
    \arrow[rr, "\mu"']
    \&\&
    \monadT^{1}
    % 2-Arrows
    \arrow[from=3-3,to=2-4,"\rotslant{-30}{-30}{\rotatebox{140}{\usebox{\BoxTwo}}}",phantom,yshift=-0.25em]
    \arrow[from=4-2,to=3-3,"\rotslant{-22.5}{+22.5}{\rotatebox{0}{\usebox{\BoxThree}}}",phantom]
    \arrow[from=4-2,to=3-3,"\scalebox{0.75}{$\alpha$}"description,phantom]
    \arrow[from=3-1,to=1-3,"\alpha_{\alpha}^{-1}"description,Rightarrow,shorten=3.0em]
\end{tikzcd}

那里的 \rotslant 宏来自tex.SE 答案我之前提到过。

另外,是否有可能在更一般的曲面上(即立方体表面上的 2 箭头除外)获得这样的 2 箭头效果,例如图中所示的效果 在此处输入图片描述

编辑:这是第一张图像的可编译代码(输出略有不同(例如字体、间距),但 3D 箭头的行为相同):

\documentclass[english,11pt]{standalone}
\RequirePackage{luatex85}
\newcommand{\monadT}{\mathrm{T}}
\newcommand{\biid}{\mathsf{id}}
\newcommand{\tcirc}{\otimes}
\usepackage{tikz}
\usepackage{tikz-cd}
\usetikzlibrary{arrows.meta,calc,positioning,decorations.markings,fit,patterns,decorations.pathreplacing,3d}
\usepackage{libertine}
\usepackage[libertine]{newtxmath}
% 3D Rotate
\usepackage{fp}
\newsavebox\foobox
\newcommand\slbox[2]{%
    \FPdiv{\result}{#1}{57.296}% CONVERT deg TO rad
    \FPtan{\result}{\result}%
    \slantbox[\result]{#2}%
}%
\newcommand{\slantbox}[2][30]{%
        \mbox{%
        \sbox{\foobox}{#2}%
        \hskip\wd\foobox
        \pdfsave
        \pdfsetmatrix{1 0 #1 1}%
        \llap{\usebox{\foobox}}%
        \pdfrestore
}}
\newcommand\rotslant[3]{\rotatebox{#1}{\slbox{#2}{#3}}}
\begin{document} 
\newsavebox{\BoxOne}
\savebox{\BoxOne}{
    \begin{tikzcd}[row sep=4.5em, column sep=4.5em, ampersand replacement=\&]
        {}
        \arrow[d, "\alpha\tcirc\biid_{\biid_{\monadT}}"{rotate=-140,description}, Rightarrow]
        \\
        {}
    \end{tikzcd}
}
\newsavebox{\BoxThree}
\savebox{\BoxThree}{
    \begin{tikzcd}[row sep=3.6em, column sep=3.6em, ampersand replacement=\&]
        {}
        \arrow[d, Leftarrow]
        \\
        {}
    \end{tikzcd}
}
    \begin{tikzcd}[row sep={4.5em,between origins}, column sep={4.5em,between origins}, ampersand replacement=\&]
        \monadT^{4}
        \arrow[rr, "\monadT^{2}\tcirc\mu"description]
        \arrow[dd, "\mu\tcirc\monadT^{2}"'description]
        \arrow[rd, "\monadT\tcirc(\mu\tcirc\monadT)"{name=1,description}]
        \&
        \&
        \monadT^{3}
        \arrow[rd, "\monadT\tcirc\mu"description]
        \&
        \\
        \&
        \monadT^{3}
        \arrow[rr, "\monadT\tcirc\mu"description]
        \arrow[dd, "\mu\tcirc\monadT"description]
        \&
        \&
        \monadT^{2}
        \arrow[dd, "\mu"description]
        \\
        \monadT^{3}
        \arrow[rd, "\mu\tcirc\monadT"{name=2,description}]
        \&
        \&
        \&
        \\
        \&
        \monadT^{2}
        \arrow[rr, "\mu"'description]
        \&\&
        \monadT^{1}
        % 2-Arrows
        \arrow[from=3-1,to=2-2,"\rotslant{-30}{-30}{\rotatebox{140}{\usebox{\BoxOne}}}",phantom,yshift=-0.25em]
        \arrow[from=2-2,to=1-3,"\rotslant{-22.5}{+22.5}{\rotatebox{0}{\usebox{\BoxThree}}}",phantom]
        \arrow[from=2-2,to=1-3,"\scalebox{0.75}{$\monadT\tcirc\alpha$}"description,phantom]
        \arrow[from=4-2,to=2-4,"\alpha"description,Rightarrow,shorten=3.0em]
    \end{tikzcd}
=
\newsavebox{\BoxTwo}
\savebox{\BoxTwo}{
    \begin{tikzcd}[row sep=3.6em, column sep=3.6em, ampersand replacement=\&]
        {}
        \arrow[d, "\alpha"{rotate=-140,description}, Rightarrow]
        \\
        {}
    \end{tikzcd}
}
\newsavebox{\BoxFour}
\savebox{\BoxFour}{
    \begin{tikzcd}[row sep=3.6em, column sep=3.6em, ampersand replacement=\&]
        {}
        \arrow[d, Leftarrow]
        \\
        {}
    \end{tikzcd}
}
\begin{tikzcd}[row sep={4.5em,between origins}, column sep={4.5em,between origins}, ampersand replacement=\&]
    \monadT^{4}
    \arrow[rr, "\monadT^{2}\tcirc\mu"description]
    \arrow[dd, "\mu\tcirc\monadT^{2}"'description]
    \&
    \&
    \monadT^{3}
    \arrow[dd, "\mu\tcirc\monadT"description,dashed]
    \arrow[rd, "\monadT\tcirc\mu"description]
    \&
    \\
    \&
    \&
    \&
    \monadT^{2}
    \arrow[dd, "\mu"]
    \\
    \monadT^{3}
    \arrow[rr, "\monadT\tcirc\mu"description,dashed]
    \arrow[rd, "\mu\tcirc\monadT"{name=2,description}]
    \&
    \&
    \monadT^{2}
    \arrow[rd, "\mu"description,dashed]
    \&
    \\
    \&
    \monadT^{2}
    \arrow[rr, "\mu"']
    \&\&
    \monadT^{1}
    % 2-Arrows
    \arrow[from=3-3,to=2-4,"\rotslant{-30}{-30}{\rotatebox{140}{\usebox{\BoxTwo}}}",phantom,yshift=-0.25em]
    \arrow[from=4-2,to=3-3,"\rotslant{-22.5}{+22.5}{\rotatebox{0}{\usebox{\BoxFour}}}",phantom]
    \arrow[from=4-2,to=3-3,"\scalebox{0.75}{$\alpha$}"description,phantom]
    \arrow[from=3-1,to=1-3,"\alpha_{\alpha}^{-1}"description,Rightarrow,shorten=3.0em]
\end{tikzcd}
\end{document}

答案1

更新

简化plane风格

回答

我定义一个键plane={<coord-1> and <coord-2>}来让路径放在依赖于 x 单位向量(0, 0) --> <coord-1>和 y 单位向量的特定平面上(0, 0) --> <coord-2>

在您的情况下,row sepcolumn sep都是between origins,因此您可以计算两个向量的精确结果。 在此处输入图片描述

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{3d, cd}
\newcommand{\monadT}{\mathrm{T}}
\newcommand{\biid}{\mathsf{id}}
\newcommand{\tcirc}{\otimes}
\makeatletter
\tikzset{
  plane/.style args={#1and#2}{
    plane x={#1},
    plane y={#2},
    canvas is plane,
  }
}
\makeatother

\begin{document}
\begin{tikzcd}[row sep={4.5em,between origins}, column sep={4.5em,between origins}, ampersand replacement=\&]
  \monadT^{4}
  \arrow[rr, "\monadT^{2}\tcirc\mu"description]
  \arrow[dd, "\mu\tcirc\monadT^{2}"'description]
  \arrow[rd, "\monadT\tcirc(\mu\tcirc\monadT)"{name=1,description}]
  \&
  \&
  \monadT^{3}
  \arrow[rd, "\monadT\tcirc\mu"description]
  \&
  \\
  \&
  \monadT^{3}
  \arrow[rr, "\monadT\tcirc\mu"description]
  \arrow[dd, "\mu\tcirc\monadT"description]
  \&
  \&
  \monadT^{2}
  \arrow[dd, "\mu"description]
  \\
  \monadT^{3}
  \arrow[rd, "\mu\tcirc\monadT"{name=2,description}]
  \&
  \&
  \&
  \\
  \&
  \monadT^{2}
  \arrow[rr, "\mu"'description]
  \&\&
  \monadT^{1}
  % 2-Arrows
  \arrow[from=3-1,to=2-2,"\alpha\tcirc\biid_{\biid_{\monadT}}"{description, plane={(2^.5/2, -2^.5/2) and (0, 1)}, text=red}, Rightarrow]
  \arrow[from=2-2,to=1-3,"\monadT\tcirc\alpha"{description, plane={(1, 0) and (-2^.5/2, 2^.5/2)}, text=red}]
\end{tikzcd}
\end{document}

至于在曲面上放置一段文字,我没有找到好的办法。以下代码只是为了好玩。

在此处输入图片描述

\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{calc, 3d, cd, decorations.markings}
\makeatletter
\newcounter{tangent}
\tikzset{
  tangent/.style args={#1:#2:#3}{
    postaction=decorate,
    decoration={
      markings,
      mark=at position 0 with {
        \setcounter{tangent}{0}
        \pgfmathparse{(#2-#1)/(#3-1)}
        \global\let\mystep\pgfmathresult
      },
      mark=between positions #1 and #2 step \mystep with {
        \stepcounter{tangent}
        \edef\index{\number\value{tangent}}
        \typeout{xxx \index}
        \coordinate (t-o-\index) at (0, 0);
        \coordinate (t-x-\index) at (1, 0);
        \coordinate (t-y-\index) at (0, 1);
      }
    },
  },
  plane/.style args={#1and#2}{
    plane x={#1},
    plane y={#2},
    canvas is plane,
  }
}
\makeatother

\begin{document}
\begin{tikzpicture}[thick]
  \draw (0, 0) -- (0, 2) (11, 0) -- (11, 2);
  \path[tangent=.1:.9:11] (0, 0) arc (180:360:5.5cm and 2cm);
  \draw (0, 0) arc (180:360:5.5cm and 2cm)
  \foreach \i  in {1,...,11} {
    node[plane={($(t-x-\i)-(t-o-\i)$) and (0, 1)}, above, align=center] at (t-o-\i) {\i\\\i\\\i\\\i}
  };
  \coordinate (a) at (5.5, 16);
  \draw (a) -- (0, 2) (a) -- (11, 2);
  \path[tangent=.1:.9:11] (0, 2) arc (180:360:5.5cm and 2cm);
  \draw (0, 2) arc (180:360:5.5cm and 2cm)
  \foreach \i  in {1,...,11} {
    node[
      plane={($(t-x-\i)-(t-o-\i)$) and ($(t-o-\i)!1cm!(a)-(t-o-\i)$)},
      above, align=center, inner sep=0pt,
    ] at (t-o-\i) {\i\\\i\\\i\\\i\\\i\\\i\\\i\\\i\\\i\\\i\\\i\\\i\\\i\\\i\\\i\\\i\\\i\\\i\\\i\\\i\\\i\\\i\\\i\\\i\\\i\\\i\\}
  };
\end{tikzpicture}
\end{document}

相关内容