# Translating a node style from tikz to tikz-cd

I'd like to switch from tikz to tikz-cd to draw diagrams of arrows (I just started practicing, so I don't know much), and I can't figure out how to translate the following node style:

\documentclass[a4paper,11pt]{article}

\usepackage{tikz}
\usetikzlibrary{matrix,arrows}

\begin{document}

\begin{tikzpicture}
\matrix (m) [matrix of math nodes,
row sep=2.5em, column sep=3em,
text height=1.5ex, text depth=0.25ex]
{\cdot &       \\
& \cdot \\};
\path[->,font=\scriptsize]
(m-1-1) edge node[auto] {$f$} (m-2-2)
edge node[grade] {$[1]$} (m-2-2);
\end{tikzpicture}

\end{document}


I tried out some basic solution, but it just does't look right:

\documentclass[a4paper,11pt]{article}

\usepackage{tikz-cd}

\begin{document}

\begin{tikzcd}
\cdot \ar[dr,"f", "(1)" description, sloped, font=\tiny] & \\
& \cdot
\end{tikzcd}

\end{document}


The main problems are:

• I can't figure out how to change the font size of the label;

• the labels overlap;

• the options affect both labels.

Plus it's very annoying not being able to type directly square brackets in the label.

Any suggestion?

Two diagrams to compare:

The first diagram is the original one using a matrix of math nodes. The second one uses tikz-cd.

The code:

\documentclass[a4paper,11pt]{article}
\usepackage{tikz-cd}
\usetikzlibrary{matrix,arrows}

\tikzset{
}

\begin{document}

\begin{tikzpicture}
\matrix (m) [matrix of math nodes,
row sep=2.5em, column sep=3em,
text height=1.5ex, text depth=0.25ex]
{\cdot &       \\
& \cdot \\};
\path[->,font=\scriptsize]
(m-1-1) edge node[auto] {$f$} (m-2-2)
edge node[grade] {$[1]$} (m-2-2);
\end{tikzpicture}

\begin{tikzcd}[
row sep=2.5em,
column sep=3em,
]
\cdot\ar[dr,phantom,"f" above right=1pt]\ar[dr,"{[1]}" description] & \\
& \cdot
\end{tikzcd}

\end{document}


To answer the specific questions at the end of the question:

• You can use description/.style or description/.append style to change the style for description. In particular, I used description/.append style={grade} in the second diagram.

• In the case of nested expressions with brackets, you need an extra pair of braces for the inner one, as in

\ar[dr,"{[1]}" description];


otherwise, the first ] is considered the closing bracket for the opning one in \ar[.

• Instead of one arrow with two labels as in

\ar[dr,"f", "(1)" description, sloped, font=\tiny]


you can use two arrows; in this way, you have individual control over the elements:

\ar[dr,phantom,"f" above right=1pt]\ar[dr,"{[1]}" description]


since the first arrow is of style phantom, it isn't effectively drawn.

• You can use left=<length>, or right=<length> (or similar) to move labels. I used

\ar[dr,"{f}" above right=1pt]


I found out that using \tikzcdset the problem can be solved in an even more compact way:

\documentclass[a4paper,11pt]{article}
\usepackage{tikz-cd}
\usetikzlibrary{matrix,arrows}

\tikzcdset{diagrams={row sep=2.5em, column sep=3em},

One has just to be careful and put \gar after the arrow, otherwise the label will be placed underneath the edge.