4

I'm creating labels for edges by manually creating a node and placing it in the center of the edge. Is there a cleaner way to do it? Also I would like to have the edge invisible inside the label.

\begin{figure}
\centering
{
    \begin{tikzpicture}[    transform shape]
        \newcommand\XA{-3}
        \newcommand\YA{0}
        \node (x) [circle, draw=black, align=center, minimum size=1cm] at (\XA,\YA) {$V$};
        \node (y) [circle, draw=black, align=center, minimum size=1cm   ] at (\XA-1.5,\YA-1.5) {$U$};
        \node (l1) [thin, draw=black, align=center, minimum width=0.5cm, minimum height=0.5cm] at(\XA-0.75,\YA-0.75) {\Large d};
        \path[every node/.style={font=\sffamily\small}]
        (x) edge[->] node {} (y);
    \end{tikzpicture}
}
\end{figure}

enter image description here

3

Use fill=white.

\documentclass{article}
\usepackage{tikz}
\begin{document}
  \begin{figure}
\centering
    \begin{tikzpicture}[transform shape,mylabel/.style={thin, draw=black, align=center, minimum width=0.5cm, minimum height=0.5cm,fill=white,font=\Large}]
        \newcommand\XA{-3}
        \newcommand\YA{0}
        \node (x) [circle, draw=black, align=center, minimum size=1cm] at (\XA,\YA) {$V$};
        \node (y) [circle, draw=black, align=center, minimum size=1cm   ] at (\XA-1.5,\YA-1.5) {$U$};
        \draw[->]  (x) -- node[mylabel] {d} (y);
    \end{tikzpicture}
\end{figure}
\end{document}

enter image description here

\centering doesn't take an argument, hence {...} are not needed. Also, edge is a monster, don't use it for small things.

  • perfect. Thank you. This is much cleaner than my approach. – arunmoezhi Oct 27 '14 at 4:40

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.