3

I've never used TikZ and certainly not for drawing graphs. Based on your experience with TikZ, would you say I shouldn't try to draw the graph below with it?

Look at the combinations of lines consisting of an arrowed line, a dotted line and a line ending with a black dot (e.g. there's one between A1 and Q1). I assume that I could draw such by drawing 3 different lines, but can I keep them aligned so that they would appear as a straight and continuous path? Or will there be visible joints?

I'd prefer simplicity, so it might be easiest to somehow group lines together, but is that even possible?

1
  • 2
    It would be helpful to show us what you have tried. Posting a minimal working example that indicates what you are trying to do makes it easier for people to understand what you want. It also makes it easier for people to help you, since they have some code to start from, and much more likely that some one will try to help you.
    – user30471
    Oct 24, 2016 at 21:43

2 Answers 2

9

If you are going to be making many of these complex arrows (as you seem to be doing) you can also use path replacing to automate your arrow style:

\documentclass[tikz, border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, arrows, decorations.pathreplacing}
\tikzset{
  myarrow/.style={
    decoration={show path construction, lineto code={
      \path (\tikzinputsegmentfirst) to coordinate[pos=.2] (mid1) coordinate[pos=.75] (mid2) (\tikzinputsegmentlast);
      \draw[-stealth] (\tikzinputsegmentfirst) to (mid1);
      \draw[dashed, shorten <=3pt] (mid1) to (mid2);
      \draw[-*, shorten >=2pt] (mid2) to (\tikzinputsegmentlast);
      }},
    decorate
    },
  label1/.style={pos=.2, font=\footnotesize},
  label2/.style={pos=.9, font=\tiny}
  }

\begin{document}
\begin{tikzpicture}
\node (C) at (0,0)  [draw=red, circle, fill=gray!50]{C} ;
\node (X) at (1,4)  [draw=black, circle]{X} ;
\node (Y) at (25:4)  [draw=black, circle]{Y} ;
\draw[myarrow] (C) to node[label1, right] {0,7} node[label2, right] {0,65} (X);
\draw[myarrow] (C) to node[label1, below] {0,4} node[label2, below] {0,35} (Y);
\end{tikzpicture}
\end{document}

funky arrows

3
  • Reusable styles. Nice, but what does "to coordinate[pos=.2] (mid1)" mean? Oct 25, 2016 at 4:11
  • It finds the point 2/10 of the way from (\tikzinputsegmentfirst) (the starting point of the styled segment) to (\tikzinputsegmentlast) (the endpoint of the styled segment) and labels it (mid1) so that that coordinate can be used later.
    – Emma
    Oct 25, 2016 at 4:14
  • +1! +4 if possible... At a first glance I thought I'd see a huge code as a solution, great use of TikZ capabilieties!! Oct 25, 2016 at 8:05
3

The following has a 2cm arrow, a one cm line ending in a circle in a straight line between two nodes, with the remainder drawn with dots.

enter image description here

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepgflibrary{arrows.meta}

\begin{document}
\begin{tikzpicture}
\node (C) at (0,0)  [draw=red,circle, fill=gray!50, align=center, text width=30pt,line width=2pt,outer sep = 2pt]{C} ;
\node (X) at (3,7)  [draw=black,circle,  align=center, text width=20pt,line width=2pt,outer sep = 2pt]{X} ;
\draw [->] (C) --  ($(C)!2cm!(X)$);
\draw [dotted] ($(C)!2.1cm!(X)$) -- ($(X)!2.1cm!(C)$);
\draw [-{Circle}] ($(X)!2cm!(C)$) --  (X);
\end{tikzpicture}
\end{document}
7
  • 2
    \usetikzlibrary{calc,arrows.meta}?
    – cfr
    Oct 25, 2016 at 0:39
  • Looks promising.. first there would be setting of node positions and then drawing of a line having 3 different parts between them. I guess I understand what "($(C)!2.1cm!(X)$)" means, but what kind of purpose do those exclamation marks have? Manual seems like reading it could be exhausting. Oct 25, 2016 at 3:50
  • @cfr not sure what the question is (this is first tikzpicture I've written:-) as far as I understand I need calc for the ! syntax and arrows.meta for -{Circle} Oct 25, 2016 at 7:13
  • 1
    @DavidCarlisle, this is what you get for not using picture... I think what @cfr means is that you can load both libraries in just one call, like packages... Oct 25, 2016 at 7:59
  • ^^ What @GuilhermeZ.Santos said. But more than that, it seemed confusing to use \usetikzlibrary for one and \usepgflibrary for the other and I wasn't sure why you'd done that. If you want to load them separately, you can just use \usetikzlibrary twice. I guess I'd use the TikZ interface where possible, when loading TikZ, for much the same reasons I'd use LaTeX syntax when possible, when using LaTeX, at least when it is no more clunky or awkward. (I draw the line at doing this for \ifs.)
    – cfr
    Oct 25, 2016 at 11:43

You must log in to answer this question.

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