2

I am making a commutative diagram using tikz-cd. However, I am having trouble with the vertical placement of the arrow labels. As you can see in the picture, the fraction \tfrac{a}{b_0} shrinks the left and right arrows. Therefore the labels \phi are not on the same height as the label of the middle arrow. Is there a possibility to vertically align all arrow labels so that they are on the same height?

Vertical label misplacement in tikz-cd

Here is a minimal working example producing the diagram.

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

\begin{document}
\begin{tikzcd}[row sep=large]
  0\arrow[r]&\tfrac{a}{b_0}X\arrow[d,"\phi"]\arrow[r]&X\arrow[d,"\phi"'] \arrow[r] & X/\tfrac{a}{b_0}X\arrow[d,"\phi"']\arrow[r]&0\\
  0\arrow[r]&\tfrac{a}{b_0}Y\arrow[r] &Y \arrow[r]& Y/\tfrac{a}{b}Y\arrow[r]&0
\end{tikzcd}
\end{document}

2 Answers 2

1

In addition to Salim's answer, you could use a \vphantom with any content you like:

% arara: pdflatex
% arara: pdflatex

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

\begin{document}
\begin{tikzcd}[row sep=large,remember picture]
    0\arrow[r]&\tfrac{a}{b_0}X\arrow[d,"\phi"]\arrow[r]&\vphantom{\tfrac{a}{b_0}}X\arrow[d,"\phi"'] \arrow[r] & X/\tfrac{a}{b_0}X\arrow[d,"\phi"']\arrow[r]&0\\
    0\arrow[r]&\tfrac{a}{b_0}Y\arrow[r] &Y \arrow[r]& Y/\tfrac{a}{b}Y\arrow[r]&0
\end{tikzcd}
\begin{tikzpicture}[remember picture,overlay]
\draw[thick,red] ([xshift=-1cm,yshift=-.99cm]\tikzcdmatrixname-1-1.west) -- ([xshift=1cm,yshift=-.99cm]\tikzcdmatrixname-1-5.east);
\end{tikzpicture}
\end{document}

enter image description here

1
  • I prefer this answer because it doesn't require "hardcoding" vertical distances and therefore it is more applicable in my situation, but both work very well. Sep 15, 2016 at 14:44
1

Labels are not aligned because depth for first row elements are not equal, you can define a strut to made them equal. For the second row just simple \strut suffice to obtain equal height

\documentclass{article}
\usepackage{amsmath}

\usepackage{tikz-cd}

\def\mystrut{\vrule width0pt height.7\baselineskip depth.4\baselineskip}


\begin{document}
\begin{tikzcd}[row sep=large]
  0\arrow[r]&\mystrut \tfrac{a}{b_0}X\arrow[d,"\phi"]\arrow[r]& \mystrut X\arrow[d,"\phi"'] \arrow[r] & \mystrut X/\tfrac{a}{b_0}X\arrow[d,"\phi"']\arrow[r]&0\\
  0\arrow[r]&\strut \tfrac{a}{b_0}Y\arrow[r] & \strut Y \arrow[r]& \strut Y/\tfrac{a}{b}Y\arrow[r]&0
\end{tikzcd}
\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 .