1

I'm trying to use tikz-cd to write category theory maps within text, like Let \begin{tikzcd}[column sep=small] A \arrow[r] & B \end{tikzcd} be a map., but whenever I do so, there is some unnecessary spacing between the map and the text around it, like this:

Map within text

It wasn't much of a problem until I had to write images of maps like Im(\begin{tikzcd}[column sep=small] A \arrow[r] & B \end{tikzcd}) and the space between the map and the parenthesis became way too noticeable, looking like this:

Image of the map

Is there any way to make the tikz-cd maps blend better with the text around it, rather than having this weird space whenever it appears in the middle of it?

1 Answers1

1

Here's a cramped* style that sets the right sep settings so that the resulting CD resembles A \to B as close as possible.

This means:

  • No seps for the internal TikZ \matrix.
  • No seps for the cells' nodes (labels along an arrow are a different thing).
  • The outer sep of the cells' nodes should be the width of \thickmuskip (≈ \;, the pading around \to) but something goes wrong there hence the correction factor of 1.25.
  • A column sep that's the width of \to including the padding.
  • Round line cap (as with the \to symbol).
  • Arrows that do not contribute to the bounding box.

The last one is probably unnecessary for most cases and might be a bad idea for CDs but then again, more complex arrows won't look good inside math-mode anyway, I guess.

Code

\documentclass[varwidth,convert]{standalone}
\usepackage{tikz-cd}
\tikzcdset{
  cramped*/.style={
    arrows=overlay, line cap=round,
    every matrix/.append style={
      every outer matrix/.append style={inner sep=+0pt}},
    every cell/.append style={inner sep=+0pt, outer sep=1.25*width("$\;$")},
    column sep/.evaluated=width("${}\to{}$")}}
\begin{document}
Let $A \to B$ be a map. (\texttt{\textbackslash to})\par
Let \begin{tikzcd}[column sep=small] A \arrow[r] & B \end{tikzcd}
  be a map. (\texttt{column sep=small})\par
Let \begin{tikzcd}[column sep=small, cramped] A \arrow[r] & B \end{tikzcd}
  be a map. (\texttt{column sep=small, cramped})\par
Let $A \to B$ be a map. (\texttt{\textbackslash to})\par
Let \begin{tikzcd}[cramped*] A \arrow[r] & B \end{tikzcd}
be a map. (\texttt{cramped*})\par
Let \begin{tikzcd}[cramped*]
  A \ar[r, bend left] \ar[r, bend right, <-] & B
\end{tikzcd} be a map.\par

[\sin( \begin{tikzcd}[cramped*] A \ar[r, bend left] \ar[r, bend right, <-] & B \end{tikzcd})] [\sin( \begin{tikzcd}[cramped*] A \rar & B \end{tikzcd})] [\sin(A \to B)] \end{document}

Output

enter image description here

Qrrbrbirlbel
  • 119,821