3

I am using the description style arrow label in Tikz-cd so that the label appears on top of the arrow with some white space around the label. The issue is, with small arrows and large labels, the white space eats up the entire arrow.

Thus I would like to shrink the white space around the label. In the Tikz-cd documentation it says this can be accomplished with "inner sep," though I am not sure exactly how this is done.

Here is a minimal working example where I try to (unsuccessfully) modify the white space around the arrow label using inner sep.

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

\begin{document}
    $$
    \begin{tikzcd}
        A \ar[r, "f" description] & B
    \end{tikzcd}
    $$
    $$
    \begin{tikzcd}
        A \ar[r, "f" description, inner sep = -2em] & B
    \end{tikzcd}
    $$
\end{document}

2 Answers 2

6

Put inner sep in the option labels of TikZ-CD.
You can also set it locally, for one or some labels only, with:

"<labeltext>" {description, inner sep = <dimension>}

See the example:

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

\begin{document}
    \[
    \begin{tikzcd}
        A \ar[r, "f" description] & B
    \end{tikzcd}
    \]
    \[
    \begin{tikzcd}[labels={inner sep = .5pt}]
        A \ar[r, "f" description] & B
    \end{tikzcd}
    \]
    In the following CD, the first label has a  standard inner sep, the second has an inner sep of .5pt: 
    \[
    \begin{tikzcd}
        A \ar[r, "f" description] & B\\
        A \ar[r, "f" {description, inner sep = .5pt}] & B\\
    \end{tikzcd}
    \]
\end{document}

enter image description here

Off-topic: don't use $$...$$ in LaTeX, use \[...\], see here: Why is \[ ... \] preferable to $$ ... $$?

3
  • Thank you so much! Just what I need. I also like how I can add your solution: "labels={inner sep = .5pt}" locally to the optional arguments of a single bad arrow. Thanks also for the tip on avoiding $$ ... $$, I have been using LaTeX for a while now and I still have so much to learn! :)
    – user38770
    Apr 24, 2023 at 23:44
  • @user38770 Of course, you can, also without explicitly set labels. See my renewed answer.
    – CarLaTeX
    Apr 25, 2023 at 6:30
  • @user38770 It might be better to use the description key (description/.append style={inner sep = .5pt}) instead of changing the inner sep for all labels. However, if all your labels should lie on top of the line, you can also do labels = description and don't have do specify description each time. Apr 25, 2023 at 14:05
3

Same result with xy package:

\documentclass[12pt]{article}
\usepackage{amsmath,amssymb}
\usepackage[cmtip,all]{xy}

\begin{document}
    \[\xymatrix{
    A \ar[r]|f & B
    } \]
\end{document}

enter image description here

You must log in to answer this question.

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