3

Why does using scale on a node using the scope environment cause its coordinate to scale, but when I use scale on a node using its options, only the contents are scaled?

In the following code, the first P-node's coordinate is scaled by a factor of 2 --- the expected result.

However, the second P-node's coordinate is not scaled, and instead the contents are scaled.

I didn't use \pgflowlevelsynccm, so this is unexpected for me.

\documentclass[tikz, border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}
\begin{scope}[scale=2]
    \node at (1,0) {P};
\end{scope}
\node[scale=2] at  (1,0) {P};
\end{tikzpicture}
\end{document}

output

4
  • To my understanding, both Ps should be the same. Commented Feb 23 at 14:51
  • 3
    What you've described is the behaviour as laid out in the TikZ/PGF manual. Node contents are not affected by transformations by default, to override this you either need to specify the transformation on the node itself - as in your second example - or use the option transform shape. Transformations on the scope apply to all coordinates within that scope, but options on the node are for the node, not its location, so the scale option in your first only applies to the node itself and not to its location. If you want both, try \path[scale=2] node[scale=2] at (0,1) {P}; Commented Feb 23 at 14:55
  • @AndrewStacey Interesting. I was under the impression that I'd need to use transform shape or \pgflowlevelsynccm to scale the node contents, and that the (node) option scale would otherwise only affect the node's coordinate. Thank you for clarifying this for me. Would you be interested in posting an answer? Commented Feb 23 at 15:00
  • 1

1 Answer 1

4

Nodes are not scaled by default, so to scale a node you need to explicitly say that you want the node scaled. This is accomplished either by using a scale=X option in the node options, or by using the transform shape option to apply the current scaling to a node.

Transformations on a scope apply to their coordinates, as do options passed directly to the \path command.

The command \node[options] ... expands to \path node[options] so the options are only applied to the node and not to the path it is defined on.

So there are multiple ways that a node and a transformation can be specified, and the effects can be a little confusing. Here's an attempt at summarising:

\node[scale=2] at (0,1) {P}; % contents, not coordinate
\path[scale=2] node at (0,1) {P}; % coordinate, not contents
\path[scale=2] node[scale=2] at (0,1) {P}; % both
\path[scale=2] node[transform shape] at (0,1) {P}; both

Using a scope environment works the same way as \path[...] node.

Note that this also applies to other transformations, there's nothing special about scaling here.

Here's some code to illustrate this:

\documentclass[tikz, border=3.14mm]{standalone}
%\url{https://tex.stackexchange.com/q/737730/86}
\begin{document}
\begin{tikzpicture}
\draw (-1,-1) grid (3,3);
\fill[red] (0,0) circle[radius=2pt];
\begin{scope}[scale=2]
    \node[red] at (1,0) {A}; % scale coordinate, not node
    \node[transform shape,green] at (1,0) {B}; % scale coordinate and node
\end{scope}
\node[scale=2,blue] at  (1,0) {C}; % scale node, not coordinate
\path[scale=2,orange] node at (1,0) {D}; % scale coordinate, not node
\path[scale=2,magenta] node[transform shape] at (1,0) {E}; % scale coordinate and node
\end{tikzpicture}
\end{document}

The result of the above code, showing how the transformations apply to nodes and coordinates

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.