Graphics, Figures & Tables ⇒ Markov Latex
Markov Latex
how to do this Markov diagram in Latex?
Thankss
- Attachments
-
- markov latex.png (30.08 KiB) Viewed 13621 times
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
- Stefan Kottwitz
- Site Admin
- Posts: 10330
- Joined: Mon Mar 10, 2008 9:44 pm
Markov Latex
Code: Select all
\documentclass[tikz, border=10pt]{standalone}
\usetikzlibrary{calc, automata, chains, arrows.meta}
\begin{document}
\begin{tikzpicture}[start chain = going right,
-Triangle, every loop/.append style = {-Triangle}]
\foreach \i in {0,...,4}
\node[state, on chain] (\i) {\i};
\foreach \i in {0,...,3} {
\draw let \n1 = { int(\i+1) } in
(\i) edge[bend left] (\n1)
(\n1) edge[bend left] (\i);
}
\foreach \i in {1,...,3}
\draw (\i) edge[loop below] (\i);
\draw (0) edge[loop left] (0);
\draw (4) edge[loop right] (4);
\end{tikzpicture}
\end{document}
Re: Markov Latex
But one thing more, I would to writte text or number above the arrows.
I do not know how to do it.
Can you help me?
Thanks
- Stefan Kottwitz
- Site Admin
- Posts: 10330
- Joined: Mon Mar 10, 2008 9:44 pm
Re: Markov Latex
I just need to go to sleep now, I will write again tomorrow.
Stefan
- Stefan Kottwitz
- Site Admin
- Posts: 10330
- Joined: Mon Mar 10, 2008 9:44 pm
Markov Latex
It's actually simple: the new
quotes
library, which comes with TikZ 3.0 or later, brings an easy syntax instead of adding nodes:Code: Select all
\draw (0) edge[loop left, "left"] (0);
\draw (4) edge[loop right, "right"] (4);
Code: Select all
\foreach \i/\txt in {1/here,2/there,3/here too}
\draw (\i) edge[loop below, "\txt"] (\i);
Code: Select all
\documentclass[tikz, border=10pt]{standalone}
\usetikzlibrary{calc, automata, chains, arrows.meta, quotes}
\begin{document}
\begin{tikzpicture}[start chain = going right,
-Triangle, every loop/.append style = {-Triangle}]
\foreach \i in {0,...,4}
\node[state, on chain] (\i) {\i};
\foreach \i in {0,...,3} {
\draw let \n1 = { int(\i+1) } in
(\i) edge[bend left] (\n1)
(\n1) edge[bend left] (\i);
}
\foreach \i/\txt in {1/here,2/there,3/here too}
\draw (\i) edge[loop below, "\txt"] (\i);
\draw (0) edge[loop left, "left"] (0);
\draw (4) edge[loop right, "right"] (4);
\end{tikzpicture}
\end{document}
Markov Latex

If you run/execute this code, you will se the strange problem
Code: Select all
\documentclass[12pt,a4paper,tikz,border=10pt]{article}
\usepackage[spanish]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{listings}
\usepackage{fancybox}
\usepackage{fancyvrb}
\usepackage{enumerate}
\usepackage{pstricks}
\usepackage{graphicx}
\usepackage{enumitem}
\usepackage{parskip}
\usepackage{tikz}
\usetikzlibrary{calc, automata, chains, arrows.meta, quotes}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[left=3cm,right=2cm,top=1cm,bottom=2cm]{geometry}
\title{Cadenes de Markov}
\date{}
%%%%%%%%%%%%%%%%%%%%% COLORES %%%%%%%%%%%%%%%%%%%%%%%
\usepackage{color}
\definecolor{gray97}{gray}{.97}
\definecolor{gray75}{gray}{.75}
\definecolor{gray45}{gray}{.45}
\usepackage{mdframed}
\usepackage{subfig}
\usepackage{epsfig}
\usepackage{enumitem}
\usepackage{listings}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\maketitle
\noindent \large{\textbf{Ejercicio 1.}}
\\
\begin{tikzpicture}[start chain = going right,
-Triangle, every loop/.append style = {-Triangle}]
\foreach \i in {0,...,4}
\node[state, on chain] (\i) {\i};
\foreach \i in {0,...,3} {
\draw let \n1 = { int(\i+1) } in
(\i) edge[bend left] (\n1)
(\n1) edge[bend left] (\i);
}
\foreach \i/\txt in {1/here,2/there,3/here too}
\draw (\i) edge[loop below, "\txt"] (\i);
\draw (0) edge[loop left, "left"] (0);
\draw (4) edge[loop right, "right"] (4);
\end{tikzpicture}
\end{document}
- Stefan Kottwitz
- Site Admin
- Posts: 10330
- Joined: Mon Mar 10, 2008 9:44 pm
Markov Latex
Code: Select all
\shorthandoff{"}
Stefan
Markov Latex
Sorry but I need the last one thing, I don´t know to writte above translation.
I tried this but it does not run
Code: Select all
\draw (\i) edge[bend left,"\txt"] (\n1)
\draw (0) edge[bend left,"a"] (1)
I need this: (photo)
thanks
- Attachments
-
- markov-writte.png (17.55 KiB) Viewed 13539 times