tikz add tag
5 years ago Diaa

I would like to prettify the following code by:

1- using relative dimensions instead of the absolute ones so that any any scaling or changing of the document font size would keep the layout intact.

2- making the wall left-aligned with the voltage terminals

P.S. Any further refinements are highly welcomed

1.png

Top Answer
5 years ago user 3.14159

I have basically no experience with circuitikz, so we will have to wait for Rmano’s input. As for the other parts,

  1. By setting x=3em,y=3em, say, you can achieve that things scale with the font size. To demonstrate this, I put the picture twice, and the second time after \Large. (Notice that some things do not change, such as the size of bricks and line widhts. You can change them if you want but generally this is not something that one does.) Presumably one can scale everything by invoking something like scale=2.5em/1cm,transform shape, but this might have downsides so I didn’t try.
  2. You were alreaady pretty good with relative positioning, the only real change is that I placed the wall first such that it aligns with the circuit, and then drew the damper (which I also modified to use em instead of pt and to accept an argument that can be used to place the label).
  3. You have a couple of vertical bars, which are now pics as well.
  4. There are things like Telmech which I kept my claws away from, this is more for squirrels. 🐿 😸

Screen Shot 2020-12-23 at 5.05.28 PM.png

Here is an addendum on patterns. This one scales, but only after using {Bricks[brick width=1.01em,brick height=1.01em]} in one code and {Bricks[brick width=1em,brick height=1em]} in the other because otherwise TikZ wants so be efficient and thinks: I already did the one with 1em so I can just recycle that one. The pattern offset is not fixed here (but in principle it could with more efforts, see here).

Screen Shot 2020-12-24 at 9.27.38 AM.png

5 years
Diaa replying to user 3.14159 — Monday, 28th Dec 2020 14:44

Please, have a look at my follow-up question here https://topanswers.xyz/tex?q=1581.

3 days
user 3.14159 replying to Diaa — Friday, 25th Dec 2020 20:48

Here is a very basic version. On the long run you probably need also something for curves.

Screen Shot 2020-12-25 at 12.48.11 PM.png

44 minutes
Diaa replying to user 3.14159 — Friday, 25th Dec 2020 20:04

if you can have a key or option in the to [ ] command to draw a parallel arrow (with the ability to pass the typical style options of any regular arrow)), it would be awesome

Diaa replying to user 3.14159 — Friday, 25th Dec 2020 19:56

I did it this way, but I am sure the code can be prettified and simplified a lot

blob

user 3.14159 replying to Diaa — Friday, 25th Dec 2020 19:48

Yes, that explains a lot. So circuitikz is an organically grown package and the elements in there may or may not be precisely what one wants. (It isn’t too difficult to add an arrow parallel to a path via a pic, say, or a style that adds a pic…)

31 minutes
Diaa — Friday, 25th Dec 2020 19:17

Seemingly, it is better to avoid using the flow arrow and replace it a labelled arrow.

Diaa — Friday, 25th Dec 2020 19:10

@marmot, re: your answer, FYI, I received this response from Rmano on tex.se:

“The flow arrow is not a TikZ arrow, it is a shape, so you can’t scale its parts differently. You can use the “advanced flows” to build your own arrow, see the manual, section 4.8, around pag 158, and tex.stackexchange.com/a/549354/38080 See also https://tex.stackexchange.com/q/574576/2288 for an example application”

3 hours
user 3.14159 replying to Diaa — Friday, 25th Dec 2020 16:09

During hibernation season there is no real distinction between day and night for marmots. 😸

5 hours
Diaa replying to user 3.14159 — Friday, 25th Dec 2020 11:35

You are right, both worked but without effect on the flow arrow size since the flow arrow is a node not real arrow as quoted from pgfcircflow.tex.
I think that’s the end of my journey unless Rmano shows up.

Have a nice night (I guess 😃)

15 minutes
user 3.14159 replying to Diaa — Friday, 25th Dec 2020 11:20

In my case it is defined but I get an arithmetic overflow error. This is because the “natural” scale here is not 1 but 16. (Why 16? I do not know.) Also I have no intuition for this key but to[short,f=$i_a$,current arrow scale=16/\myscale] or to[short,f=$i_a$,current arrow scale=16*\myscale] do not cause errors on my machine. Please also note that in principle arrow heads should scale with the line width. And you’re welcome! 😸

22 minutes
Diaa replying to user 3.14159 — Friday, 25th Dec 2020 10:58

May I know why does this to[short, f=$i_a$, current arrow scale = \myscale] fail?
Isn’t \myscale globally accessed?

10 minutes
Diaa replying to user 3.14159 — Friday, 25th Dec 2020 10:47

It is really enjoyable to TeXting with you 😄
My problem was solved a couple of codes before but your knowledge is tempting to ask for more.
My code goes from good to better.
Thanks for the help.

19 minutes
user 3.14159 replying to Diaa — Friday, 25th Dec 2020 10:28

