3

I'd like to scale a custom symbol drawn in tikz, such that it's the same size as surrounding text in a tikz-cd diagram.

For example, in the following code I'd like the box to the left of A_2 to be proportionally the same as the box to the left of A_1: currently it's the boxes are the same size, even though A_2 is smaller than A_1.

\documentclass{standalone}
\usepackage{tikz-cd}

\newcommand{\boxL}{%
  \tikz[baseline=0em,xscale=0.02em,yscale=0.02em]
  \fill (1,0) -- (0,0) -- (0,1) -- (1,1) -- cycle;\mspace{1mu}}

\begin{document}
\begin{tikzcd}
{\boxL A_1} \rar{\boxL A_2} & A_3
\end{tikzcd}
\end{document}

enter image description here

Here, tikz-cd uses \scriptstyle for labels, which is good, but the box in the label isn't getting scaled properly.

For the record, this can be fixed if the equation is replaced with:

{\boxL A_1} \rar{\scriptsize\boxL A_2} & A_3

This results in the following picture:

enter image description here

However, I don't want to have to add \scriptsize explicitly everywhere.

  • @Papiro no. I think it might be useful for newcomers. – Gonzalo Medina May 6 '13 at 23:33
  • I get errors that \box is already defined and \BoxL is not … — Anyway, as the arrow label is per default in math-mode you can use amsmath’s/amstext’s \text macro so that TikZ picks up the correct em size. – Qrrbrbirlbel May 7 '13 at 1:51
3

Code

\documentclass[convert=false]{standalone}
\usepackage{amstext,tikz-cd}

\newcommand{\BOX}{%
  \text{%
    \tikz[baseline=0em,xscale=0.02em,yscale=0.02em]
    \fill (1,0) -- (0,0) -- (0,1) -- (1,1) -- cycle;}\mkern1mu\relax}

\begin{document}
\begin{tikzcd}
{\BOX A_1} \rar{\BOX A_2} & A_3
\end{tikzcd}
\end{document}

Output

enter image description here

2

You can use \mathchoice to scale the symbol appropriately depending on the style:

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

\newcommand\Mybox{%
  \tikz[baseline=0em,xscale=0.02em,yscale=0.02em]
  \fill (\unit,0) -- (0,0) -- (0,\unit) -- (\unit,\unit) -- cycle;\mspace{1mu}}
\newcommand\Mbox{%
  \mathchoice{\def\unit{1}\Mybox}{\def\unit{1}\Mybox}{\def\unit{0.67}\Mybox}{\def\unit{0.5}\Mybox}
}

\begin{document}

\[ \Mbox_{\Mbox_{\Mbox}} \]

\begin{tikzcd}
{\Mbox A_1} \rar{\Mbox A_2} & A_3
\end{tikzcd}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.