4

I have a basic pic ("brick") that I rotate/flip/shift within other pics (e.g. "wall"). These pics ("wall") then get drawn in my tikzpicture, possibly themselves rotated/flipped/shifted.

The brick pic renders fine, the wall pic renders fine, but I cannot seem to scale or rotate the wall pic (I can shift it with xshift and yshift though).

I have followed this nested pics question which was resolved by replacing the \draw in the wall pic with \path. However, that question did not deal with rotations and scalings.

How can I rotate/scale my wall pic? At the moment my ugly workaround is to put the tikz for brick into a macro which I call in the wall code (as opposed to drawing the brick pic), but this does not seem to be the tikz way.

enter image description here

In the above, shifting the wall works (blue), but the x-mirrored wall (red) does not mirror. (Obviously not intended to be bricks and walls, unless I am constructionally challenged).

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\tikzset{
  brick/.pic={
    \draw (0, 0) -- (1, 3) -- (2, 1.5) -- cycle;
  },
  wall/.pic={
    \path pic {brick};
    \path pic [xshift=1cm,yshift=2cm,scale=0.5] {brick};
  }
}
\begin{tikzpicture}
  \draw (-3, -1) rectangle (3, 4);% bounding box
  \node at (0, 0) {.}; % origin

  \draw pic {wall};
  \path pic [red,ultra thin,xscale=-1] {wall};
  % shifting works
  \path pic [blue,ultra thin,xshift=1cm] {wall};
\end{tikzpicture}
\end{document}
  • I had such an issue before, and it was recommended to use pics (see comments below post). It turned out that mirroring doesn't work with pics. – gernot Dec 9 '16 at 14:26
  • 2
    Need transform shape. – Symbol 1 Dec 10 '16 at 16:32
  • @Symbol1 thanks so much! I put transform shape into the tikzpiture \path pic, and it worked. (I think I'll every node/.style={transform shape}). If you would like to post it as an answer I can mark the question as closed. Otherwise I'll post your answer as an answer (for posterity) tomorrow some time. – mathematical.coffee Dec 11 '16 at 11:49
1

This question is somewhat related to Why does the pic option get passed through to the entire object?

Drawing a pic is essentially drawing a node, so everything you know about node applies. For example: a node is not rotated/scaled but only shifted. However a node is rotated/scaled if you said transform shape. And this is indeed the answer to your question.

To clarify:

% does not work
\path pic [red,ultra thin,xscale=-1] {wall};
% works
\path pic [red,ultra thin,xscale=-1,transform shape] {wall};

To make things easier, one could add [every node/.style=transform shape] into the tikzpicture options or similar.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.