-1

I'd like to produce a diagram like this

enter image description here

Is it even possible in TikZ?

MWE of my attempt

%\documentclass{standalone}
%\usepackage{tikz}
\documentclass[10pt,border=3mm,tikz]{standalone}% better visibility

\begin{document} \begin{tikzpicture} % First Horizontal Line and Vertical Lines \draw [thick] (0,0) -- (5,0); \draw [thick] (0,-0.2) -- (0,0.2); \draw [thick] (5,-0.2) -- (5,0.2);

% Second Horizontal Line and Vertical Lines
\draw [thick] (6,0) -- (11,0);
\draw [thick] (6,-0.2) -- (6,0.2);
\draw [thick] (11,-0.2) -- (11,0.2);

\end{tikzpicture} \end{document}

result

MS-SPO
  • 11,519
  • 3
    What you try so far? Where you stuck? – Zarko Aug 30 '23 at 10:05
  • 2
    It is, and it's not very complicated. Have a look into the tutorial part of https://tikz.dev/tutorials-guidelines . – MS-SPO Aug 30 '23 at 10:12
  • how then? I have no idea how to use tikz – GregoryHouse Aug 30 '23 at 10:15
  • 1
    downvoting me isn't helping me to leatn – GregoryHouse Aug 30 '23 at 10:17
  • 4
    Please make a visible effort, people will be happy to help with the rest. – Ingmar Aug 30 '23 at 10:27
  • 1
    If MS-SPO's link was not to your liking, you can try TikZ CTAN page, which provides a minimal tutorial. – Miyase Aug 30 '23 at 10:27
  • 4
    About learning: a) read said tutorials, b) search here, c) try simple Tikz code yourself, d) search the web for the Tikz gallery (which also holds code). Just start, it's not that difficult. – MS-SPO Aug 30 '23 at 10:28
  • 4
    And remember this site is not a please do this for me service. I would just draw this one graph (?) paper, then define \coordinate for the relevant points, and lastly draw the lines and add the text. – daleif Aug 30 '23 at 10:35
  • 1
    @GregoryHouse Have a look at https://tex.stackexchange.com/questions/15779/materials-for-learning-tikz – samcarter_is_at_topanswers.xyz Aug 30 '23 at 10:45
  • If your solution to my problem is "just learn the language bro" then that's pretty sorry attempt at helping. I attached a MWE of an attempt – GregoryHouse Aug 30 '23 at 11:04
  • 7
    Please don‘t be angry, that‘s not the point. Both Latex and Tikz are complex enough, demanding for concrete code to give better answers. E.g. looking at your MWE it‘s obvious to me, so I give the hint, that you should have a look into the manual for arrows.meta . That‘s the way it works here, as the other answers, not comments, demonstrate, too. – MS-SPO Aug 30 '23 at 12:47

3 Answers3

8

Her is one just added ad hoc to the MWE

\documentclass[margin=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
    % First Horizontal Line and Vertical Lines
    \draw [thick] (0,0) coordinate (Zero) -- (5,0) coordinate (A);
    \draw [thick] (0,-0.2) node[below] {\strut$0$} -- (0,0.2);
    \draw [thick] (5,-0.2) node[below] {\strut$a$} -- (5,0.2);
% Second Horizontal Line and Vertical Lines
\draw [thick] (6,0) coordinate (B) -- (11,0) coordinate (C);
\draw [thick] (6,-0.2) node[below] {\strut$b$} -- (6,0.2);
\draw [thick] (11,-0.2) node[below] {\strut$C$} -- (11,0.2);

\coordinate (T0) at ($(Zero)+(0,-1)$);
\coordinate (Ta) at ($(A)+(0,-1)$);
\coordinate (Tb) at ($(B)+(0,-1)$);
\coordinate (Tc) at ($(C)+(0,-1)$);

\draw[<-] (T0) -- (Ta) node[pos=0.5,above] {\footnotesize $a\to0$};

\draw[->] (Tb) -- ($(Tb)!0.45!(Tc)$);
\draw[->] (Tc) -- ($(Tb)!0.55!(Tc)$);

\coordinate (D) at ($(Tb)!0.5!(Tc)$);

\node[above] at (D) {\footnotesize $b\to C$};

\coordinate (E) at ($(T0)!0.5!(Ta)+(0,-0.5)$);

\draw (E) -- ++(0,-1) node[below] {$0$};
\draw ($(D)+(0,-0.5)$) coordinate(D') -- ++(0,-1) coordinate(D'') node[below]  {$bC$} ;

\fill ($(D')!0.5!(D'')$) circle (2pt);


\end{tikzpicture} \end{document}

enter image description here

daleif
  • 54,450
5

It would be easier to first select initial coordinate(s) as a start point and then expand your diagram with the help of modifiers, rather than trying to calculate midpoints at for instance 0.2 let Tikz do the computing part

for example in the following code \coordinate (e) at ($(a)!0.5!(b)$); the 0.5 acts as the midpoint between coordinates a,b

 \documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{calc} 
\usetikzlibrary{angles,intersections,quotes}

\begin{document} \begin{tikzpicture} \draw [help lines] (0,0) grid (4,3);

\coordinate[label=-90:A] (a) at (1,0);
\coordinate (b) at (1,2);
\coordinate [label=-90:C](c) at (3,0);
\coordinate (d) at (3,2);

\draw[red, line width=1pt] (a) -- (b);
\draw[blue, line width=1pt] (c) -- (d); 
\coordinate (e) at ($(a)!0.5!(b)$);
\coordinate (f) at ($(c)!0.5!(d)$); 

\draw[green, line width=1pt, shorten <=0.5pt, shorten >=0.5pt] (e) -- (f);

\end{tikzpicture} \end{document}

enter image description here

js bibra
  • 21,280
3

Just to stimulate your programming skill, let's try some refactoring on your MWE:

  • both lines are the same, besides their coordinates
  • so let's perceive them as a route-object
  • which Tikz can provide via a \pic
  • which allows both replication of what you have already ...
  • and new options

It's a good idea, to refactor code more often than not ;-)

result

\documentclass[10pt,border=3mm,tikz]{standalone}% better visibility

\begin{document} \begin{tikzpicture}[ route/.pic={% ~~~ refactoring duplicate parts ~~~ \draw [thick] (0,0) -- (5,0); \draw [thick] (0,-0.2) -- (0,0.2); \draw [thick] (5,-0.2) -- (5,0.2); } ] % === Reproduction of what was already available ===== % ~~~ First Horizontal Line and Vertical Lines \pic at (0,0) {route};
% ~~~ Second Horizontal Line and Vertical Lines \pic at (6,0) {route};

% === New options ========
% ~~~ going crazy to demonstrate \pics ~~~
\pic[rotate=30,dotted]          at (45:4)   {route};    
\pic[rotate=-15,red,scale=0.5]  at (45:4)   {route};    

\end{tikzpicture} \end{document}

MS-SPO
  • 11,519