1

I have part of a diagram with tikzcd which looks like this:

\begin{tikzcd}[column sep=20mm]
A\ar[rd,"a"] & \\
B\ar[rd,"b"]\ar[u,"b"] & C \\
& D\ar[u,"d"]
\end{tikzcd}

and produces the following

enter image description here

Now, I want to add a text in the middle of this diagram, and with the same inclination than it. The only way that I got to produce this, was to embed the tikzcd inside a tikzpicture:

\begin{tikzpicture}
  \node {\begin{tikzcd}[column sep=20mm]
      A\ar[rd,"a"] & \\
      B\ar[rd,"b"]\ar[u,"b"] & C \\
      & D\ar[u,"d"]
  \end{tikzcd}};
  \node[rotate=-25] {Text};
\end{tikzpicture}

enter image description here

Is there any way to produce the same within the tikzcd environment?

1
  • 2
    OK, I see, and added a proposal.
    – user121799
    Apr 2, 2019 at 18:22

2 Answers 2

4

Using this answer there is no need to nest tikzpictures, which you are effectively doing when putting a tikzcd environment into a node of a tikzpicture.

\documentclass{article}
\usepackage{tikz-cd}
\begin{document}  
\[  \begin{tikzcd}[column sep=20mm,
  execute at end picture={
    \path (\tikzcdmatrixname-1-1) -- (\tikzcdmatrixname-2-1)
    coordinate[pos=0.5] (aux1)
    (\tikzcdmatrixname-2-2) -- (\tikzcdmatrixname-3-2)
    coordinate[pos=0.5] (aux2)
    (aux1) -- (aux2) node[midway,sloped]{Text};
  }]
      A\ar[rd,"a"] & \\
      B\ar[rd,"b"]\ar[u,"b"] & C \\
      & D\ar[u,"d"]
  \end{tikzcd}\]
\end{document}

enter image description here

2
  • Great! Thank you very much. Apr 2, 2019 at 19:14
  • 2
    @AlejandroDC You're welcome!
    – user121799
    Apr 2, 2019 at 19:22
2

Another solution from within tikz-cd:

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

\begin{document}

\begin{tikzcd}[column sep=20mm]
A\ar[rd,"a"] \ar[rd, phantom, shift right=3.4ex, "\quad\text{Text}" marking]& \\
B\ar[rd,"b"]\ar[u,"b"] & C \\
& D\ar[u,"d"]
\end{tikzcd}

\end{document} 

enter image description here

4
  • (a) my answer is "from within tikz-cd" as well and (b) is there a way to avoid the hard-coded distance in shift right=3.4ex?
    – user121799
    Apr 2, 2019 at 20:26
  • 1
    @marmot: I wrote another solution from within tikz-cd, not another solution, from within tikz-cd. (b) I don't know enough of tikz to say whether it's possible. It would be possible if there is a way to determine the mid-points between A and B, and between C and D.
    – Bernard
    Apr 2, 2019 at 20:28
  • Yes, there are ways, but the most straightforward one may be either loading calc or doing something of the sort I did. BTW, you do not need two separate arrows, if you are fine with adding explicit dimensions you could just do A\ar[rd,"a","\text{Text}" {sloped,below=1.5ex,xshift=0.75em}].
    – user121799
    Apr 2, 2019 at 20:36
  • Thanks for the information! I added a phantom arrow, as you can guess, to have full control on the distance.
    – Bernard
    Apr 2, 2019 at 21:08

You must log in to answer this question.

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