2

I've got the following code:

\begin{tikzpicture}[node distance=2cm, auto]
    \node (0) {\Large$0$};
    \node (1) [right of=0] {\Large$1$};
    \node (2) [right of=1] {\Large$2$};
    \node (3) [right of=2] {\Large$3$};
    \node (4) [right of=3] {\Large$\cdots$};
    \draw[->] (1.160) to node {\small$(0,1)$} (0.20);
    \draw[->] (1.200) to node [swap] {\small$(1,0)$} (0.340);
    \draw[->] (2.160) to node {\small$(0,1)$} (1.20);
    \draw[->] (2.200) to node [swap] {\small$(1,0)$} (1.340);
    \draw[->] (3.160) to node {\small$(0,1)$} (2.20);
    \draw[->] (3.200) to node [swap] {\small$(1,0)$} (2.340);
    \draw[->] (4.169) to node {\small$(0,1)$} (3.20);
    \draw[->] (4.191) to node [swap] {\small$(1,0)$} (3.340);
\end{tikzpicture}

This gives me the following picture:

messed up diagram

It was basically working fine, but I decided to switch the directions of all the arrows, it previously gave me this:

neat but backwards diagram

which is basically what I want.

So my question is how do I adjust the label positions of my edges?

  • Maybe something like that example: \draw (0,0) -- (6,0) node[midway,fill=white] {Test};? I don't fully understand the question … – current_user Aug 2 '18 at 20:56
  • 3
    Since you specify all angles explicitly, you have to swap the positions of the [swap]s. – user121799 Aug 2 '18 at 21:04
3

I'll be happy to retract this answer, just in case nobody answers. The issue is that you specify all the angles explicitly. Therefore, what worked fine in one direction, won't work fine if you reverse the direction. So you could either exchange the angles, i.e. 160 <-> 200 and 20 <-> 340, or, what is easier, swap the positions of the [swap]s. Of course, the results of these procedures differ.

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}[node distance=2cm, auto]
    \node (0) {\Large$0$};
    \node (1) [right of=0] {\Large$1$};
    \node (2) [right of=1] {\Large$2$};
    \node (3) [right of=2] {\Large$3$};
    \node (4) [right of=3] {\Large$\cdots$};
    \draw[->] (1.160) to node [swap] {\small$(0,1)$} (0.20);
    \draw[->] (1.200) to node {\small$(1,0)$} (0.340);
    \draw[->] (2.160) to node [swap] {\small$(0,1)$} (1.20);
    \draw[->] (2.200) to node {\small$(1,0)$} (1.340);
    \draw[->] (3.160) to node [swap] {\small$(0,1)$} (2.20);
    \draw[->] (3.200) to node {\small$(1,0)$} (2.340);
    \draw[->] (4.169) to node [swap] {\small$(0,1)$} (3.20);
    \draw[->] (4.191) to node {\small$(1,0)$} (3.340);
\end{tikzpicture}
\end{document}

enter image description here

  • moving the [swap] was a great and easy fix. thanks! – Math chiller Aug 3 '18 at 0:04
1

an alternative solution: based on use of the tikz libraries chains and positioning and since seems to be all arrow labels the same, is used loop for drawing them between nodes:

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{chains, positioning}

\begin{document}
    \begin{tikzpicture}[
node distance = 1cm,
  start chain = A going right,
  num/.style = {font=\Large, on chain=A},
                        ]
\node[num]  {$0$};      % node name: A-1
\node[num]  {$1$};
\node[num]  {$2$};
\node[num]  {$3$};
\node[num]  {$\cdots$}; % node name: A-5
%
\foreach \i [evaluate=\i as \j using int(\i-1)] in {5,...,2}
{
\draw[->,transform canvas={yshift=+1mm}]   (A-\i) -- node[above,font=\small] {$(0,1)$} (A-\j);
\draw[->,transform canvas={yshift=-1mm}]   (A-\i) -- node[below,font=\small] {$(1,0)$} (A-\j);
}

enter image description here

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.