3

I would like to illustrate properties of binary relation on a graph G(V,E), where V={a,b,c,d,e} and E={aa,ab,ac,bb,bc,bd…}

Going through documentation and examples I tried several different approaches, however none of results was exactly satisfactory. Most elegant attempt is probably this one, yet it still does not produce complete solution:

\tikz \graph [simple] {
    subgraph K_n [->,n=5, clockwise];
    % Redirect edges:
    1 <- 4;
    1 <- 5;
    2 <- 5;
    2 <- 1;
    3 <- 1;
    3 <- 2;
    4 <- 2;
    4 <- 3;
    5 <- 3;
    5 <- 4;
};

Can I

  • rename vertices to a,b,c,d,e,
  • add loop to each node to illustrate reflexivity?

Another almost working attempt producing badly skewed graph:

\begin{tikzpicture}[node distance=3cm,gnode/.style={circle,draw,font=\bfseries}]
    \node[gnode](d) {d};
    \node[gnode](c) [right of=d] {c};
    \node[gnode](e) [above left of=d] {e};
    \node[gnode](b) [above right of=c] {b};
    \node[gnode](a) [above right of=e] {a};
    \graph{
        (a) -> {(b),(c)};
        (b) -> {(c),(d)};
        (c) -> {(d),(e)};
        (d) -> {(e),(a)};
        (e) -> {(a),(b)};
        };
    \path
        (a) edge [loop above] node {} (a)
        (b) edge [loop right] node {} (b)
        (c) edge [loop below] node {} (c)
        (d) edge [loop below] node {} (d)
        (e) edge [loop left] node {} (e);
\end{tikzpicture}
  • What do you mean by almost complete? It is complete right? – Symbol 1 Mar 23 '15 at 0:13
  • @Symbol1 binary relation R it is describing is defined like this: aRa, aRb, aRc, bRb, bRc, bRd, cRc, cRd, cRe … eRe, eRa, eRb. This R relation is represented by oriented edge in the graph, so it looks like K₅ with oriented edges and loop added at each vertex. – Mr. Tao Mar 23 '15 at 0:20
  • Oops, I got it. Well, there is \foreach in TikZ. And there is 1/a-syntax so that 1 becomes the name and a becomes the label. – Symbol 1 Mar 23 '15 at 0:29
  • 1
    @Symbol1: Indeed! This produces acceptable graph: \foreach \name/\angle/\text in {P-1/234/d, P-2/162/e, P-3/90/a, P-4/18/b, P-5/-54/c} \node[vertex,xshift=6cm,yshift=.5cm] (\name) at (\angle:1cm) {$\text$}; \foreach \from/\to in {1/2,2/3,3/4,4/5,5/1,1/3,2/4,3/5,4/1,5/2} { \draw (P-\from) -- (P-\to); } \foreach \from/\pos in {1/below,2/left,3/above,4/right,5/below} { \path (P-\from) edge[loop \pos] node {} (P-\from); } – Mr. Tao Mar 23 '15 at 1:05
  • You can/are encourages to answer your own question. You can also include a snapshot to make it more beginner-friendly. – Symbol 1 Mar 23 '15 at 2:19
2

Inspired by Symbol1’s comment I went through graphs in TikZ gallery where the Automata example provided almost complete solution. Below is slightly tweaked code and resulting graph.

\documentclass[]{scrartcl}

\usepackage{tikz}
\begin{document}
\pagestyle{empty}

\begin{tikzpicture}[shorten >=1pt,->]
    \tikzstyle{vertex}=[circle,draw=black!25,minimum size=17pt,inner sep=0pt]

    \foreach \name/\angle/\text in {P-1/234/d, P-2/162/e, P-3/90/a, P-4/18/b, P-5/-54/c}
        \node[vertex,xshift=6cm,yshift=.5cm] (\name) at (\angle:1cm) {$\text$};

    \foreach \from/\to in {1/2,2/3,3/4,4/5,5/1,1/3,2/4,3/5,4/1,5/2}
        { \draw (P-\from) -- (P-\to); }

    \foreach \from/\pos in {1/below,2/left,3/above,4/right,5/below}
        { \path (P-\from) edge[loop \pos] node {} (P-\from); }
\end{tikzpicture}

\end{document}

relation represented as graph

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.