1

I need to have an arrow that has a vertical bar in the middle, something like this:

----|---->

in commutative diagrams. Tikzcd does not have such an arrow supported directly, as far as I can tell.

Any ideas on how to do this? Ideally I would like to still be able to have labels.

I found a way to do this in the math environment using \mathclap and + as shown in code for arrow with a short vertical line in the middle of the shaft (not perfect but good enough) but this does not work well within a commutative diagram.

4

tikz-cd supports markings.

\documentclass{article}
\usepackage{tikz-cd}
\begin{document}
\begin{tikzcd}[]
    a \arrow[r,"|" marking] & b
\end{tikzcd}
\end{document}

enter image description here

If you want to have full control over all aspects of the bar, you can use a TikZy decoration.

\documentclass{article}
\usepackage{tikz-cd}
\usetikzlibrary{decorations.markings}
\tikzset{mid vert/.style={/utils/exec=\tikzset{every node/.append style={outer sep=0.8ex}},
postaction=decorate,decoration={markings,
mark=at position 0.5 with {\draw[-] (0,#1) -- (0,-#1);}}},
mid vert/.default=0.75ex}
\begin{document}
\begin{tikzcd}[]
    a \arrow[r,mid vert,"pft"] & b \arrow[r,"pht"] & c
\end{tikzcd}
\end{document}

enter image description here

In this version, the parameter is the length of the arrow, with the default being 2*0.75ex, but you can adjust the other parameters as well.

  • Great this works! Is it possible to add to the definition of mid vert the fact that all the labels should have outer sep of, say, 0.8ex? I am not familiar with decorations – geguze May 29 at 4:29
  • @geguze Yes, it is. (I actually like the idea!) I modified the code accordingly. (And this change is only local, as shown in the example, i.e. the other arrows will have business as usual.) – user121799 May 29 at 4:40
  • Wonderful! One last question. The definition of the arrow with a bar in running math, suggested at the link included in my question, does not look very good, especially when compared to a tikz-cd diagram. Any suggestion on how to make that better? One could put a tikz-cd inline based on the mid vert definition you provided, not sure that's the best way though. – geguze May 29 at 4:51
  • 1
    @geguze How about $a\mathrel{\tikz[baseline=-0.5ex]{\draw[->,mid vert](0,0) --(1.2em,0);}}b\longrightarrow c$ with the above preamble? Or \newcommand{\tobar}{\mathrel{\tikz[baseline=-0.5ex]{\draw[->,mid vert](0,0) --(1.2em,0);}}} $a\tobar b\longrightarrow c$? There is a long discussion how to make this symbol adjust to the font size, see this thread. (For a simple vertical bar you could also use \rule ...) – user121799 May 29 at 4:57

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.