2

I drew a tikz picture, but after scaling the picture using \begin{tikzpicture}[scale=200/(\hsize-24)], everything inside the scope of transform canvas disappear. could someone explain this?

This the original tikz picture

\documentclass[tikz, border=12]{standalone}

\usepackage{tikz, tkz-euclide, pgfmath, pstricks}
\usetikzlibrary{intersections, decorations.markings, angles,
quotes, calc, arrows, arrows.meta}
\usetkzobj{all}
%
\definecolor{blue}{RGB}{0,51,255}
\definecolor{green}{RGB}{0,153,0}
\definecolor{blue1}{RGB}{174,214,241}
\definecolor{blue}{RGB}{161,207,223}
\definecolor{yellow}{RGB}{255,220,0}
\colorlet{dcolor}{blue}
%
\begin{document}
\begin{tikzpicture}
\pgfgettransformentries{\mya}{\myb}{\myc}{\myd}{\mys}{\myt}
\pgfmathsetmacro{\preserve}{1/\mya}
\begin{scope}[>={Stealth[scale=1.2]} , thick,rotate=0 ] 

%
\newcommand\height{10}
%
\newcommand\Ac{-4}
%
\newcommand\Bc{27.46586300953384}
%
\pgfmathsetmacro{\distance}{\Bc+\Ac}
\draw (0,-0.2) node [color=black,fill=white,below] {$Q$};
\draw [fill=black] (\Ac-0.1*\distance,0)--(\Bc+0.1*\distance,0)--(\Bc+0.1*\distance,0.01*\height)--(\Ac-0.1*\distance,0.01*\height)--cycle;
\draw [fill=black] (\Ac-0.1*\distance,\height)--(\Bc+0.1*\distance,\height)--(\Bc+0.1*\distance,1.01*\height)--(\Ac-0.1*\distance,1.01*\height)--cycle;
\draw [black,densely dashed](0,0)--(0,\height);


%
\coordinate (pulleyCenter) at (0,0.9*\height);
%
\pgfmathsetmacro{\pulleyRadius}{0.0375*\height}

\draw (0,0.9*\height-\pulleyRadius) node [color=black,fill=white,below] {$P$};

\draw [line width = 0.2*\distance,line cap=round](0,0.9*\height)--(0,0.995*\height);
\draw [line width = 0.2*\distance]([shift={(0,\height)}]0:-0.025*\height) arc[radius=0.025*\height, start angle=180, end angle= 360];

\pgfmathsetmacro{\ax}{\Bc-0.04*\distance}
\pgfmathsetmacro{\bx}{\Bc+0.04*\distance}
\pgfmathsetmacro{\lowerwidth}{\bx-\ax}
\pgfmathsetmacro{\aby}{0.2+0.01*\height}
\pgfmathsetmacro{\dx}{\Bc-0.08*\distance}
\pgfmathsetmacro{\cx}{\Bc+0.08*\distance}
\pgfmathsetmacro{\upperwidth}{\cx-\dx}
\pgfmathsetmacro{\cartheight}{1.25*\lowerwidth}
\pgfmathsetmacro{\dcy}{\aby+\cartheight}
\coordinate(a) at (\ax,\aby);
\coordinate(b) at (\bx,\aby);
\coordinate(d) at (\dx,\dcy);
\coordinate(c) at (\cx,\dcy);


\pgfmathsetmacro{\adx}{\Bc-0.06*\distance}
\pgfmathsetmacro{\ady}{\aby+0.5*\cartheight}
\coordinate (c1) at (\adx,\ady);
\draw [gray!120,line width = 0.01*\height cm,line cap=round](c1)--++(180:0.01*\Bc) coordinate (e1);


\coordinate (c2) at (\Bc+0.06*\distance,\ady);
\draw [gray!120,line width = 0.01*\height cm,line cap=round](c2)--++(0:0.01*\Bc) coordinate (e2);


\draw [line width = 0.005*\height cm,blue!200,fill=blue](a)--(b)--(c)--(d)--cycle;

\tkzTangent[from with R=e1](pulleyCenter,\pulleyRadius cm) \tkzGetPoints{D1}{D2}

\draw[yellow, line width = 0.010*\height cm,line cap =round](e1)--(D1);
\draw [gray!120,line width = 0.01*\height cm,line cap=round](c1)--(e1);
\draw [line width = 0.005*\height cm,blue!200,fill=blue](a)--(b)--(c)--(d)--cycle;

\pgfmathsetmacro{\wheelax}{0.25*\lowerwidth+\ax}
\pgfmathsetmacro{\wheelbx}{0.75*\lowerwidth+\ax}
\draw[black,fill=black](\wheelax,\aby)circle(\aby-0.011*\height);
\draw[black,fill=gray](\wheelax,\aby)circle(0.75*\aby-0.75*0.011*\height);

\draw[black,fill=black](\wheelbx,\aby)circle(\aby-0.011*\height);
\draw[black,fill=gray](\wheelbx,\aby)circle(0.75*\aby-0.75*0.011*\height);

