3

I have this graph where the times above the nodes is the departure time. How can I format the "+1" better? It stands for the "next day". Now is too big with respect to the time, and also the 'plus' is exaggerated. I was trying to put the "+1" smaller and maybe with a different colour.

How can I achieve this? Thanks!

EDIT: How can I also reduce the white part that covers each edges? (the part in the middle of the edge covered by a number)

\documentclass[margin=10pt]{standalone}
\usepackage{color,xcolor}
\usepackage{tikz-qtree, tikz}
\usepackage{pgfplots}
\usepackage[utf8]{inputenc} 
\usetikzlibrary{decorations.pathreplacing,arrows,shapes,positioning,shadows,calc}
\usetikzlibrary{decorations, decorations.text,backgrounds}
\tikzset{every picture/.style={font issue=\footnotesize},
    font issue/.style={execute at begin picture={#1\selectfont}}
}

\pgfplotsset{width=10cm,compat=1.17}
\usepgfplotslibrary{fillbetween}

\usetikzlibrary{arrows.meta}
\usetikzlibrary{positioning}
\usepackage{clock}
\usepackage[clock]{ifsym}

\ClockFrametrue\ClockStyle=0

\newcommand{\orig}{\mathcal{O}} % origin position
\newcommand{\dest}{\mathcal{D}} % destination position

\begin{document}
    \begin{tikzpicture}
            \begin{scope}[every node/.style={circle,thick,draw}]
            \node[fill=red!30] (Orig) at (0,0) {$\orig$};
            \node (A) at (2,2) {A};
            \node (B) at (2.3,0.5) {B};
            \node (C) at (3.3,-1.2) {C};
            \node (H) at (4.2,2.1) {H};
            \node (L) at (6.4,-0.5) {L};
            \node (E) at (5.9,1.9) {E} ;
            \node[fill=green!30] (Dest) at (8,1) {$\dest$};
        \end{scope}
        
        \begin{scope}[>={stealth[black]},
            every node/.style={fill=white,circle},
            every edge/.style={draw=red,very thick}]
            \path [->] (Orig) edge node {$5$} (A);
            \path [->] (A) edge node {$5$} (H);
            \path [->] (H) edge node {$3$} (E);
            \path [->] (E) edge node {$8$} (Dest); 
            % \path [->] (B) edge[bend right=60] node {$1$} (E); 
        \end{scope}
    
        \begin{scope}[>={stealth[black]},
            every node/.style={fill=white,circle},
            every edge/.style={draw=black,very thick}]
            \path [->] (Orig) edge node {$5$} (B);
            \path [->] (Orig) edge node {$5$} (C);
            \path [->] (B) edge node {$3$} (C);
            \path [->] (B) edge node {$3$} (H);
            \path [->] (B) edge node {$3$} (L);
            \path [->] (C) edge node {$5$} (L);
            \path [->] (E) edge node {$8$} (L); 
            \path [->] (L) edge node {$8$} (Dest); 
        \end{scope}
    

        \begin{scope}[font=\tiny]
            \node [above=0.5pt of A] {\clock{15}{30} 15:30};
            \node [below=0.5pt of Orig] {\clock{18}{15} 18:15};
            \node [above=0.5pt of H] {\clock{8}{30} 8:30$^{+1}$};
            \node [above=0.5pt of E] {\clock{10}{45} 10:45$^{+1}$};
            \node [above=0.5pt of Dest, align=center] {Arrive \\ \clock{12}{00} 12:00$^{+1}$};
        \end{scope}

    
        \matrix [draw,above left, row sep=1mm, nodes={font=\scriptsize}] at (current bounding box.north east) {
            \node [circle, black, draw, label=right:Hotel] {H}; \\
            \node [circle, black, draw, label=right:Lunch] {L}; \\
        };
    \end{tikzpicture}
\end{document}

Graph

1
  • For the edges, use inner sep=1pt (or any size that suits you). For the clocks, you could scale them using scale=0.8 in the node definition, for example.
    – SebGlav
    Mar 3, 2022 at 22:21

3 Answers 3

4

I would a bit redesign your image. I suggest to use :

  • quotes library for edges labels
  • at nodes O,A,H,E and D use labels for time information
  • most of styles write as option to tikzpicture:
\documentclass[margin=10pt]{standalone}

\usepackage{clock}
\ClockFrametrue\ClockStyle=1

\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                positioning,
                quotes}

\begin{document}
    \begin{tikzpicture}[
C/.style = {circle, draw, fill=#1, minimum size=1em, inner sep=1pt},
C/.default = white,
every label/.style = {align=center, font=\tiny, inner sep=2pt},
every edge/.style = {draw, - Stealth, thick},
every edge quotes/.style = {font=\scriptsize, text=black, fill=white, inner sep=2pt}
                        ]
\node (O) [C=red!30, 
           label=below:\clock{18}{15}\\\scriptsize{18:15}]  {$\mathcal{O}$};
\node (A) [C,
           label=above:\clock{15}{30}\\\scriptsize{15:30}]          at (2,2)    {A};
\node (B) [C] at (2.3,0.5) {B};
\node (C) [C] at (3.3,-1.2) {C};
\node (H) [C, 
           label=above:\clock{8}{30}\\\scriptsize{8:30$^{+1}$}]      at (4,2)    {H};
\node (L) [C] at (6.4,-0.5) {L};
\node (E) [C, 
           label=above:\clock{10}{45}\\\scriptsize{10:45$^{+1}$}]   at (6,2)    {E} ;
\node (D) [C=green!30,
           label=85:{\scriptsize Arrive:\\[1ex] 
                        \clock{12}{00}
                        \scriptsize 12:00$^{+1}$}]  at (8,1)    {$\mathcal{D}$};

\path [red] (O) edge ["5"]  (A) 
            (A) edge ["5"]  (H) 
            (H) edge ["3"]  (E) 
            (E) edge ["8"]  (D);
\path       (O) edge ["5"]  (B)
            (O) edge ["5"]  (C)
            (B) edge ["3"]  (C)
            (B) edge ["3"]  (H)
            (B) edge ["3"]  (L)
            (C) edge ["5"]  (L)
            (E) edge ["8"]  (L)
            (L) edge ["8"]  (D);

\matrix [draw,above left, row sep=1mm] 
        at (current bounding box.north east) 
{\node [C, label=right:Hotel] {H}; \\
 \node [C, label=right:Lunch] {L}; \\
};
    \end{tikzpicture}
\end{document}

enter image description here

3
  • Nicer solution, indeed. Still, I don't understand why I don't get the clock to print, even with your code...
    – SebGlav
    Mar 4, 2022 at 10:35
  • 1
    @SebGlav, I tested (and show result of compilation) with recent MiKTeX and used package versions (article.cls 2021/10/04 v1.4n Standard LaTeX document class size10.clo 2021/10/04 v1.4n Standard LaTeX file (size option) clock.sty 2001/04/10 v0.1 TeXclock tikz.sty 2021/05/15 v3.1.9a (3.1.9a) pgf.sty 2021/05/15 v3.1.9a (3.1.9a). I tested again and get the same result as shown in answer.
    – Zarko
    Mar 4, 2022 at 11:39
  • Considering the date of clock.sty, I shouldn't get this error, but I'll update my TeX distribution. Thanks.
    – SebGlav
    Mar 4, 2022 at 14:54
3

I don't know why clocks don't come up for me, but the rest is ok, so...

resize font in nodes

\documentclass[margin=10pt]{standalone}

\usepackage{color,xcolor}
\usepackage{tikz-qtree, tikz}
\usepackage{pgfplots}
\usepackage[utf8]{inputenc} 
\usetikzlibrary{decorations.pathreplacing,arrows,shapes,positioning,shadows,calc}
\usetikzlibrary{decorations, decorations.text,backgrounds}
\tikzset{every picture/.style={font issue=\footnotesize},
    font issue/.style={execute at begin picture={#1\selectfont}}
}

\pgfplotsset{width=10cm,compat=1.17}
\usepgfplotslibrary{fillbetween}

\usetikzlibrary{arrows.meta}
\usetikzlibrary{positioning}
\usepackage{clock}
\usepackage[clock]{ifsym}

\ClockFrametrue\ClockStyle=0

\newcommand{\orig}{\mathcal{O}} % origin position
\newcommand{\dest}{\mathcal{D}} % destination position

\begin{document}
    \begin{tikzpicture}
            \begin{scope}[every node/.style={circle,thick,draw}]
            \node[fill=red!30] (Orig) at (0,0) {$\orig$};
            \node (A) at (2,2) {A};
            \node (B) at (2.3,0.5) {B};
            \node (C) at (3.3,-1.2) {C};
            \node (H) at (4.2,2.1) {H};
            \node (L) at (6.4,-0.5) {L};
            \node (E) at (5.9,1.9) {E} ;
            \node[fill=green!30] (Dest) at (8,1) {$\dest$};
        \end{scope}
        
        \begin{scope}[>={stealth[black]},
            every node/.style={fill=white,circle, inner sep = 0.5pt},
            every edge/.style={draw=red,very thick}]
            \path [->] (Orig) edge node {$5$} (A);
            \path [->] (A) edge node {$5$} (H);
            \path [->] (H) edge node {$3$} (E);
            \path [->] (E) edge node {$8$} (Dest); 
            % \path [->] (B) edge[bend right=60] node {$1$} (E); 
        \end{scope}
    
        \begin{scope}[>={stealth[black]},
            every node/.style={fill=white,circle,inner sep=0.5pt},
            every edge/.style={draw=black,very thick}]
            \path [->] (Orig) edge node {$5$} (B);
            \path [->] (Orig) edge node {$5$} (C);
            \path [->] (B) edge node {$3$} (C);
            \path [->] (B) edge node {$3$} (H);
            \path [->] (B) edge node {$3$} (L);
            \path [->] (C) edge node {$5$} (L);
            \path [->] (E) edge node {$8$} (L); 
            \path [->] (L) edge node {$8$} (Dest); 
        \end{scope}
    

        \begin{scope}[font=\tiny, every node/.style={scale=0.8}]
            \node [above=0.5pt of A] {\clock{15}{30} 15:30};
            \node [below=0.5pt of Orig] {\clock{18}{15} 18:15};
            \node [above=0.5pt of H] {\clock{8}{30} 8:30$^{+1}$};
            \node [above=0.5pt of E] {\clock{10}{45} 10:45$^{+1}$};
            \node [above=0.5pt of Dest, align=center] {Arrive \\ \clock{12}{00} 12:00$^{+1}$};
        \end{scope}

    
        \matrix [draw,above left, row sep=1mm, nodes={font=\scriptsize}] at (current bounding box.north east) {
            \node [circle, black, draw, label=right:Hotel] {H}; \\
            \node [circle, black, draw, label=right:Lunch] {L}; \\
        };
    \end{tikzpicture}
\end{document}

EDIT

I probably did't read correctly in the first place, you wanted to resize the +1 only. One way to do this is to add a label to your node, containing the +1 and positionned correctly. I tried this (note the style for every node):

\begin{scope}[font=\tiny,every node/.style={inner sep=0pt}]
            \node [above=0.5pt of A] {\clock{15}{30} 15:30};
            \node [below=0.5pt of Orig] {\clock{18}{15} 18:15};
            \node [above=0.5pt of H,label={[scale=0.7]10:$+1$}] {\clock{8}{30} 8:30};

which leads to this:

different labeling

You can see the difference betwenn node H (with label) and node E (with the old style). Here's the complete code where Arrive is also put as a node label:

\documentclass[margin=10pt]{standalone}
% https://tex.stackexchange.com/q/635913/204164

\usepackage{color,xcolor}
\usepackage{tikz-qtree, tikz}
\usepackage{pgfplots}
\usepackage[utf8]{inputenc} 
\usetikzlibrary{decorations.pathreplacing,arrows,shapes,positioning,shadows,calc}
\usetikzlibrary{decorations, decorations.text,backgrounds}
\tikzset{every picture/.style={font issue=\footnotesize},
    font issue/.style={execute at begin picture={#1\selectfont}}
}

\pgfplotsset{width=10cm,compat=1.17}
\usepgfplotslibrary{fillbetween}

\usetikzlibrary{arrows.meta}
\usetikzlibrary{positioning}
\usepackage{clock}
\usepackage[clock]{ifsym}

\ClockFrametrue\ClockStyle=0

\newcommand{\orig}{\mathcal{O}} % origin position
\newcommand{\dest}{\mathcal{D}} % destination position

\begin{document}
    \begin{tikzpicture}
            \begin{scope}[every node/.style={circle,thick,draw}]
            \node[fill=red!30] (Orig) at (0,0) {$\orig$};
            \node (A) at (2,2) {A};
            \node (B) at (2.3,0.5) {B};
            \node (C) at (3.3,-1.2) {C};
            \node (H) at (4.2,2.1) {H};
            \node (L) at (6.4,-0.5) {L};
            \node (E) at (5.9,1.9) {E} ;
            \node[fill=green!30] (Dest) at (8,1) {$\dest$};
        \end{scope}
        
        \begin{scope}[>={stealth[black]},
            every node/.style={fill=white,circle, inner sep = 0.5pt},
            every edge/.style={draw=red,very thick}]
            \path [->] (Orig) edge node {$5$} (A);
            \path [->] (A) edge node {$5$} (H);
            \path [->] (H) edge node {$3$} (E);
            \path [->] (E) edge node {$8$} (Dest); 
            % \path [->] (B) edge[bend right=60] node {$1$} (E); 
        \end{scope}
    
        \begin{scope}[>={stealth[black]},
            every node/.style={fill=white,circle,inner sep=0.5pt},
            every edge/.style={draw=black,very thick}]
            \path [->] (Orig) edge node {$5$} (B);
            \path [->] (Orig) edge node {$5$} (C);
            \path [->] (B) edge node {$3$} (C);
            \path [->] (B) edge node {$3$} (H);
            \path [->] (B) edge node {$3$} (L);
            \path [->] (C) edge node {$5$} (L);
            \path [->] (E) edge node {$8$} (L); 
            \path [->] (L) edge node {$8$} (Dest); 
        \end{scope}
    

        \begin{scope}[font=\tiny,every node/.style={inner sep=0pt}]
            \node [above=0.5pt of A] {\clock{15}{30} 15:30};
            \node [below=0.5pt of Orig] {\clock{18}{15} 18:15};
            \node [above=0.5pt of H,label={[scale=0.7]10:$+1$}] {\clock{8}{30} 8:30};
            \node [above=0.5pt of E,label={[scale=0.7]10:$+1$}]{\clock{10}{45} 10:45};
            \node [above=0.5pt of Dest, align=center,label={[label distance=2pt]above:Arrive},label={[scale=0.7]10:$+1$}] {\clock{12}{00} 12:00};
        \end{scope}

    
        \matrix [draw,above left, row sep=1mm, nodes={font=\scriptsize}] at (current bounding box.north east) {
            \node [circle, black, draw, label=right:Hotel] {H}; \\
            \node [circle, black, draw, label=right:Lunch] {L}; \\
        };
    \end{tikzpicture}
\end{document}

Not related, but your code could be improved to be shorter, you don't need all those scopes.

1

enter image description here

I used the \scalebox command to downsize the +1.

The whitespace around the arrow labels is controlled by setting inner sep.

Also, I rewrote your code in a way that felt more natural to me, without all the scopes. Using \foreach is an easy way to set the coordinates and edges, in case you want to add or change any.

Here is the code:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning}

\usepackage{clock}

\ClockFrametrue\ClockStyle=0

\newcommand{\orig}{\ensuremath{\mathcal{O}}} % origin position
\newcommand{\dest}{\ensuremath{\mathcal{D}}} % destination position

\tikzset{vertex/.style={circle, thick, inner sep=0mm, minimum width=7mm, draw}}

\begin{document}

\begin{tikzpicture}
\node[vertex, fill=red!30] (Orig) at (0,0) {$\orig$};
\node[vertex, fill=green!30] (Dest) at (8,1) {$\dest$};
\foreach \x/\y/\nm/\lbl in {2/2/A/A,2.3/.5/B/B,3.3/-1.2/C/C,4.2/2.1/H/H,6.4/-.5/L/L,5.9/1.9/E/E} 
    \node[vertex](\nm) at (\x,\y) {\lbl};
\foreach \a\b\lbl in {Orig/B/5,Orig/C/5,B/C/3,B/H/3,B/L/3,C/L/5,E/L/8,L/Dest/8}
    \draw [very thick,-stealth](\a)--(\b) node[circle, fill=white, inner sep=.5mm, midway]{\lbl};
\foreach \a\b\lbl in {Orig/A/5,A/H/5,H/E/3,E/Dest/8}
    \draw [draw=red, fill=black, very thick, arrows={-stealth[black]}](\a)--(\b) node[circle, fill=white, inner sep=.5mm, midway]{\lbl};
\foreach \n\hr\min\day in {A/15/30/,Orig/18/15/,H/8/30/+1,E/10/45/+1,Dest/12/00/+1}
    \node [font=\tiny, above=0.5pt of \n] {\clock{\hr}{\min} \hr:\min${}^{\scalebox{.8}{\day}}$};

\matrix [draw,above left, row sep=1mm, nodes={font=\scriptsize}] at (current bounding box.north east) {
    \node [circle, black, draw, label=right:Hotel] {H}; \\
    \node [circle, black, draw, label=right:Lunch] {L}; \\
};
\end{tikzpicture}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .