7

Here is my problem.

Problem

I am trying to get a bent arrow "go" under the CxExF node by breaking the long arrow into two parts. However, I would like the two parts to follow the same "path" as the long arrow. This means that I would need to move/shift the entry (and exit) point of the two parts so that it looks as the broken arrow is really passing under the node. To give a sense of what I mean, I include below what would be desirable, (generated using an image editor). Any suggestion? Any better way?

Desired solution

Below the code generating the issue.

\documentclass{article}
\usepackage{tikz-cd}
\begin{document}
\[
\begin{tikzcd}
        X \ar[r] & A &\\
        & C\times D\times F  &\\ 
        &   &\\
        &   &\\
        &   &\\
        &   & B \ar[luuuuu, bend left, in=190, out=10]
\end{tikzcd}
\]  

\[
\begin{tikzcd}
    X \ar[r] & A &\\
    & C\times D\times F \ar[u, bend left, in=240, out=0] &\\ 
    &   &\\
    &   &\\
    &   &\\
    &   & B \ar[-,luuuu, bend left, in=190, out=10]
\end{tikzcd}
\]  
\end{document}

3 Answers 3

10

How about you set a customized dashing pattern that skips the part where the text occurs, like so:

Output

\documentclass{article}
\usepackage{tikz-cd}
\begin{document}
\[
\begin{tikzcd}
        X \ar[r] & A &\\
        & C\times D\times F &\\ 
        &   &\\
        &   &\\
        &   &\\
        &   & B \ar[luuuuu, bend left, in=190, out=10, dash pattern=on 80pt off 15pt]
\end{tikzcd}
\]  
\end{document}
3
  • This seems to be a good way to solve the problem. I still wonder if one can get control on the position of the end/start points of arrows (I could only find a way to shift an entire arrow but not just one end). Thx!
    – geguze
    Jun 15, 2019 at 21:03
  • To be honest, that is the only easy and simple way I can think of. If you want, you can change the column separation \begin{tikzcd}[column sep = 10em] to avoid your problem but then everything will get far apart... Another solution is to used TikZ instead of tikzcd and build everything from scratch. Breaking a line into two halves is not an easy approach. Jun 15, 2019 at 21:30
  • 1
    Good suggestion! I concur that probably one needs to go deeper into TikZ to solve the problem. Thx again!
    – geguze
    Jun 15, 2019 at 21:42
8

Just for fun: something very much along the lines of the reverseclip trick. That way you do not have to adjust things by hand.

\documentclass{article}
\usepackage{tikz-cd}
\begin{document}
\[
\begin{tikzcd}[execute at end picture={
\clip (C.north east) rectangle (C.south west)
(current bounding box.south west) -| (current bounding box.north east)
-| cycle;
\draw[->] (B) to[out=110,in=-90] (A);
}]
        X \ar[r] & |[alias=A]|A &\\
        & |[alias=C]| C\times D\times F  &\\ 
        &   &\\
        &   &\\
        &   &\\
        &   & |[alias=B]|B 
\end{tikzcd}
\]  
\end{document}

enter image description here

4

Whereas I think marmot's solution is neater, here is another trick that might be useful:

\documentclass{article}
\usepackage{tikz-cd}

\begin{document}
\[
\begin{tikzcd}
        X \ar[r] & A &\\
        &   \tikz[remember picture]{\node (P0) at (0,0) {$C\times D\times F$}} &\\ 
        &   &\\
        &   &\\
        &   &\\
        &   & B \ar[luuuuu, bend left, in=190, out=10]
\end{tikzcd}
\]   
\tikz[overlay,remember picture]{\node[fill=white] at (P0) {$C\times D\times F$}};

\end{document}

hybrid solution

The above code defines a tikz node (P0) at the matrix cell, and remembers it. Subsequently, the node is filled the equation and a white background, which is drawn on top of the arrow. Essentially, it is a hybrid solution between tikz-cd and tikz.

At this point, one might also consider going for a full tikz solution, using a matrix of nodes and layers, which is useful if many arrows passing under many nodes will have to be defined:

\documentclass{article}
\usepackage{tikz-cd}
\usetikzlibrary{matrix}

\begin{document}

\pgfdeclarelayer{background}
\pgfsetlayers{background,main}

\begin{tikzpicture}
\matrix (X) [matrix of nodes,column sep=0.8cm,row sep=0.8cm,every node/.style={fill=white}]
{
    $X$ & $A$ \\
    & $C\times D \times F$ \\
    &   &\\
    &   &\\
    &   &\\
    &   & $B$ \\
};

\begin{pgfonlayer}{background}
   \draw[->] (X-1-1) -- (X-1-2) ;
   \draw[->] (X-6-3) to[in=-55, out=125] (X-1-2);
\end{pgfonlayer}
\end{tikzpicture}

\end{document}

fulltikz

An example with multiple arrows and nodes:

\begin{tikzpicture}
\matrix (X) [matrix of nodes,column sep=0.8cm,row sep=0.8cm,every node/.style={fill=white}]
{
    $X$ & $A$ \\
    & $C\times D \times F$ \\
    &  $K\times L \times M \times N$ &\\
    &  $G\times H \times I \times J$ &\\
    &   & \\
    &   & $B$ \\
};
\begin{pgfonlayer}{background}
\draw[->] (X-1-1) -- (X-1-2) ;
\draw[->] (X-6-3) to[in=-55, out=125] (X-1-2);
\draw[->] (X-6-3) to[in=-60, out=150] (X-2-2);
\draw[->] (X-2-2) to[in=120, out=-120] (X-4-2);
\end{pgfonlayer}
\end{tikzpicture}

multiple full tikz

You must log in to answer this question.

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