0

Below is the coding using Latex to generate 3 nodes and 3 edges graph, as seen in the picture. It works perfectly, with only one small problem. So, each edge has 7, 31, 31, which represent the weight of the edge.

My question is, how to increase the number size (7, 31, 31) so that it will become bigger and look clearer. I want the coding to increase the size of the weight. I will get the same result, but the edge weight (7, 31, 31) will look bigger in the picture.

I attach the second picture; as you can see, the weight (7,31, 31) becomes bigger in their size, but the other parts remain the same—just a perspective like that.

\documentclass[11pt]{scrartcl}

\centering

\newcommand\rad{6.5}

\PassOptionsToPackage{usenames,dvipsnames,svgnames}{xcolor}  

\usepackage{tikz}

\usetikzlibrary{arrows,positioning,automata}

\begin{document}

\begin{tikzpicture}[>=stealth',shorten >=1pt,node distance=7cm,on grid,initial/.style    ={}]

  \node[state]          (S1)  at (120:\rad)    {$S1$};

  \node[state]          (S2)  at (240:\rad)    {$S2$};

  \node[state]          (S3)  at (360:\rad)   {$S3$};

\tikzset{mystyle/.style={->,double=orange}}

\tikzset{every node/.style={fill=white}}

\path (S1)     edge [mystyle]    node   {$7$}   (S2)

      (S2)     edge [mystyle]    node   {$31$}  (S3)

      (S1)     edge [mystyle]    node   {$31$}  (S3);

\end{tikzpicture}

\end{document}

enter image description here

enter image description here

6
  • 1
    Welcome to TeX.SX! A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it).
    – dexteritas
    Jul 15 at 9:59
  • 1
    The question about the weights is not very clear to me. You could edit your question and add an image of the result of the posted code and an image of what you want different. Do you want to change the position of the nodes?
    – dexteritas
    Jul 15 at 10:03
  • I'm not sure this is what you want, but you can say mystyle/.style={->,double=orange,font=\footnotesize} to reduce the font size used for printing the weights.
    – egreg
    Jul 15 at 10:28
  • Your question is not Overleaf specific. It is about how to draw images by tikz. Please, correct question's tags accordingly.
    – Zarko
    Jul 15 at 11:07
  • I have edited my question and put the output image for a better prespective and understanding. Thank you Jul 15 at 11:24
0
\documentclass[11pt]{scrartcl}
\PassOptionsToPackage{usenames,dvipsnames,svgnames}{xcolor}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,automata,
                positioning,
                quotes}

\begin{document}
    \begin{tikzpicture}[
state/.append style = {minimum size=1.8em, inner sep=0pt},
  every edge/.style = {draw=orange, semithick, 
                       -{Stealth[scale=0.8]}, shorten > = 1pt},
every edge quotes/.style = {fill=white, font=\footnotesize}
                        ]
\newcommand\rad{1.44} % for distance ~ 1cm between nodes
%
\node[state]    (S1)  at (120:\rad)    {$S1$};
\node[state]    (S2)  at (240:\rad)    {$S2$};
\node[state]    (S3)  at (360:\rad)   {$S3$};

\path (S1)  edge ["$7$" ]   (S2)
      (S2)  edge ["$33$"]  (S3)
      (S1)  edge ["$33$"]  (S3);
    \end{tikzpicture}
\end{document}

Edit (1): If you like to have positions of nodes somewhere else, than you need to select different coordinates positions. In above MWE (Minimal Working Example) coordinates follows to coordinates defined in your MWE. They are defined in polar coordinate system: <angle>:<distance where in your case the starting point for coordinates is considered (0,0).

If positions of nodes you change to for example

\node[state]    (S1)  at (180:\rad)    {$S1$};
\node[state]    (S2)  at (270:\rad)    {$S2$};
\node[state]    (S3)  at ( 60:\rad)   {$S3$};

then resulted image is:

enter image description here

Of course, you can define cartesian coordinates of nodes. For example, using relative coordinate system:

\documentclass[11pt]{scrartcl}
\PassOptionsToPackage{usenames,dvipsnames,svgnames}{xcolor}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,automata,
                positioning,
                quotes}

\begin{document}
    \begin{tikzpicture}[
state/.append style = {minimum size=1.8em, inner sep=0pt},
  every edge/.style = {draw=orange, semithick, 
                       -{Stealth[scale=0.8]}, shorten > = 1pt},
every edge quotes/.style = {fill=white, font=\footnotesize}
                        ]
%
\node[state]    (S1)  at (0,0)  {$S1$};
\node[state, above right=1cm and 1.4cm of S1]   (S2)    {$S2$};
\node[state, below right=1.4cm and 1cm of S1]   (S3)    {$S3$};

\path (S1)  edge ["$7$" ]   (S2)
      (S2)  edge ["$31$"]   (S3)
      (S1)  edge ["$31$"]   (S3);
    \end{tikzpicture}
\end{document}

Note, from (basic) geometry follows, that equal distance (about 1cm) is possible, if nodes are symmetrical placed on plane, i.e. that they lie on circle. Radius of circle you can calculate. This is simple, if you with distance you consider distance between centers of nodes.

enter image description here

Edit (2): From your comment below, now follows, that you concern is only edge label font sute. It is all MWE in my answer determined by code line:

every edge quotes/.style = {fill=white, font=\Large} % <--- here you can set font size of edge labels

which is at use above settings gives:

enter image description here

If \Large is not sufficient, you can change it to \huge or even \Huge predefined font size, or define own size with

font=\fontsize{<desired size>}{<baselineskip>}\selectfont

for example font=\fontsize{24pt}{28pt}\selectfont for some silly big size for edge labels:

enter image description here

3
  • My problem is not changing the position of the weight like you show. My problem is changing the 'font size' of the weight. I want to make weight look bigger in 'font size'. Jul 15 at 12:39
  • @KamenRider, sorry, your question is not entirely clear about this. Even more, showed images in edited question is mostly concern about node condition. However, font size of edge labels can be simple change. See edited answer.
    – Zarko
    Jul 15 at 13:12
  • @KamenRider, any news?
    – Zarko
    Aug 14 at 19:47

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.