\draw (\Bc,\ady) node [color=black] {$A$};


\pgfmathsetmacro{\shift}{\Ac-\Bc}
\begin{scope}[transform canvas={xshift=\shift cm}]
\draw [gray!120,line width = 0.01*\height cm,line cap=round](c1)--(e1);
\draw [gray!120,line width = 0.01*\height cm,line cap=round](c2)--(e2);
\coordinate (pulleyCenter) at (-1*\shift,0.9*\height);
\tkzTangent[from with R=e2](pulleyCenter,\pulleyRadius cm) \tkzGetPoints{D1}{D2}
\draw[yellow, line width = 0.01*\height cm,line cap =round](e2)--(D2);
\draw[gray!120,line width = 0.01*\height cm,line cap=round](c2)--(e2);
\draw [line width = 0.005*\height cm,blue!200,fill=blue](a)--(b)--(c)--(d)--cycle;
\draw[black,fill=black](\wheelax,\aby)circle(\aby-0.011*\height);
\draw[black,fill=gray](\wheelax,\aby)circle(0.75*\aby-0.75*0.011*\height);

\draw[black,fill=black](\wheelbx,\aby)circle(\aby-0.011*\height);
\draw[black,fill=gray](\wheelbx,\aby)circle(0.75*\aby-0.75*0.011*\height);
\draw (\Bc,\ady) node [color=black] {$B$};

\draw [gray,fill=gray!50,line width = 0.005*\height cm](pulleyCenter) circle(\pulleyRadius);
\end{scope}



\end{scope}
\end{tikzpicture}
\end{document}

enter image description here

And, this is the same tikz picture after using \begin{tikzpicture}[scale=200/(\hsize-24)]

\documentclass[tikz, border=12]{standalone}

\usepackage{tikz, tkz-euclide, pgfmath, pstricks}
\usetikzlibrary{intersections, decorations.markings, angles,
quotes, calc, arrows, arrows.meta}
\usetkzobj{all}
%
\definecolor{blue}{RGB}{0,51,255}
\definecolor{green}{RGB}{0,153,0}
\definecolor{blue1}{RGB}{174,214,241}
\definecolor{blue}{RGB}{161,207,223}
\definecolor{yellow}{RGB}{255,220,0}
\colorlet{dcolor}{blue}
%
\begin{document}
\begin{tikzpicture}[scale=200/(\hsize-24)]

\pgfgettransformentries{\mya}{\myb}{\myc}{\myd}{\mys}{\myt}
\pgfmathsetmacro{\preserve}{1/\mya}
\begin{scope}[>={Stealth[scale=1.2]} , thick,rotate=0 ] 

%
\newcommand\height{10}
%
\newcommand\Ac{-4}
%
\newcommand\Bc{27.46586300953384}
%
\pgfmathsetmacro{\distance}{\Bc+\Ac}
\draw (0,-0.2) node [color=black,fill=white,below] {$Q$};
\draw [fill=black] (\Ac-0.1*\distance,0)--(\Bc+0.1*\distance,0)--(\Bc+0.1*\distance,0.01*\height)--(\Ac-0.1*\distance,0.01*\height)--cycle;
\draw [fill=black] (\Ac-0.1*\distance,\height)--(\Bc+0.1*\distance,\height)--(\Bc+0.1*\distance,1.01*\height)--(\Ac-0.1*\distance,1.01*\height)--cycle;
\draw [black,densely dashed](0,0)--(0,\height);


%
\coordinate (pulleyCenter) at (0,0.9*\height);
%
\pgfmathsetmacro{\pulleyRadius}{0.0375*\height}

\draw (0,0.9*\height-\pulleyRadius) node [color=black,fill=white,below] {$P$};

\draw [line width = 0.2*\distance,line cap=round](0,0.9*\height)--(0,0.995*\height);
\draw [line width = 0.2*\distance]([shift={(0,\height)}]0:-0.025*\height) arc[radius=0.025*\height, start angle=180, end angle= 360];

\pgfmathsetmacro{\ax}{\Bc-0.04*\distance}
\pgfmathsetmacro{\bx}{\Bc+0.04*\distance}
\pgfmathsetmacro{\lowerwidth}{\bx-\ax}
\pgfmathsetmacro{\aby}{0.2+0.01*\height}
\pgfmathsetmacro{\dx}{\Bc-0.08*\distance}
\pgfmathsetmacro{\cx}{\Bc+0.08*\distance}
\pgfmathsetmacro{\upperwidth}{\cx-\dx}
\pgfmathsetmacro{\cartheight}{1.25*\lowerwidth}
\pgfmathsetmacro{\dcy}{\aby+\cartheight}
\coordinate(a) at (\ax,\aby);
\coordinate(b) at (\bx,\aby);
\coordinate(d) at (\dx,\dcy);
\coordinate(c) at (\cx,\dcy);


\pgfmathsetmacro{\adx}{\Bc-0.06*\distance}
\pgfmathsetmacro{\ady}{\aby+0.5*\cartheight}
\coordinate (c1) at (\adx,\ady);
\draw [gray!120,line width = 0.01*\height cm,line cap=round](c1)--++(180:0.01*\Bc) coordinate (e1);


