Graphics, Figures & TablestikZ | Commutative Diagram

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
gheorghebg
Posts: 3
Joined: Sat Apr 21, 2012 5:22 pm

tikZ | Commutative Diagram

Post by gheorghebg »

Dear community,

I am using tikZ to draw mathematical commutative diagrams. I am struggling to draw a diagram as the image attached, but I don't really know how to draw the double diagonal line, the one labeled with H.

My code is

Code: Select all

\begin{tikzpicture}
\matrix (m) [matrix of math nodes, row sep=3em, column sep=3em, text height=1.5ex, text depth=0.25ex]
{ K & X  \\
  L & Y     \\ };
\path[->]
(m-1-1) edge (m-1-2)
(m-1-1) edge node[left] {$ i $} (m-2-1)
(m-1-2) edge node[right] {$ p $} (m-2-2)
(m-2-1) edge (m-2-2);
\path[dotted,->]
(m-2-1) edge (m-1-2);
\end{tikzpicture}
I thought about putting it as a label \Rightarrow for the diagonal dotted line L \to X, but then I get it horizontal on the right, instead of diagonal pointing down right. I feel like looking for a double diagonal line as a latex symbol is not the right way to solve the problem. Is there another way to draw the double line I want? Also, I may want to label this double line, so is it possible to draw it like a \path?

Thank you very much,
Bogdan
Attachments
CommutativeDiagram.png
CommutativeDiagram.png (4.81 KiB) Viewed 4905 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

tikZ | Commutative Diagram

Post by localghost »

Please always provide a complete example that is compilable out of the box for everybody. It will be much easier then to test possible solutions without having to think about what is all necessary to get your code working.

The »calc« library of pgf/tikZ allows to calculate coordinates. This ways you can draw a path relative to the lower right matrix element.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{calc,matrix}

\begin{document}
  \begin{tikzpicture}[>=stealth]
    \matrix (m) [
      matrix of math nodes,
      row sep=3em,
      column sep=3em,
      text height=1.5ex,
      text depth=0.25ex
    ] {
      K & X \\
      L & Y \\
    };
    \path[->]        (m-1-1) edge                   (m-1-2)
                     (m-1-1) edge node[left]  {$i$} (m-2-1)
                     (m-1-2) edge node[right] {$p$} (m-2-2)
                     (m-2-1) edge                   (m-2-2);
    \path[dotted,->] (m-2-1) edge (m-1-2);
    \draw[->,double] ($(m-2-2)+(-2em,2em)$) -- (m-2-2) node[midway,sloped,above] {\scriptsize $H$};
  \end{tikzpicture}
\end{document}
It might also be possible to draw the double line as intersection to the dotted line.


Thorsten
Attachments
The rendered output.
The rendered output.
CDsample.png (7.79 KiB) Viewed 4905 times
User avatar
Stefan Kottwitz
Site Admin
Posts: 10350
Joined: Mon Mar 10, 2008 9:44 pm

tikZ | Commutative Diagram

Post by Stefan Kottwitz »

Hi Bogdan,

Thorsten has already provided a nice way. Indeed, calculations with coordinates are generally useful. There's another approace, by placing a coordinate node and referring to that, without calculation.

Placing the center coordinate node, for example when drawing the dotted line:

Code: Select all

\path[dotted,->] (m-2-1) edge coordinate[midway] (center) (m-1-2);
Later we just use it, and shorten the arrow a bit:

Code: Select all

\draw[->,double,shorten <=0.5ex] (center) -- (m-2-2)
    node[midway,sloped,above] {\scriptsize $H$};
Complete code, based on your's and Thorsten's:

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
  \begin{tikzpicture}[>=stealth]
    \matrix (m) [
      matrix of math nodes,
      row sep=3em,
      column sep=3em,
      text height=1.5ex,
      text depth=0.25ex
    ] {
      K & X \\
      L & Y \\
    };
    \path[->]        (m-1-1) edge                   (m-1-2)
                     (m-1-1) edge node[left]  {$i$} (m-2-1)
                     (m-1-2) edge node[right] {$p$} (m-2-2)
                     (m-2-1) edge                   (m-2-2);
    \path[dotted,->] (m-2-1) edge coordinate[midway] (center) (m-1-2);
    \draw[->,double,shorten <=0.5ex] (center) -- (m-2-2)
        node[midway,sloped,above] {\scriptsize $H$};
  \end{tikzpicture}
\end{document}
Commutative Diagram
Commutative Diagram
diagram.png (4.06 KiB) Viewed 4901 times
Stefan
LaTeX.org admin
Post Reply