1

enter image description here

I am a little new to LaTeX and I am trying to draw this grid with arrows using TikZ. Currently I am only able to draw the grid using :

\begin{tikzpicture}
\draw[step=1cm, black] (-1.9,-1.9) grid (5.9,5.9);
\end{tikzpicture}

However I am not able to do much more than that with my current skill level and I've tried to find a way online however it wasn't fruitful. I would appreciate any help on the matter.

In addition I want to be able to reproduce a drawing like the following one :enter image description here

The general structure of the image is not really crucial to me, what I want to learn is how to add numbers (or letters) like in the picture and how I can align two vertices next to each other.

1

1 Answer 1

1

Below is a pretty naïve approach.

To draw arrows, the arrows.meta module is quite useful, providing support for various arrow types. To enable it, put the following line in your preamble after you have loaded tikz.

\usetikzlibrary{arrows.meta}

Within the tikzpicture, you can add a scope, so that each time you can simply use > to refer to the arrow tip you want. For example, below I shall use Stealth.

\begin{scope}[>=Stealth]
    ...
\end{scope}

You can then draw the lines first:

\draw (0,0) -- (0, 1);
\draw (0,0) -- (0,-1);
\draw (0,0) -- ( 1,0);
\draw (0,0) -- (-1,0);

enter image description here

An arrow can be drawn like

\draw[->] (0,0) -- (0.6,0);

enter image description here

Here the arrow is placed at (0.6,0) (the line from (0,0) to (0.6,0) coincide with the line that you've drawn in the previous step). In the same way, you can draw an arrow of reversed direction:

\draw[>-] ( 0.6,0) -- (0,0);

enter image description here

Below is the complete code for a "c-type" arrow in your picture:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{arrows.meta}

\begin{document}

\begin{tikzpicture}
    \begin{scope}[>=Stealth]
        \draw (0,0) -- (0, 1);
        \draw (0,0) -- (0,-1);
        \draw (0,0) -- ( 1,0);
        \draw (0,0) -- (-1,0);
        \draw[->] (0,0) -- (0, 0.6);
        \draw[->] (0,0) -- (0,-0.6);
        \draw[>-] ( 0.6,0) -- (0,0);
        \draw[>-] (-0.6,0) -- (0,0);
    \end{scope}
\end{tikzpicture}

\end{document}

enter image description here

For the grid with arrows, since the distribution of your arrows doesn't seem very regular, you might have to repeat the above steps to draw the arrows -- shouldn't be that hard.

But this is just a beginning, which works even with a minimal amount of TikZ knowledge. I'm not proud of my TikZ skill, there might be some clever methods that can produce such graphs with very simple commands -- I shall left it to the experts :)


Regarding the labeling, this is simple, you can use \node:

\begin{tikzpicture}
    \draw (0,0) -- (0, 1);
    \draw (0,0) -- (0,-1);
    \draw (0,0) -- ( 1,0);
    \draw (0,0) -- (-1,0);
    \node at (0.2, 0.6) {$1$};
    \node at (0.2,-0.6) {$2$};
    \node at ( 0.6,0.2) {$2$};
    \node at (-0.6,0.2) {$1$};
\end{tikzpicture}

enter image description here

1
  • Thanks a lot ! It was extremely helpful I was able to redo them and I am going to post the code for it !
    – Ceethemez
    Commented Jun 19, 2022 at 20:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .