0

I'm trying to code a star graph, using the tikz graphs library. This is what I have so far:

\documentclass[border=10pt]{standalone}

\usepackage{tikz} 
\usetikzlibrary{graphs}

\begin{document}
\pagestyle{empty}

\begin{tikzpicture}

    \graph [clockwise=10, radius=1cm] {
        hidden -> \foreach \i in {1,...,10} {p\i/$P_{\i}$}};

\end{tikzpicture}
\end{document}

The result is this: enter image description here

Why is the root node not centered? Shouldn't everything be nicely disposed around (0, 0)?

6
  • 1
    @Zarko, I am not a native speaker, but I am not sure your edit is correct. Apologies if you are a native speaker and I'm talking nonsense :)
    – Schiphol
    Jul 28, 2021 at 15:07
  • 1
    Actually, your first title was syntaxically correct ;)
    – SebGlav
    Jul 28, 2021 at 15:46
  • 1
    @SebGlav: ‘syntactically’.
    – Bernard
    Jul 28, 2021 at 16:04
  • 1
    Aha, of course ^^ Those mismatches between French and English. That was exactly the place to make this mistake. Thanks, Bernard.
    – SebGlav
    Jul 28, 2021 at 16:07
  • You still can revert my correction of title.
    – Zarko
    Jul 28, 2021 at 16:57

1 Answer 1

1

If your plan is just to draw this particular circular graph, I would not use the graphs library but do the following:

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

\begin{document}
    \begin{tikzpicture}
        \node[ellipse,inner sep=1pt] (h) {hidden};
        \foreach \i in {1,...,10}
            \draw [->] (h) -- (126-36*\i:2) node[shift=(123-36*\i:8pt)] (p\i){$P_{\i}$};
    \end{tikzpicture}
\end{document}

circular graphs without graphs library

Note that I used a radius of 2cm, because with only 1 cm, all nodes were too close from the centre, for my taste.

2
  • Thanks, this is helpful! I do want to use graphs, as I plan to complicate the graph a bit from this MWE.
    – Schiphol
    Jul 28, 2021 at 15:59
  • 1
    So the way you're doing it is wrong. See this, for example.
    – SebGlav
    Jul 28, 2021 at 16:00

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.