TikZ CD – Creating Custom Arrow Shapes in TikZ-CD

tikz-cd

The tikz-cd package comes with plenty of arrow head and tail options, but there are some more adventurous applications that are harder to implement. In my particular case, I would like to replace the arrow with a long triangle, as illustrated in this mock-up:

enter image description here

There are dedicated chemistry notation packages with this kind of arrow/bond packages available, but I want the output to be consistent with the other diagrams I have in my work, so a tikz-cd-based option would be preferred. A solid triangle would also be acceptable if that is easier for whatever reason.

MWE (outputs dashed line where I would like the triangle to be):

\documentclass[11pt]{article}
\usepackage{tikz-cd}

\begin{document}

\begin{tikzcd}
K \ar[dr,dashed, no head] & & \\
& A \ar[dr,two heads] & \\
& & X
\end{tikzcd}

\end{document}

Best Answer

So, here's a solution that involves remember picture and to draw afterwards your tikz-cd, but I think it could be enough for your purpose.

new arrow type on tikz-cd

\documentclass[11pt]{article}
\usepackage{tikz-cd}
\usetikzlibrary{calc}

\newcommand{\triar}[2]{
    \draw[orange] ($(#2)!0.2!(#1)$) -- ($ (#2)!0.8! 10:(#1) $) -- ($ (#2)!0.8! -10:(#1) $)  --cycle;
    }
    
\begin{document}

    \begin{tikzcd}[remember picture]
        |[alias=K]|K  & & \\
        & |[alias=A]|A \ar[dr,two heads] & \\
        & & X
    \end{tikzcd}
    
    \begin{tikzpicture}[overlay,remember picture]
        \triar{K}{A};
    \end{tikzpicture}

\end{document}

If you're not familiar with the calc library, when you type ($ (#2)!0.8! 10:(#1) $), it means the point between arg2 and arg1 (here between A and K), but with an additional turn by 10°. The triangle is made with this. You can change the value of the angle like you want.

Of course, the orange colour is only here to emphasize the new arrow.

EDIT

Here's a little variation, letting you pass the angle as a parameter, because on more complex diagrams, it could be interesting to customize that point.

\documentclass[11pt]{article}
\usepackage{tikz-cd}
\usetikzlibrary{calc}

\newcommand{\triar}[3]{
    \draw[orange] ($(#2)!0.1!(#1)$) -- ($ (#2)!0.9! #3:(#1) $) -- ($ (#2)!0.9! -#3:(#1) $)  --cycle;
    }
    
\begin{document}
    \begin{tikzcd}[remember picture]
        |[alias=A]|A \arrow{d} \arrow{r}[near start]{\phi}[near end]{\psi}
        & |[alias=B]|B  & |[alias=E]| E\\
        |[alias=C]|C \arrow[red]{r}[blue,below]{\eta}
        & |[alias=D]|D \arrow[purple]{r}[green,below]{\nu} & |[alias=F]| F
    \end{tikzcd}
    
    \begin{tikzpicture}[overlay,remember picture]
        \triar{E}{C}{2};
    \end{tikzpicture}

\end{document}

I also changed the percentage to .1 and .9 for start and end of the triangle, it seems better to me like this.

custom arrow shape 2

And of course, I know this commutative diagram is absurd, it's just to show the new arrow properties.

Related Question