I may be able to partially understand this code but I am not sure. Seems like you want to rescale \pgf@circ@Rlen. So one has to find the code that sets it, which seems to be pgfcirc.defines.tex, manipulate it, and see if this helps. However, I think this is a very dangerous game which may result in more trouble than benefits. So, unless one wants to read the manual and source code carefully, the best bet would be to ask an expert like Rmano.

user 3.14159 replying to Diaa — Friday, 25th Dec 2020 10:19

This problem can be repaired with

Why? Because thick and friends are defined with an explicit line width in point. (I just copied these definitions from tikz.code.tex and multiplied them by \myscale.) That means that, if you want to go this route, there may be many other things that also have explicit fixed dimensions in their definitions. And of course it is not sufficient to just scan tikz.code.tex for pt.

2 hours
Diaa replying to user 3.14159 — Friday, 25th Dec 2020 08:33

This code is so beautiful but it needs to accordingly scale the line width (and its friends thick, very thick, etc) to NOT have this weird output when using \tiny

https://pastebin.com/ih9jn9WH

blob

Diaa replying to user 3.14159 — Friday, 25th Dec 2020 08:28

I think the node of the flow arrow can be hacked or replaced by a scalable one to go in sync with the font size.

Diaa replying to user 3.14159 — Friday, 25th Dec 2020 08:25

I found this in the file pgfcircflow.tex of circuitikz package but it looks like sorcery to me 😄 :

6 hours
user 3.14159 replying to Diaa — Friday, 25th Dec 2020 02:09

An arguably better way could be the following. But I struggle to find the right key to scale the arrows. Since there is a key named current arrow scale, there should be a way, but I am not sure what “current” means in this context, contemporary or flow of electric charge.

Screen Shot 2020-12-24 at 6.09.08 PM.png

41 minutes
user 3.14159 — Friday, 25th Dec 2020 01:29

This is IMHO a tiny bit better but still far from good.

10 minutes
user 3.14159 replying to Diaa — Friday, 25th Dec 2020 01:19

I am afraid that I do not like the answer. It “over transforms things”, i.e. it makes fonts tiny and transforms a second time. (I think it is also unnecessarily complicated.) Please look at

Screen Shot 2020-12-24 at 5.16.25 PM.png

As you can see, it effectively squares the transformation, i.e. instead of 1/2, say, you get 1/4. This is because of how transform shape works. And this why I thought it would be good to as Rmano. There should be something that just scales the length of the circuit elements without scaling the texts.

2 hours
Diaa — Thursday, 24th Dec 2020 23:45

@marmot, re: your answer, Is it possible to employ this answer I got https://tex.stackexchange.com/a/576289/2288 with your beautiful codes to have a complete circuit with bricks pattern that can be scaled by either font size or adjustbox? Or am I talking about something tedious, fragile and not worth the effort?

5 hours
user 3.14159 replying to Diaa — Thursday, 24th Dec 2020 18:58

Well, sure. There is a chance that one can add a force recompile option here, ironically the problem is very analogous to externalize: if you use em units in a picture, say, and the font size changes, externalize “thinks” : “Well, this input I already compiled in a previous run, so nothing to do.”. Similarly for patterns, if you had used one with em units TikZ thinks that you are using an old one and does not recalibrate it. (At least a brute force solution is possible, I think.)

20 minutes
Diaa replying to user 3.14159 — Thursday, 24th Dec 2020 18:38

Your great pattern addendum should be highlighted in a new answer.
Would you like to move it to a new Q/A?

an hour
user 3.14159 replying to Diaa — Thursday, 24th Dec 2020 17:22

This one scales the patterns. (One has to use tricks like 1.01em so that TikZ does not think it has done this already an just keeps what it has had before. In some way this is a bug.) Note, however, that the pattern offset is not synchronized. (Can be done, even more efforts.) (I had to move the code to the answer because it would not fit in the comments.)

24 minutes
user 3.14159 replying to Diaa — Thursday, 24th Dec 2020 16:58

“Ordinary” patterns generally do not scale, I think, but this could depend on how they were defined. One can design some with patterns.meta which should.

15 minutes
Diaa — Thursday, 24th Dec 2020 16:43

@marmot, re: your answer, I have another question if you don’t mind:

why the bricks pattern here doesn’t scale down? I mean the bricks should be scaled not zoomed in

blob

Diaa replying to user 3.14159 — Thursday, 24th Dec 2020 16:40

My eyes can’t feel the difference.

2 hours
user 3.14159 replying to Diaa — Thursday, 24th Dec 2020 14:24

Not really. scale={3em/1cm},transform shape works for the circuitikz nodes but not for everything, it seems.

4 hours
Diaa — Thursday, 24th Dec 2020 10:16

@marmot, re: your answer, In case you have any idea, do you know how to make the line thickness of the resistor and inductance the same as that of connecting wire?

9 hours
user 3.14159 replying to Diaa — Thursday, 24th Dec 2020 01:07

Yes, good point. Tried to fix it.

Diaa — Thursday, 24th Dec 2020 01:01

@marmot, re: your answer, many thanks for your beautiful answer. I am currently away from PC but there is some minor visual tweak: the gears should be apart from each other a bit to indicate they are meshing gears not a belt around pulleys as I have in my question image.

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.