# How to scale a Tikz pic, when it should be positioned absolutely

I have prepared a MWE, where I have tried different approaches, how a tikz pic can be scaled AND positioned absolute:

 \documentclass{standalone}
\usepackage{lmodern}
\RequirePackage{tikz}
\RequirePackage{pgfplots}
\pgfplotsset{compat=1.11}

\tikzset{
Test/.pic = {
-- ++ (0, 2cm) arc[start angle=0, end angle=180, x radius=5cm, y radius=2.5cm]
-- cycle;
\path[draw=none, postaction={decorate},decoration={text along path,
text={|\fontsize{16mm}{19mm}\bfseries\color{red}|text},
\node at (5cm, 1cm) {\fontsize{16mm}{19mm}TEXT};
}

}
\begin{document}

\begin{tikzpicture}[every node/.append style={transform shape}]
\draw (-1cm, -1cm) rectangle (11cm, 9cm);
\pic[] at (0, 3cm) {Test};
\pic[scale=0.25] at (8cm, 0) {Test}; %Scales all but the text along the path
\begin{pgflowlevelscope}{\pgftransformscale{0.25}}\pic at (4*4cm, 0) {Test};\end{pgflowlevelscope} %Scales and positions right, if I consider the scale factor as an additional multiplication by 4.
\begin{pgflowlevelscope}{\pgftransformscale{0.25}}\pic{Test};\end{pgflowlevelscope} %Scales but no way to set the position
\end{tikzpicture}

\end{document}


I want to scale my pics according to the \pic[scale=0.5] property or something similar. So I have different approaches:

1. \pic[] at (0, 3cm) {Test};': This is the reference approach, where no scaling is needed. (It can be seen in the image below as the top variant)

2. \pic[scale=0.25] at (8cm, 0) {Test};: As you can see at the image below (variant on the bottom right), the problem with the code is that the \pic[scale=0.5] ... variant scales everything correct, but not the text which is defined as text along path.

3. \begin{pgflowlevelscope}{\pgftransformscale{0.25}}\pic at (4*4cm, 0) {Test};\end{pgflowlevelscope}: This is the variant, which scales everything correct, but the positioning of the \pic is much harder. Because here I have to keep in mind, that in the future the scaling by factor 1/4 is applied, and therefore the coordinates must be multiplied by 4, to position it correctly.

What I want to know, is if there is another approach of scaling which does meet my requirements. (they are scale by a certain factor and also direct absolute positioning without keeping in mind the scaling factor at the absolute position calcuation step).

• Postioning problem can be solved with Claudio's answer to Anchoring TikZ pics – Ignasi Apr 25 '18 at 17:57
• I'm not really clear what you are looking for. If you want to scale shapes & positions & text, use \pic[scale=0.25, transform shape] at (8cm,0) {Test};. If you want to scale shapes & positions but not text, here's a dumb solution: \path[scale=0.25] pic[scale=0.25] at (8cm, 0) {Test};. – wklchris Apr 25 '18 at 23:17
• Sorry, for beeing unclear, I have updated the question with more details. I hope, that now it is clear. – byteunit Apr 26 '18 at 9:20
• @byteunit Alright, I think Kypm's answer is what you want. Also, please try your best to make it easy for others to locate where the core problem is (e.g. removing irrelevant libraries and minor commands). – wklchris Apr 26 '18 at 23:14

When I started to write the answer to this question I thought that just putting transform canvas inside the pic will be ok. But then I realized that even inside the pic, the canvas transform scale origin is by default the canvas origin (and not the pic's one). So a simple transform canvas = {scale = ...} displace the entire pic. To overcome this I transform the canvas by scaling around the pic's origin.

\documentclass[tikz]{standalone}
\usepackage{lmodern}
\usetikzlibrary{decorations.text}

\tikzset{
Test/.pic = {
\path (0,0) coordinate (O);
\begin{scope}[transform canvas = {scale around={#1:(O)}}]
-- ++ (0, 2cm) arc[start angle=0, end angle=180, x radius=5cm, y radius=2.5cm]
-- cycle;
\path[draw=none, postaction={decorate},
decoration={
text along path,
text={|\fontsize{16mm}{19mm}\bfseries\color{red}|text},
text align=center}
\node[transform shape] at (5cm, 1cm) {TEXT};
\end{scope}
},
pics/Test/.default = 1,
}
\begin{document}
\begin{tikzpicture}
\filldraw[help lines,blue!35] (-1cm, -1cm) grid (11cm, 9cm) (0,0) circle(2pt);
\pic at (0, 3) {Test};
\pic at (0, 2) {Test=.5};
\pic at (0, 1) {Test=.25};
\end{tikzpicture}
\end{document}


• Really learn something from your impressive MWE. Moreover, library calc is not used thus it can also be removed. And font=\fontsize{16mm}{19mm} doesn't make much sense unless append \selectfont to it (though OP also wrote it in an invalid way). – wklchris Apr 26 '18 at 23:03
• @wklchris thanks for your very useful comment. The calc is a scrap of my unsuccessful attempts, and you are absolutely right about font=\fontsize{16mm}{19mm} that \selectfont is needed, but the first |\fontsize{16mm}{19mm}| , inside the text decoration, is ok because \selectfont` is automatically called. I corrected my answer. – Kpym Apr 27 '18 at 5:07