4

When a node is scaled with transform shape and scale, the anchor border no longer lines up with the background path. At first I thought this was a bug in my own code, but I now realize that "standard" shapes (such as rectangle) do this, too. Here is a minimal example:

\documentclass[tikz]{standalone} \begin{document} \begin{tikzpicture}[transform shape] \node [name=r,draw,rectangle,minimum height=2cm,minimum width=3cm, line width=0.25cm] {Rectangle}; \draw [shift=(r.0),green] plot [mark=x] coordinates {(0,0)}; \draw [shift=(r.north),green] plot [mark=x] coordinates {(0,0)}; \node [name=s,draw,scale=2,color=gray,rectangle,minimum height=2cm,minimum width=3cm, line width=0.25cm] {Rectangle}; \draw [shift=(s.0),cyan] plot [mark=x] coordinates {(0,0)}; \draw [shift=(s.north),cyan] plot [mark=x] coordinates {(0,0)}; \end{tikzpicture} \end{document} 

Image showing problem

I expected the blue crosses to be on the border of the gray rectangle, as the green ones are on the black one.

How do I get around this? I think I know why it happens (it's because the lines do not scale but the outer x/y separations do, I think), but I'm not certain how to work around it. In this particular case, I'm trying to draw a picture that's exactly \textwidth wide in a document that shows points on the anchor border of a node, similar to those that appear in the PGF manual. It works fine if there is no scaling, but if I scale the node larger or smaller, those anchors do not lie in the right place.

I tried transform canvas={scale=2}, but that put the node in the upper left corner and cut most of it off.

6
  • 1
    specify the outer sep explicitly e.g. outer sep=0.0625cm in this case (which is half what you want, so ends up correct). or create a shape with anchors on the border of the undrawn shape and adjust appropriately when placing further elements. Commented Jun 18 at 21:50
  • tex.stackexchange.com/questions/385815/… is a different question, but your question reminds me of the one I asked there. if you create anchors which discount any drawn line, you do at least know where you are, regardless of scaling etc. Commented Jun 18 at 21:56
  • The problem here is that everything that belongs to the shape is scaled (including outer sep), but then you set the line width. Strangely indeed, outer sep=0.5\pgflinewidth even specified after setting the line width does not help. Commented Jun 19 at 6:45
  • @JasperHabicht Setting line width=0.25cm in the optional argument to the tikzpicture environment does not change this behavior, either (though doing so makes the marks much thicker). Commented Jun 19 at 13:43
  • github.com/pgf-tikz/pgf/issues/1393#issue-3165060132 Commented Jun 21 at 12:39

0

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.