3

I know how to scale a shape in TiKZ. The following code snippet draws two rectangles, where the first rectangle has a line width of 2 and the second rectangle is a scaled version of the first one, with xscale=6 and yscale=2.

\documentclass{report}
\usepackage{tikz,pgfplots}
\begin{document}
\begin{tikzpicture}
\draw[line width =2] (0,3) rectangle ++ (1,1);                        % First rectangle (original)
\draw[line width =2,xscale=6,yscale=2] (0,0) rectangle ++ (1,1);      % Second rectangle (scaled version)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Labels
\node at(10,3.5) {First rectangle (original)};
\node at(10,1) {Second rectangle (scaled version)};
\end{tikzpicture}
\end{document}

Here is a preview: enter image description here

What I want to do, is to scale the line widths, as well as the shapes. In particular, I wish the scaled version of the first rectangle to look like the following enter image description here

The difference is that the xscaling and yscaling actions have impacted everything, and the vertical and horizontal lines have a thickness of 6 and 2, respectively. None of the methods I found (like this or using affine transformation with scope) seem to work. I appreciate your time.

Addendum

I need a general answer. That said, I may have many shapes in a tikzpicture, each of which being scaled, rotated or generally transformed differently. Therefore, an answer to this question must only affect the intended shape, not any other ones. Furthermore, the shapes are general (i.e. they can be rectangles, ellipses, stars, polygons, etc.)

1 Answer 1

6

Instead of scaling the shape itself, you could transform the canvas on which the shape is drawn, like drawing on an empty balloon and then blowing it up:

\documentclass{report}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[line width =2] (0,3) rectangle ++ (1,1); 
\begin{scope}[transform canvas={xscale=6,yscale=2}]
   \draw[line width =2] (0,0) rectangle ++ (1,1);     
\end{scope}
\end{tikzpicture}
\end{document}

enter image description here

1
  • Nicely done (+1).
    – Keen Teen
    Jun 18, 2023 at 14:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .