I am trying to type the following simple commutative diagram in LaTeX. I have the basics, but I need for the V to be centered, and for the arrow under the g to be in the opposite direction.

\begin{tikzpicture}[every node/.style={midway}]
\matrix[column sep={4em,between origins},
    row sep={2em}] at (0,0)
{ \node(X)   {$X$}  ; & \node(Y) {$Y$}; \\
\node(V) {$V$};                   \\};
\draw[<-] (V) -- (X) node[anchor=east]  {$h$};
\draw[->] (V) -- (Y) node[anchor=north]  {$g$};
\draw[->] (X)   -- (Y) node[anchor=south] {$f$};
  • To switch the direction of the arrow, just reverse the order: \draw[->] (Y) -- (V) instead of \draw[->] (V) -- (Y). Also, the V node is centered, so perhaps just increasing the length of the line a bit by adding shorten option as in \draw[->, shorten >=-0.5ex] (Y) -- (V) makes it look more centered. – Peter Grill Jan 1 '13 at 19:56
  • have you seen Commutative Diagrams and TikZ and a search for commutative diagrams – cmhughes Jan 1 '13 at 20:00
  • @PeterGrill When I compile, I still see the V directly beneath the X,rather than centered and diagonally beneath and to the right of the X, as I would like for it to be. Thanks again. – Michael Dykes Jan 1 '13 at 20:05
  • @MichaelDykes: Duhh!!! Sorry about that. Not sure what part of "center" was confusing to me. :-) – Peter Grill Jan 1 '13 at 20:49

Does this solution with tikz-cd help?



\begin{tikzcd}[column sep=small]
X \arrow{rr}{f} \arrow[swap]{dr}{h}& &Y \arrow{dl}{g}\\
& V & 


enter image description here

  • Actually, it does as this is exactly what I was looking for. In general, what are the differences between tikz and tikz-cd? I mean when is it better to use the latter rather than the former? Thanks again. – Michael Dykes Jan 1 '13 at 20:18
  • I am unexpert, but as I see it, tikz-cd is a tikz-based package to easily type commutative diagrams. As you can see, the syntaxis is as easy as xymatrix. – c.p. Jan 1 '13 at 20:24
  • You're welcome. Here is the manual for more information: ctan.unixbrain.com/graphics/pgf/contrib/tikz-cd/tikz-cd-doc.pdf – c.p. Jan 1 '13 at 20:33

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.