Graphics, Figures & TablesTikz edge label spacing from line

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
macgyver
Posts: 4
Joined: Fri Nov 06, 2009 2:41 pm

Tikz edge label spacing from line

Post by macgyver »

Hi everyone!

I would like to move the labels of the edges a little more to the left/right/below because they are clipping part of the edges.

I’ve used \tikzstyle{LabelStyle}=[right/left/above/below] however the spacing provided is not enough.

Here is a minimal working example showing the problem

Code: Select all

\documentclass[]{article}
\usepackage{tkz-berge}
\usepackage[position=top]{subfig}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[scale=1,transform shape]
  \Vertex[x=0,y=0,Math=true]{v_{2}}
  \Vertex[position={right of=v_{2},xshift=3cm},Math=true]{v_{3}}
  \Vertex[position={above of=v_{2},yshift=2cm,xshift=2cm},Math=true]{v_{1}}
  \Vertex[position={right of=v_{1},xshift=3cm},Math=true]{v_{4}}
\tikzstyle{EdgeStyle}=[right] \tikzstyle{LabelStyle}=[below]
\Edge[label=$e_{3}$](v_{2})(v_{3})\tikzstyle{LabelStyle}=[left]
\Edge[label=$e_{1}$](v_{2})(v_{1})
\Edge[label=$e_{4}$](v_{3})(v_{4}) \tikzstyle{LabelStyle}=[right]
\Edge[label=$e_{2}$](v_{1})(v_{3})
\end{tikzpicture}
\end{figure}
\end{document}
Could you please help me on this issue?
Thanks in advance.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Tikz edge label spacing from line

Post by localghost »

At first, when using packages (or classes) that can not be found on CTAN you should attach them or at least give a link where to find them [1].

The issues can entirely be solved by looking at the pgf/tikZ manual. Modify your code as shown below.

Code: Select all

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{tkz-berge}

\begin{document}
  \begin{figure}[!ht]
    \centering
    \begin{tikzpicture}[scale=1,transform shape]
      \Vertex[x=0,y=0,Math=true]{v_{2}}
      \Vertex[position={right of=v_{2},xshift=3cm},Math=true]{v_{3}}
      \Vertex[position={above of=v_{2},yshift=2cm,xshift=2cm},Math=true]{v_{1}}
      \Vertex[position={right of=v_{1},xshift=3cm},Math=true]{v_{4}}
      \tikzstyle{EdgeStyle}=[right] \tikzstyle{LabelStyle}=[below=3pt]
      \Edge[label=$e_{3}$](v_{2})(v_{3})\tikzstyle{LabelStyle}=[above left]
      \Edge[label=$e_{1}$](v_{2})(v_{1})
      \Edge[label=$e_{4}$](v_{3})(v_{4}) \tikzstyle{LabelStyle}=[above right]
      \Edge[label=$e_{2}$](v_{1})(v_{3})
    \end{tikzpicture}
  \end{figure}
\end{document}
Note the modifications to the LabelStyle declarations.

[1] ALTERMUNDUS - Archives Générales


Best regards and welcome to the board
Thorsten¹
macgyver
Posts: 4
Joined: Fri Nov 06, 2009 2:41 pm

Re: Tikz edge label spacing from line

Post by macgyver »

Thank you so much for your advice and help! I really appreciate it!
Post Reply