1

Consider the following example. The numbers in the subscript within another subscript which is overall put in \scriptsize (default as the labels over the arrows in the diagrams) appear to be too large. I tried this with different fonts yet they all show the same result, so this is not a font issue but an incorrect input of mine.

How should I correctly input this kind of subsubscript so that the numbers could appear in the right size? (The goal is to make the symbols like f_{c_1} in the arrow labels looks similar to the normal version as shown in the displayed math. As you can see, for now the number 1 is even bigger than the letter c in the arrow label.)

\documentclass{article}
\usepackage{tikz-cd}
% \usepackage{kpfonts-otf}
% \usepackage{newpxmath}
% \usepackage{ebgaramond-maths}
\begin{document}
\[
    \begin{tikzcd}
        \bullet & \bullet \\
        \bullet & \bullet
        \arrow[from=1-1, to=2-1]
        \arrow[from=1-2, to=2-2]
        \arrow["{f_{c_1}}", from=1-1, to=1-2]
        \arrow["{f_{c_2}}"', from=2-1, to=2-2]
    \end{tikzcd}
\]
\[
    f_{c_1}, f_{c_2}
\]
\end{document}

enter image description here

2

2 Answers 2

0

As mentioned in the comments, TikZ-CD sets \scriptstyle for the so called labels (i.e. nodes along arrows). The first subscript gets \scriptscriptstyle … and that's it.

If you want your labels set in the same size as normal math you could just tell TikZ-CD that by setting the font of those label to \textstyle – or \displaystyle but that doesn't do anything in this example.

I've also added an option to scale these labels down again using scale which keeps the math styles and just scales down the whole node, similar on how \scalebox would do.

By default, every label gets the style default label scaling with scale = 0.7. You'd need to use scale = 1/.7 to revert that which to me is uncomfortable because TeX/TikZ might not revert is properly due to imprecisions. You could also use shift only in front of scale={#1} to reset any rotating, slanting and scaling but that might mess with labels that are sloped.
Instead, the scale labels key simply overwrites default label scaling with a no-op ands adds the desired scaling.

However, this can only be done once as the second example shows, here they stack again.

Though, I don't think this should be a problem because diagrams with differently scaled labels are going to be ugly anyway.

Code

\documentclass{article}
\usepackage{tikz-cd}
\tikzcdset{
  default label scaling/.style={scale=.7},
  labels={default label scaling},
  labels in textstyle/.style={
    labels={font=\everymath\expandafter{\the\everymath\textstyle},
    inner sep=+0.7ex}},
  scale labels/.style={
    default label scaling/.code=, % disable default scaling
    labels={scale={#1}}}}
% \usepackage{kpfonts-otf}
% \usepackage{newpxmath}
% \usepackage{ebgaramond-maths}
\begin{document}
\[
\begin{tikzcd}[labels in textstyle]
    \bullet & \bullet \\
    \bullet & \bullet
    \arrow[from=1-1, to=2-1]
    \arrow[from=1-2, to=2-2]
    \arrow["{f_{c_1}}", from=1-1, to=1-2]
    \arrow["{f_{c_2}}"', scale labels=1, from=2-1, to=2-2] % removes scale=.7
\end{tikzcd}
\]
\[
    f_{c_1}, f_{c_2} \quad \scriptstyle f_{c_1}, f_{c_2}
\]
\[
\begin{tikzcd}[labels in textstyle, scale labels=.5] % .5, not .7 * .5
    \bullet & \bullet \\
    \bullet & \bullet
    \arrow[from=1-1, to=2-1]
    \arrow[from=1-2, to=2-2]
    % the following keep scale = .5 from the environment's setting
    \arrow["{f_{c_1}}" , scale labels= .5, from=1-1, to=1-2] % .5 *  .5
    \arrow["{f_{c_2}}"', scale labels=2,   from=2-1, to=2-2] % .5 * 2
\end{tikzcd}
\]
\end{document}

Output

enter image description here

4
  • Thank you for this. Is it possible to set the scale=0.7 as default, only using other scale factor when explicitly given otherwise?
    – Jinwen
    Dec 1, 2022 at 21:07
  • @Jinwen Depens, do you want all labels of one or all diagrams to use scale=0.7 unless stated otherwise or do you want scale labels act as if you have writen scale labels=0.7? Dec 1, 2022 at 21:26
  • I meant the first one: to use scale=0.7 unless stated otherwise. To achieve such a key-value interface with the expl3 mechanism is known to me, but I'm not familiar with the PGF key handling system.
    – Jinwen
    Dec 1, 2022 at 21:48
  • @Jinwen It's not really a problem with PGFKeys either. I'm just wondering how to deal with the stacking of the scaleing. For most simple labels, shift only is probably good enough. For most simply diagrams, scale labels as defined in my updated answer should be good to go, too, because I would use it only on the environment and not individually. Dec 1, 2022 at 22:47
0

As @Werner mentioned in a comment to the question, the right thing to do in this case seems to be (in one way or another) scaling the normal version.

An example would be:

\documentclass{article}
\usepackage{tikz-cd}
\begin{document}
\[
    \begin{tikzcd}
        \bullet & \bullet \\
        \bullet & \bullet
        \arrow[from=1-1, to=2-1]
        \arrow[from=1-2, to=2-2]
        \arrow["{\displaystyle\widehat{f}_{c_1}}"{scale=.75}, from=1-1, to=1-2]
        \arrow["{\displaystyle\widehat{f}_{c_2}}"'{scale=.75}, from=2-1, to=2-2]
    \end{tikzcd}
\]
\[
    f_{c_1}, f_{c_2}
\]
\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 .