0

Is it possible to set independently a shape scale and a label scale, individually per node, without setting the shape's minimum size or setting sizes globally? For some shapes, there is a similar dependency with rotation, because shape border rotate does not work for them.

There seems to be some auto-fit enabled all the time, because even using labels like `{\tiny label-text}' affects the shape's scale.

For example, I would like to use logic gate symbols with size differences exactly as in the library, e.g. the NAND gate being larger than the NOT gate. I do not want any of these symbols to follow the number of characters in its label or the label's font size. Also, different symbold may need a different minimum size, so I would need to tune that to each symbol individually and the rotation problem would still be unresolved.

On the opposite, if I want to make one of two circle symbols larger, I would still want them both have labels of the same font size.

Source which shows the dependency between scale and label size:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{lmodern}
\usetikzlibrary{positioning, shapes, shapes.gates.logic.US, shadows, arrows}
\usepackage{anyfontsize}

\begin{document}
\thispagestyle{empty}
\begin{tikzpicture}[
    every node/.style={line width=2mm, draw}
    ]
    \node (input1) [circle, thick, font=\fontsize{10}{0}\selectfont] at (0,0) {x};
    \node (input2) [circle, thick, font=\fontsize{10}{0}\selectfont, below=5mm of input1] {\Large xyz};
    \node (input3) [circle, font=\fontsize{20}{0}\selectfont, below=5mm of input2] {x};
    \node (input4) [not gate US, thick, scale=1.5, below=5mm of input3] {scale 2};
    \node (input5) [not gate US, thick, scale=3, below=8mm of input4] {scale 3};
\end{tikzpicture}
\end{document}

gives what is in the left column. An approximate desired output is in the right column:

enter image description here

10
  • can you illustrate your question please?
    – anis
    Jun 21, 2023 at 15:41
  • @anis I added an example.
    – scriptfoo
    Jun 21, 2023 at 16:01
  • so you want the size of the node to be independent of the text? I am not getting the question here. can you provide an example of what you want
    – anis
    Jun 21, 2023 at 16:20
  • a node per definition must be able to contain its content. So making the content bigger will inevitably result in a bigger shape to surround it. This is why there is a minimum size option but no maximum. There are way to obtain shapes that are completely independent of the content. Do you want that?
    – anis
    Jun 21, 2023 at 16:24
  • 1
    Every text you put in a node is surrounded by the length stored in /pgf/inner xsep and /pgf/inner ysep (or the maximum of that) – at least for the shapes provided by PGF/TikZ. By default, this is 0.3333em, thus this scales with the font size. However: The sizes of font are installed too late for it to be in effect when 0.3333em gets evaluated. You will need to use node font for that. (That's why the really big X of your last node has the same space around it as the normal one.) Jun 21, 2023 at 17:03

1 Answer 1

1

Most node shape definitions, certainly the ones provides PGF/TikZ, use the values of /pgf/inner xsep and /pgf/inner ysep as padding between the text and the node's own path in some form.

For the rectangle shape the inner xsep is added to the left and right, the inner ysep is added above and below the text.

By default, both values are 0.3333em, i.e. a fontsize dependent length. However, neither the font of the font key nor any fontsizes you use inside of the node text is active when the values are evaluated.

For this, the node font key can be used as in the code below or the font size change needs to be done before the node – either inside the path or before the path, though the latter will be still active after the path and both will affect any distances in the units ex or em, of course.


Notable exception is the coordinate shape (yes, that's also a node) but it does neither have a text part nor a path.

Code

\documentclass[tikz]{standalone}
\usepackage{lmodern}
\usepackage{anyfontsize}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[nodes={line width=2mm, draw, thick}]
\node (input1)                                         {x};
\node (input2) [node font=\Large,     below=of input1] {x};
\node (input3) [node font=\fontsize{180}{0}\selectfont,
                                      below=of input2] {x};
\end{tikzpicture}
\begin{tikzpicture}[nodes={line width=2mm, draw, thick}]
                             \node (input1)                   {x};
\Large                       \node (input2) [below=of input1] {x};
\fontsize{180}{0}\selectfont \node (input3) [below=of input2] {x};
\end{tikzpicture}
\begin{tikzpicture}[nodes={line width=2mm, draw, thick}]
                       \node (input1)                   {x};
\path \pgfextra{\Large} node (input2) [below=of input1] {x};
\path[/utils/exec=\fontsize{180}{0}\selectfont]
                        node (input3) [below=of input2] {x};
\end{tikzpicture}
\end{document}

Output

enter image description here

6
  • The circuit shapes might not consider the inner seps but only use /pgf/minimum width and /pgf/minimum height but they are also rarely used with text. Jun 21, 2023 at 20:34
  • In the output, symbol size still seems to roughly follow label size. That's now what I want. I reformulated the question to make it clearer.
    – scriptfoo
    Jun 21, 2023 at 21:57
  • @scriptfoo Yes, that's mainly the point of a node. Otherwise the size of a node is only controlled by the minimum width/size. What you can try is to scale the node itself but put the text in a \resizebox with the inverse scaling so that they cancel out and the text appears normal again. Jun 21, 2023 at 22:43
  • 1
    @scriptfoo You can also just place a node without text and then another with text but without any drawing of them in the same place if you want to decouple those two. I will take another look at your Q tomorrow. Jun 21, 2023 at 22:44
  • If it were possible to make readable macros, this would be an interesting solution. I don't need much flexibility here, just a logic symbol with a simple label in the center.
    – scriptfoo
    Jun 22, 2023 at 8:10

You must log in to answer this question.

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