1

I’m writing a paper with a lot of commutative diagrams, using tikz-cd, and am using different styles to distinguish various classes of maps in the diagrams. For instance, injective maps have a hooked tail, defined and used by

\tikzset{inj/.code={\pgfsetarrowsstart{right hook}}}
\begin{tikzcd} A \ar[r,inj] & B \end{tikzcd}

There’s one I’m having trouble defining. It should produce, roughly, a subscripted “lw” beside the arrowhead, i.e.\ something like

\begin{tikzcd} A \ar[r,"lw"' very near end] & B \end{tikzcd}.

How can I define a style lw so that I can write \begin{tikzcd} A \ar[r,lw] & B \end{tikzcd} to get the subscripted “lw” beside the arrowhead as described above?

An attribute that simply adds a label "lw"' very near end as on the example above would be fine. However, if it’s possible to do something like placing a node relative to the arrowhead, so that one has the versatile syntax of node positioning to fine-tune the placement of the “lw”, that would be even better.

MWE:

\documentclass{standalone}
\usepackage{tikz-cd} \usetikzlibrary{arrows}
\begin{document}

% example of defining/using arrow styles:
\tikzset{inj/.code={\pgfsetarrowsstart{right hook}}}
\begin{tikzcd} A \ar[r,inj] & B \end{tikzcd}

% what I want to define a style for:
\begin{tikzcd} A \ar[r,"lw"' very near end] & B \end{tikzcd}

\end{document}
2

Pretty straight forward:

\tikzset{lw/.style={"lw"' very near end}}

If you want the possibility to add more settings to the label, you can do this:

\tikzset{
  lw/.style={"lw"'{very near end,#1}},
  lw/.default={}
}

You can then use the style without arguments (\ar[r,lw]), or with an argument (\ar[r,lw={blue}]).

output of code

\documentclass[border=5mm]{standalone}
\usepackage{amsmath}

\usepackage{tikz-cd}
\usetikzlibrary{arrows}
\tikzset{
  lw/.style={"lw"'{very near end,#1}},
  lw/.default={}
}
\begin{document}
\begin{tikzcd}
  A \ar[r,lw] & B  \ar[r,lw={pos=1,yshift=-2pt,blue,draw}] & C
\end{tikzcd}
\end{document}
  • I feel like an idiot now; I was sure I’d tried lw/.style={…} before and it didn’t work, but it works fine, so I must have had a typo or something! Thankyou especially for the extra positioning suggestions. – Peter LeFanu Lumsdaine Nov 6 '17 at 11:25

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.