tikz add tag
2 months ago J...S

I am trying to make a figure like this with tikz:

picd.png

So I did this:

This gives this picture:

pic.png

I had meant for the arrows go through the ‘dots’ used to denote the merging and splitting of arrow. Without there being a break.

Also, I wanted the labels and a, b, etc above some of the arrows.

Along with the arrow head being in the middle of the arrow instead of being at the end.

Any tips as to how this may be achieved?

Thanks.

Top Answer
2 months ago Qrr

This really feels very close to a circuit – and I’m sure circuitikz has a way to provide a rectangular shape with multiple inputs and outputs without having to misuse a built-in element – but in case you want a plain-ish TikZ solution, I’ll add one with my tools, i.e. the ones from my tikz-ext package – so much for plain.

Here, I’m using ext.paths.ortho and its ext/horizontal vertical horizontal key for the -|- path operation and ext.arrows-plus for adding arrow tips along path operation. Since you don’t have any curved lines the ext/arrow pic is enough.

For a rectangle with multiple, evenly spaced inputs and output anchors, I’m using a slight alteration to the \pgfDeclareGenericAnchorsLinear macro from an answer on the other site. There’s also a similar, less automatic version available.

Basically, with

three generic anchors

  • west 1/3,
  • west 2/3 and
  • west 3/3

are defined that are placed according to the PGFMath function funcHalfPadding between a shape’s north west and south east anchors.

Generic means that these are always available for every node and every shape (at least in the scope where this key/macro is used – which is the whole document in this case).


Both the Triangle arrow tip as well as the Circle are placed as arrow tips, the default settings makes it so that they are centered-ish along the line and not placed with their tip at the center which visually looks too offset. Technically, you don’t need to use arrow tips here, you could just place a node, say node[circle, fill]{} for the circle, or a custom pic along a path. Unfortunately, the manual’s example is a seagull which isn’t very inspiring.

You could just draw your triangle yourself:

and wouldn’t be constrained to the available arrow tips.

There can also be made an argument for the circle to be a node that is used to connect if it is a vertex in the graph sense and not just a annotation to the connection like the triangles. (This solution also draws the parts of the connections and some annotations twice or thrice which can be avoided by using the circular node as a vertex.)


If you find yourself, often needing to use these arrow tips on the -|- paths then you might want to define every

for all variations of these connections.

Code

Output

top8113-1.png

Answer #2
2 months ago Skillmon

I’d use circuitikz for this drawing, it already comes with easy to place arrows in the middle of a path (short,i>=label), easy to place line joins (-* or *-).

foo.png

2 months
Qrr replying to Skillmon — Monday, 28th Apr 2025 15:56

I’m just as guilty because I wrote the comment before I even properly looked at how your comment related to the question.

8 hours
J...S — Monday, 28th Apr 2025 07:35

Thanks!

5 days
Skillmon — Tuesday, 22nd Apr 2025 19:59

Should’ve read your answer first 😛

Skillmon replying to Qrr — Tuesday, 22nd Apr 2025 19:55

I suspect this is with the help of your TikZ extensions? It’s really nice (and should, imho, really be a standard feature of TikZ).

18 hours
Qrr — Tuesday, 22nd Apr 2025 02:01

Of course, if you just want to add an arrow tip in the middle of a straight line, you would just need \draw[-Triangle] (0,0) -- pic{ext/arrow} (1,1); (the pic picks up the paths arrow tip) – or the same with a key that places an edge node as above in a to.

Qrr replying to Skillmon — Tuesday, 22nd Apr 2025 01:55
4 hours
Skillmon replying to Rmano — Monday, 21st Apr 2025 21:37

I think what TikZ is really missing is the ability to specify arrows in to-paths. That’s such a useful feature. It works only in edges and they don’t get joined to the rest of the path.

2 hours
Rmano — Monday, 21st Apr 2025 19:41

@Skillmon Well, really this one is more general 😉 (and I answered a very similar one here: https://topanswers.xyz/tex?q=8102#a7727)

22 minutes
Skillmon replying to Rmano — Monday, 21st Apr 2025 19:19

I’m a bit surprised you didn’t suggest circuitikz for this… 😃

15 minutes
Rmano — Monday, 21st Apr 2025 19:04

You are sending arrows to out-join which is a node and so it has a size. When you want to mark a point, use \coordinate. Anyway, in this case if you add the definition of out-node circle, inner sep=1pt, fill=black (and remove the circle drawing) the arrows will touch the node’s border which, in this case , is what (I think) you need.

4 hours
J...S — Monday, 21st Apr 2025 14:59

I suppose the title is indeed too generic.

J...S — Monday, 21st Apr 2025 14:58

My questions were about adding labels to “|-” arrows and drawing line through a dot/circle.
Are these what you meant?

I figured posting two different questions would be frowned upon since there would be some duplication.
Since both are for the same figure.

2 hours
samcarter — Monday, 21st Apr 2025 12:39

Please only ask one question per post. This will help other users with the same problem, to find the solutions they are looking for. Please also choose question titles which describe the problem.

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.