\coordinate (c2) at (\Bc+0.06*\distance,\ady);
\draw [gray!120,line width = 0.01*\height cm,line cap=round](c2)--++(0:0.01*\Bc) coordinate (e2);


\draw [line width = 0.005*\height cm,blue!200,fill=blue](a)--(b)--(c)--(d)--cycle;

\tkzTangent[from with R=e1](pulleyCenter,\pulleyRadius cm) \tkzGetPoints{D1}{D2}

\draw[yellow, line width = 0.010*\height cm,line cap =round](e1)--(D1);
\draw [gray!120,line width = 0.01*\height cm,line cap=round](c1)--(e1);
\draw [line width = 0.005*\height cm,blue!200,fill=blue](a)--(b)--(c)--(d)--cycle;

\pgfmathsetmacro{\wheelax}{0.25*\lowerwidth+\ax}
\pgfmathsetmacro{\wheelbx}{0.75*\lowerwidth+\ax}
\draw[black,fill=black](\wheelax,\aby)circle(\aby-0.011*\height);
\draw[black,fill=gray](\wheelax,\aby)circle(0.75*\aby-0.75*0.011*\height);

\draw[black,fill=black](\wheelbx,\aby)circle(\aby-0.011*\height);
\draw[black,fill=gray](\wheelbx,\aby)circle(0.75*\aby-0.75*0.011*\height);

\draw (\Bc,\ady) node [color=black] {$A$};


\pgfmathsetmacro{\shift}{\Ac-\Bc}
\begin{scope}[transform canvas={xshift=\shift cm}]
\draw [gray!120,line width = 0.01*\height cm,line cap=round](c1)--(e1);
\draw [gray!120,line width = 0.01*\height cm,line cap=round](c2)--(e2);
\coordinate (pulleyCenter) at (-1*\shift,0.9*\height);
\tkzTangent[from with R=e2](pulleyCenter,\pulleyRadius cm) \tkzGetPoints{D1}{D2}
\draw[yellow, line width = 0.01*\height cm,line cap =round](e2)--(D2);
\draw[gray!120,line width = 0.01*\height cm,line cap=round](c2)--(e2);
\draw [line width = 0.005*\height cm,blue!200,fill=blue](a)--(b)--(c)--(d)--cycle;
\draw[black,fill=black](\wheelax,\aby)circle(\aby-0.011*\height);
\draw[black,fill=gray](\wheelax,\aby)circle(0.75*\aby-0.75*0.011*\height);

\draw[black,fill=black](\wheelbx,\aby)circle(\aby-0.011*\height);
\draw[black,fill=gray](\wheelbx,\aby)circle(0.75*\aby-0.75*0.011*\height);
\draw (\Bc,\ady) node [color=black] {$B$};

\draw [gray,fill=gray!50,line width = 0.005*\height cm](pulleyCenter) circle(\pulleyRadius);
\end{scope}



\end{scope}
\end{tikzpicture}
\end{document}

enter image description here

  • Did you try only with \begin{scope}[xshift=\shift cm]? Any reason for the low level transform? – percusse Apr 18 '17 at 10:17
  • I tried but it caused the coordinates defined outside the transform canvase scope, to stay the same. I tried tweaking the \shift value manually in the scaled version to see what's going on and it turned out that when I used transform canvas={xshift=\shift-18.5 cm}. it looked fine, so it's probably because the scaling applies differently to xshift in the transform canvas. but I need to find the exact relation between the scaling factor and xshift so that I can make this work for different values. – K. Ali Apr 18 '17 at 12:10
  • I think I've found the problem, the scaling doesn't apply to \shift in transform canvas={xshift=\shift cm} so I have to do it manually, then used the scaled shift (\shifta) in the the transform, but use the normal shift anywhere else \pgfmathsetmacro{\shifta}{(\Ac-\Bc)*\mya} \pgfmathsetmacro{\shift}{\Ac-\Bc} \begin{scope}[transform canvas={xshift=\shifta cm}] where \mya is the vertical scale – K. Ali Apr 18 '17 at 13:07
  • @CarLateX I will, I just decided to wait for a few days in case someone had a better suggestion. – K. Ali Apr 23 '17 at 7:25
  • @K.Ali OK, let's wait for a better answer, then! – CarLaTeX Apr 23 '17 at 7:34
1

The scaling of the tikz picture doesn't apply to the xshift inside the transform canvas, so all I had to do was apply the scaling to the shift outside the transform canvas, and then use the scaled value inside the canvas transform. so I used this

\pgfmathsetmacro{\shift}{\Ac-\Bc}
\pgfmathsetmacro{\shifta}{200/(\hsize-24)*\shift}
\begin{scope}[transform canvas={xshift=\shifta cm}]

instead of this

\pgfmathsetmacro{\shift}{\Ac-\Bc}
\begin{scope}[transform canvas={xshift=\shift cm}]

and the rest of the code is just the same.

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.