8

The syntax for arrows in tikz-cd is \arrow[options]. Arrows can either be positioned relatively (e.g. \arrow[r, "\phi"]) or absolutely (\arrow[from=1-1, to=1-2, "\phi"]). I want to shift the label of an arrow vertically, without also shifting the arrow itself. There is a yshift syntax in tikz-cd, but this shifts the arrow along with the label.

I can revert to tikz and use a notation like the following \arrow{r}[yshift=1ex]{\phi}, but this is inconvenient, as it doesn't compose with the other tikz-cd syntax. In addition, I'm not sure how to conveniently use absolute positioning with tikz-cd's grid using tikz directly.

Is there a convenient way to achieve this, or is this a shortcoming with tikz-cd?


Minimal working example:

\documentclass{article}

\usepackage{tikz-cd}

\begin{document}

\begin{tikzcd}
A \arrow[from=1-1, to=1-2, "\phi"] & B
\end{tikzcd}

\end{document}

A \xto{\phi} B

I want to shift \phi up without moving the arrow itself.

1
  • 1
    Welcome to TeX.SX!! Please give a full minimal working example. Currently we have to guess what you are using and this makes it really hard to help you. A MWE should start with a \documentclass command, have a minimal preamble and then \begin{document}...\end{document}. The code should compile and be as small as possible to demonstrate your problem. it is much easier to help you if you give us something to start from.
    – user30471
    Commented Apr 29, 2020 at 12:07

2 Answers 2

9

As usual in the quotes syntax, you can just add keys after "\phi", e.g.

\documentclass{article}

\usepackage{tikz-cd}

\begin{document}

\begin{tikzcd}
A \arrow[from=1-1, to=1-2, "\phi" {yshift=1pt}] & B
\end{tikzcd}

\begin{tikzcd}
A \arrow[from=1-1, to=1-2, "\phi" {yshift=5pt}] & B
\end{tikzcd}

\begin{tikzcd}
A \arrow[from=1-1, to=1-2, "\phi" {yshift=3pt,red}] & B
\end{tikzcd}

\end{document}

enter image description here

1
  • Perfect — can't believe I didn't realise this was possible! Thanks!
    – varkor
    Commented Apr 29, 2020 at 15:25
2

Edit:

In the first version of answer i misread of question. Now is (hopefully) correct:

  • global setting (for all arrows in diagram):

enter image description here

\documentclass[margin=3mm]{standalone}
\usepackage{tikz-cd}

\begin{document}
    \begin{tikzcd}[labels={inner sep=1ex}]
A \ar[r, "\phi"] & B
    \end{tikzcd}
\end{document}
  • local setting and use yshift option:
\documentclass[margin=3mm]{standalone}
\usepackage{tikz-cd}

\begin{document}
    \begin{tikzcd}
A \ar[r, "\phi", every label/.style={red,yshift=2ex}] & B
    \end{tikzcd}
\end{document}

enter image description here

  • local setting with defining arrow's label style, for example:
\begin{document}
    \begin{tikzcd}[SL/.style = {every label/.style={red,yshift=#1}}]
A \ar[r, "\phi", SL=2ex] & B
    \end{tikzcd}
\end{document}
1
  • The second solution is sufficient for my use case, thanks! However, I've accepted the other answer simply because it's a little more elegant.
    – varkor
    Commented Apr 29, 2020 at 15:28

You must log in to answer this question.

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