1
\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
\node[draw, shape=circle] (n0) at (0,0) {0};
\node[draw, shape=circle] (n1) at (2,0) {1};
\node[draw, shape=circle] (n2) at (2,2) {2};
\node[draw, shape=circle] (n3) at (0,2) {3};

\draw[->] (n0) -- (n1);
\draw[->] (n1) -- (n2);
\draw[->] (n2) -- (n3);
\draw[->] (n3) -- (n0);      
\end{tikzpicture}
\end{document}

The above is what I wanted, but I was wondering if there is a single-line solution for the same. I tried:

\draw[->] (n0) -- (n1) -- (n2) -- (n3) -- (n0);  

But this gave an arrow tip at the end of the path only.

How can I draw the arrow tip for every edge?

5
  • Simple, with defining edge style. For example: every edge/.style = {->}. That I can show you this, please extend your code fragment to an MWE!
    – Zarko
    Oct 14, 2022 at 16:21
  • @Zarko I added an MWE.
    – Chang
    Oct 14, 2022 at 16:32
  • With a single line \draw[->] (n0) edge (n1) (n1) edge (n2) (n2) edge (n3) (n3) edge (n0); Oct 14, 2022 at 16:40
  • @SimonDispa Thanks! Any method without repeating nodes?
    – Chang
    Oct 14, 2022 at 16:43
  • \draw[->] (n0) edge(n1) edge[<-] (n3) (n2) edge (n3) edge[<-] (n1); Oct 14, 2022 at 17:01

1 Answer 1

3

In order to have an arrowhead on each edge, you have two choices :

  • as you do in your MWE, or
  • instead of --, use edge which defines style for example as is done in MWE below and for all edges and than for all edges use only one command \draw.
%\documentclass{article}
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}

\begin{document}
    \begin{tikzpicture}[
C/.style = {circle, draw, minimum size=1em},
every edge/.style = {draw, -Straight Barb}
                        ]
\node [C] (n0) at (0,0) {0};
\node [C] (n1) at (2,0) {1};
\node [C] (n2) at (2,2) {2};
\node [C] (n3) at (0,2) {3};
    
\draw   (n0) edge (n1) 
        (n1) edge (n2) 
        (n2) edge (n3) 
        (n3) edge (n0);
\end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

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