enter image description hereI want to draw the following diagram in LaTeX:

enter image description here

  • You could youre the TikZ package, you will find a short tutorial at the begin of the documentation. – omisson Sep 25 at 11:04
up vote 8 down vote accepted

It's quite easy with tikz-cd:

enter image description here

\documentclass{article}
\usepackage{tikz-cd}
\begin{document}
\begin{tikzcd}
1 \ar[r,"a"] \ar[rr,bend right,"c"'] & 2 \ar[r,"b"] & 3
\end{tikzcd}
\end{document}

But, in my humble opinion, I'd vote for picture-mode, for its far more user-friendly syntax:

enter image description here

\documentclass{article}
\usepackage{pict2e}
\begin{document}
\setlength{\unitlength}{1cm}
\begin{picture}(2.1,0.75)(0,-0.45)
\put(0,0){1}
  \put(0.2,0.1){\vector(1,0){0.75}}
  \put(0.5,0.15){\footnotesize$a$}
\put(1,0){2}
  \put(1.2,0.1){\vector(1,0){0.75}}
  \put(1.5,0.15){\footnotesize$b$}
\put(2,0){3}
  \qbezier(0.2,-0.05)(1.05,-0.7)(1.9,-0.05)
  \put(1.9,-0.05){\vector(4,3){0.0001}}
  \put(1.0,-0.55){\footnotesize$c$}
\end{picture}
\end{document}

Update: tikz-cd solution for the second diagram:

enter image description here

\documentclass{article}
\usepackage{tikz-cd}
\begin{document}
\begin{tikzcd}
  1 \ar[r,"a_1"]
    \ar[rrrrr,bend right=50,looseness=0.3,"b"']
& 2 \ar[r,"a_2"]
& 3 \ar[r,"a_3"]
& \cdots
  \ar[r,"a_{n-2}"] % This arrow isn't in the picture, but I chose to add it. Feel free to remove.
& n-1 \ar[r,"a_{n-1}"]
& n
\end{tikzcd}
\end{document}
  • 1
    Actually, it's also very easy with plain TikZ (without tikz-cd), but +1 for picture mode ;) – TeXnician Sep 25 at 11:28
  • @TeXnician The tikz-cd answer is so that people can't say I posted a picture mode answer just to gain more rep. I honestly don't know why people think that ;P – Phelype Oleinik Sep 25 at 11:42
  • Your first suggestion is very practical but when I get n points (1, 2, 3, ..., n-1, n) I could not print a_1, a_2,...a_{n-1} on each arrow and I couldn't print b on below arrow from 1 to n. Can you help me? – Fatma Erol Kaynarca Sep 26 at 18:36
  • @FatmaErolKaynarca The first method can certainly be adapted to do what you want. Can you please upload a picture of what you want, I couldn't understand from your description. – Phelype Oleinik Sep 26 at 18:40
  • Okay, I am sorry:( I made correction in the first part I asked the question, can you see from there? If you don't see I upload a picture again, thank you:) – Fatma Erol Kaynarca Sep 26 at 18:48

For the sake of completeness, here it is a plain TikZ approach

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
    \begin{tikzpicture}[node distance = 2cm, thick]% 
        \node (1) {1};
        \node (2) [right=of 1] {2};
        \node (3) [right=of 2] {3};
        \draw[->] (1) -- node [midway,above] {a} (2);
        \draw[->] (1) to [bend right] node [midway,below]{c} (3);
        \draw[->] (2) -- node [midway,above] {b} (3);
    \end{tikzpicture}%
\end{document}

enter image description here

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
    \begin{tikzpicture}[node distance = 2cm, thick]% 
        \node (1) {1};
        \node (2) [right=of 1] {2};
        \node (3) [right=of 2] {3};
        \node (dots) [right=of 3] {$\cdots$};
        \node (n1) [right=of dots] {$n-1$};
        \node (n) [right=of n1] {$n$};
        %
        \draw[->] (1) -- node [midway,above] {$a_1$} (2);
        \draw[->] (1) to [bend right=15cm] node [midway,below]{b} (n);
        \draw[->] (2) -- node [midway,above] {$a_2$} (3);
        \draw[->] (3) -- node [midway,above] {$a_3$} (dots);
        \draw[->] (dots) -- node [midway,above] {$a_{n-2}$} (n1);
        \draw[->] (n1) -- node [midway,above] {$a_{n-1}$} (n);
    \end{tikzpicture}%
\end{document}

enter image description here

  • I can't print letters indexed on arrows ? – Fatma Erol Kaynarca Sep 26 at 17:24
  • @FatmaErolKaynarca could you explain more? Doesn't my code work with you? – Diaa Sep 26 at 18:58
  • Your typed code works very well, but I wanted to do something else, I couldn't fit what I wanted to do with your code. – Fatma Erol Kaynarca Sep 26 at 19:02
  • @FatmaErolKaynarca does my answer update get what you want? – Diaa Sep 26 at 19:16
  • @FatmaErolKaynarca if you mean you can't type, for example, a with subscript 1, you have to type this inside inline math mode by embracing it with the double dollar signs $a_1$. – Diaa Sep 26 at 19:23

A pstrickssolution: the three numbers are defined as nodes, and we link them by node connections.

\documentclass[12pt]{article}
\usepackage{pst-node, auto-pst-pdf}

\begin{document}

\[
  \Rnode{1}{1} \hspace{3em} \Rnode{2}{2} \hspace{3em} \Rnode{3}{3}
\psset{linewidth=0.6pt, arrows=->, arrowinset=0.12, nodesep=0.6ex, labelsep=2pt, shortput=nab}
\everypsbox{\scriptstyle}
\ncline{1}{2}^{a}\ncline{2}{3}^{b}
\ncarc[arcangle=-30]{1}{3}_{c}
\]

\end{document} 

enter image description here

With tikz, it is possible to use the chain concept of the graphs library.

chains are a series of nodes whose syntax is abbreviated compared to their normal syntax. A chain ends with a semicolon. The nodes and their text are identical by default as in the first figure. Nodes and text are the number 1, 2 and 3.

This first figure is composed of 2 chains: the first 1->2->3 and the second which goes directly from 1 to 3.

To add text to the arrow (that is called edge by tikz), simply place the option edge label or edge label' depending on whether the text is above or below the arrow. In reality, this places the text to the left or right when walking in the direction of the chain.

In the second example, to avoid having to draw an arrow, we write -!- instead of -> (see p 265 of the manual). To make the node text different from its name, simply separate the name from the text with a slash. For example : 5/{$n-1$} means that node 5 displays the n-1 text.

chaine-tikz

\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usetikzlibrary{graphs}
\begin{document}

\tikz \graph[grow right=30mm] {
1 ->[edge label={a}] 2   ->[edge label={b}] 3;
1 -> [bend right,edge label'={c}] 3;
};


\tikz \graph[grow right=20mm] {
1 ->[edge label={$a_1$}] 2   ->[edge label={$a_2$}] 3->[edge label={$a_3$}] 4/$\cdots$   -!- 5/{$n-1$}->[edge label={$a_{n-1}$}] n  ;
1 -> [bend right,edge label'={b}] n;
};

\end{document}

Edit:

Using the quotes library, the syntax for writing labels is even shorter: "a" instead of edge label={a} "c"' instead of edge label' ={c} You can customize the colors as below:

chaine

\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usetikzlibrary{graphs,quotes}
\begin{document}

\tikz[thick,gray] \graph[grow right=30mm] {
1 ->["a"] 2   ->["b"] 3;
1 -> [bend right,"c"'] 3;
};

General case:
\smallskip

\tikz[thick,every edge/.style={red,draw},every node/.style={blue}] \graph[grow right=20mm,edge quotes={black,auto}] {
1 ->["$a_1$"] 2   ->["$a_2$"] 3->["$a_3$"] 4/$\cdots$   -!- 5/{$n-1$}->["$a_{n-1}$"] n  ;
1 -> [bend right,"b"'] n;
};

\end{document}

Translated with www.DeepL.com/Translator

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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