0

I'm trying to draw some graphs (as in edges and vertices) for an article. I would like to add a bar to all edges and label them as half-edges.

\usepackage{tikz}

\begin{tikzpicture}[
          every node/.style={circle, draw, fill=black!50,
                            inner sep=0pt, minimum width=4pt}, thick
        ]
        \node(A) at (0,0){};
        \node(B) at (0.5,1){};
        \node(C) at (1,0){};
        \node(D) at (2,0){};

        \draw[-](A)--(B);
        \draw[-](A)--(C);
        \draw[-](B)--(C);
        \draw[-](C)--(D);
        \draw (D) to [out=-45,in=45,looseness=40] (D);
\end{tikzpicture}

This gives me this graph:

enter image description here

Here's the result I would like:

enter image description here

How can I do something like that ? I am using MikTex.

Thank you :)

1 Answer 1

3

You can use decorations.markings.

\documentclass[border=3mm,tikz]{standalone}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[pft/.style n args={3}{postaction={decorate,
    decoration={markings,
    mark=at position 0.25 with {\path (0,#1) node{#2};},
    mark=at position 0.5 with {\draw[thick] (0,-1*#1) -- (0,#1);},
    mark=at position 0.75 with {\path (0,#1) node{#3};}}}},font=\small]     
    \begin{scope}[nodes={circle, draw, fill=black!50,
                            inner sep=0pt, minimum width=4pt}, thick]
        \node(A) at (0,0){};
        \node(B) at (0.5,1){};
        \node(C) at (1,0){};
        \node(D) at (2,0){};
    \end{scope}
        \draw[pft={1ex}{1}{2}](A)-- (B);
        \draw[pft={-1ex}{3}{4}](A)--(C);
        \draw[pft={1ex}{5}{6}](B)--(C);
        \draw[pft={1ex}{7}{8}](C)--(D);
        \draw[pft={-1ex}{9}{10}] (D) to [out=-45,in=45,looseness=40] (D);
\end{tikzpicture}
\end{document}

enter image description here

1
  • Thank you so much !
    – Simon
    Jan 31, 2020 at 14:08

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.