TikZ CD – Adjusting White Space Around Description Style Arrow Label

tikz-cd

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}

Best Answer

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 $$ ... $$?

Related Question