2

In the diagram

\documentclass{scrartcl}
\usepackage{tikz-cd}
\begin{document}
    \[
        \begin{tikzcd}
            A \ar[rr, ""' name=x] &&[2cm] B\\
            &C   \ar[ur, "" name=y, out=0, in=-135]
                    \ar[from=x, to=y, Rightarrow]
        \end{tikzcd}
    \]
\end{document}

enter image description here

it would certainly be nicer if the double struck arrow was perfectly vertical, either by starting at (x -| y) or ending at (x |- y). But tikz-cd seems not to like the -|-syntax. How do I achieve this?

0

2 Answers 2

4

First of all, TikZ-cd uses the to path operator in its implementation of \ar (which is why out = 0, in = -135 works as it does). You can always just use to path to manually draw an arrow:

\begin{tikzcd}[labels={draw,help lines}]
  A \ar[rr, ""' name=x]                & &[2cm] B\\
& C \ar[ur, "" name=y, out=0, in=-135]
    \ar[to path=(x) -- (x|-y), Rightarrow, red]
    \ar[to path=(x-|y) -- (y), Rightarrow, blue]
\end{tikzcd}

enter image description here

In the above example, I've chosen to show the labels, i.e. the nodes you place along an arrow, because they have a size even if you specify empty text "". This has an effect on the -| and |- coordinate specifications since they only use the center of the nodes to find the intersecting coordinate.
This is the reason the red arrow ends not at the same height as the blue and the blue one doesn't start at the same place as the red one.

I would use coordinates in place of the nodes and just shorten the arrow a bit:

\begin{tikzcd}[/tikz/name*/.style={name={#1},shape=coordinate}]
  A \ar[rr, "" name*=x]                & &[2cm] B\\
& C \ar[ur, "" name*=y, out=0, in=-135]
    \ar[shorten=2pt, to path=(x) -- (x|-y), Rightarrow, red]
    \ar[shorten=2pt, to path=(x-|y) -- (y), Rightarrow, blue]
\end{tikzcd}

enter image description here


Now, I don't think it would be wise to explicitly write down each to path. We should use styles for that. I did this before in my answer to Tikz: purely vertical arrow from nodeA.south to nodeB.north and a bit more complicated version are part of the ext.paths.ortho library of my tikz-ext package.

In its most simple form they are

\tikzset{
  |*/.style={to path={--(\tikztostart|-\tikztotarget)\tikztonodes}},
  *|/.style={to path={(\tikztostart-|\tikztotarget)--(\tikztotarget)\tikztonodes}},
  -*/.style={to path={--(\tikztostart-|\tikztotarget)\tikztonodes}},
  *-/.style={to path={(\tikztostart|-\tikztotarget)--(\tikztotarget)\tikztonodes}}}
\begin{tikzcd}[/tikz/name*/.style={name={#1},shape=coordinate}]
  A \ar[rr, "" name*=x]                & &[2cm] B\\
& C \ar[ur, "" name*=y, out=0, in=-135]
    \ar[shorten=2pt, from=x, to=y, |*, Rightarrow, red]
    \ar[shorten=2pt, from=x, to=y, *|, Rightarrow, blue]
\end{tikzcd}

With the mentioned ext.paths.ortho library, the available to paths try to take the border of the start and end points in consideration.

\begin{tikzcd}[labels={draw,help lines}, /tikz/ortho/install shortcuts]
  A \ar[rr, ""' name=x]                & &[2cm] B\\
& C \ar[ur, "" name=y, out=0, in=-135]
    \ar[from=x, to=y, |*, Rightarrow, red]
    \ar[from=x, to=y, *|, Rightarrow, blue]
\end{tikzcd}

enter image description here

Here /tikz/ortho/install shortcuts actually defines |* et al to be shortcuts to only vertical first etc. which are always available with the library.


If you need the vertical line to be a specific distance away from the curved arrow you will need to use the intersections library.

Code

\documentclass[tikz]{standalone}
\usepackage{tikz-cd}
\usetikzlibrary{ext.paths.ortho}
\begin{document}
\begin{tikzcd}[labels={draw,help lines}]
  A \ar[rr, ""' name=x]                & &[2cm] B\\
& C \ar[ur, "" name=y, out=0, in=-135]
    \ar[to path=(x) -- (x|-y), Rightarrow, red]
    \ar[to path=(x-|y) -- (y), Rightarrow, blue]
\end{tikzcd}
\begin{tikzcd}[/tikz/name*/.style={name={#1},shape=coordinate}]
  A \ar[rr, "" name*=x]                & &[2cm] B\\
& C \ar[ur, "" name*=y, out=0, in=-135]
    \ar[shorten=2pt, to path=(x) -- (x|-y), Rightarrow, red]
    \ar[shorten=2pt, to path=(x-|y) -- (y), Rightarrow, blue]
\end{tikzcd}

\tikzset{
  |*/.style={to path={--(\tikztostart|-\tikztotarget)\tikztonodes}},
  *|/.style={to path={(\tikztostart-|\tikztotarget)--(\tikztotarget)\tikztonodes}},
  -*/.style={to path={--(\tikztostart-|\tikztotarget)\tikztonodes}},
  *-/.style={to path={(\tikztostart|-\tikztotarget)--(\tikztotarget)\tikztonodes}}}
\begin{tikzcd}[/tikz/name*/.style={name={#1},shape=coordinate}]
  A \ar[rr, "" name*=x]                & &[2cm] B\\
& C \ar[ur, "" name*=y, out=0, in=-135]
    \ar[shorten=2pt, from=x, to=y, |*, Rightarrow, red]
    \ar[shorten=2pt, from=x, to=y, *|, Rightarrow, blue]
\end{tikzcd}

\begin{tikzcd}[labels={draw,help lines}, /tikz/ortho/install shortcuts]
% /tikz/ortho/install shortcuts overwrites previously defined |*, *|, -*, *-
  A \ar[rr, ""' name=x]                & &[2cm] B\\
& C \ar[ur, "" name=y, out=0, in=-135]
    \ar[from=x, to=y, |*, Rightarrow, red]
    \ar[from=x, to=y, *|, Rightarrow, blue]
\end{tikzcd}
\end{document}
1
  • Wow. Ask one question and get answers to 10 more questions that I hadn't even thought about!
    – Bubaya
    Feb 9 at 22:29
1

The comment by @Qrrbrbirlbel outlines a general solution for using -| notation in tikz-cd. A somewhat simpler solution is just to add an additional column and draw a shortened down arrow.

enter image description here

\documentclass{scrartcl}
\usepackage{tikz-cd}
\begin{document}
    \[
        \begin{tikzcd}
            A \ar[rrr] && \ar[d, Rightarrow, shorten >=3.5mm] & B\\
            & C \ar[urr, out=0, in=-135] & {}
        \end{tikzcd}
    \]
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .