2

Suppose I want to make a diagram using tikz, where an arrow is diagonal:

\begin{tikzcd}
A\ar[rd] & B \\
& C
\end{tikzcd}

and I have a label to put on this arrow. I want this label to have the same "inclination" as the arrow itself: how can one achieve this? I know of the option using rotate, but one doesn't necessarily know the angle over which the label should then be rotated. Thanks in advance!

Edit.

An example is the following diagram

enter image description here

I would like to align the labels with the arrows.

  • Sure, an example should set up the generalisation, no? – B. Pasternak Mar 3 '18 at 12:07
  • it seems that you looking for sloped option, for example: A\ar["ac",sloped] & B \\ & C. however there arise problems (seems that tikz has bug here) with centering labels of edges, special when the arrow is vertical. see tex.stackexchange.com/questions/415863/… – Zarko Mar 3 '18 at 12:58
  • That's exactly what I'm looking for. It does act a little strange (not placing the label in the middle of the arrow, seemingly, but this can be fixed using near start and near end). – B. Pasternak Mar 3 '18 at 13:35
3

It seems that TikZ is not able to compute correctly the width of the sloped label; with \mathclap we make it zero width. It's your responsibility to look at the diagram and increase row or column separation so they fit, but this is true for every diagram with long labels, so not a real problem.

I also add the version with the unsloped labels, which I prefer as it doesn't force readers to tilt their head in order to look at the labels.

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

\newcommand{\id}{\mathrm{id}}

\begin{document}

\begin{tikzcd}[column sep=huge,row sep=large]
k\otimes A
  \arrow[r,"\eta\otimes\id_A"]
  \arrow[dr,"\mathclap{\mu\circ(\eta\otimes\id_A)}"',sloped]
&
A\otimes A
  \arrow[d,"\mu"]
&
A\otimes k
  \arrow[l,"\id_A\otimes\eta"']
  \arrow[dl,"\mathclap{\mu\circ(\id_A\otimes\eta)}",sloped]
\\
& A
\end{tikzcd}

\begin{tikzcd}[column sep=huge,row sep=large]
k\otimes A
  \arrow[r,"\eta\otimes\id_A"]
  \arrow[dr,"\mu\circ(\eta\otimes\id_A)"']
&
A\otimes A
  \arrow[d,"\mu"]
&
A\otimes k
  \arrow[l,"\id_A\otimes\eta"']
  \arrow[dl,"\mu\circ(\id_A\otimes\eta)"]
\\
& A
\end{tikzcd}

\end{document}

enter image description here

  • I enjoyed your last sentence. I actually want the sloped version only for symbols, so for example $\sim$, since, as you say, forcing readers not to tilt their head is preferable. – B. Pasternak Mar 3 '18 at 14:43
  • @B.Pasternak The \sim symbol for isomorphism is indeed different and tilting it could be good. – egreg Mar 3 '18 at 14:45
  • Btw, do you know whether it's possible to have a sloped and an unsloped label in the same \ar command? Because now I have to draw the same arrow twice, but that thickens that specific arrow. – B. Pasternak Mar 3 '18 at 14:48
  • @B.Pasternak \arrow[dr,"x","y"' sloped], so sloped only applies to the specific label. – egreg Mar 3 '18 at 14:51
  • Thanks. I was putting a comma before sloped which probably applied the command to the whole label. – B. Pasternak Mar 3 '18 at 14:53
2

Just for,, if I've well understood what you want, it is very easy with pstricks, using the nrot= key for node connections labels:

\documentclass[border=5pt, svgnames]{standalone}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath} 
\DeclareMathOperator{\id}{id}

\usepackage{pst-node}
\usepackage{auto-pst-pdf} % To compile with pdflatex --enable-write18 (MiKTeX) or pdflatex-shell-escape (TeX Live, MacTeX)
                                                         % pdflatex
\begin{document}

$ \everypsbox{\scriptstyle}\begin{psmatrix}
%% nodes
k \otimes A & A \otimes A & A \otimesk \\
 & A
% arrows
\psset{arrows=->, arrowinset=0.12, nodesep=3pt, labelsep=1pt}
\ncline{1,1}{1,2}\naput{\eta \otimes\id_A}
\ncline[nodesepB=1pt]{1,1}{2,2}\nbput[nrot=:U]{\mu\circ(\eta \otimes\id_{A}\mkern-1mu)}
\ncline{1,2}{2,2}\naput{\mu}
\ncline{1,3}{1,2}\nbput{\id_A\otimes\eta}
\ncline[nodesepB=1pt]{1,3}{2,2}\naput[nrot=:D]{\mu\circ(\id_{A}\otimes\eta)}
\end{psmatrix} $

\end{document} 

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.