1

How can I tilt not rotate a rectangle? I am trying to draw a rectangle within another rectangle but I want the secondary (smaller) to be titled by (for example 25 deegress).

Sample of code:

\documentclass{article}
\usepackage{tikz}
\usepackage{lscape}
\usepackage{nopageno}
\usepackage{pdflscape}
\usetikzlibrary{shapes.geometric,positioning}
\usepackage{geometry}
 \geometry{
 a4paper,
 total={170mm,257mm},
 left=20mm,
 top=20mm,
 }

\begin{document}
  \begin{landscape}
    \begin{tikzpicture}
      \node at (0,0) [trapezium,
                      name=trapezium,
                      rounded corners,
                      line width=.05cm,
                      minimum width=5cm,
                      fill=blue!9!white,
                      minimum height=1cm,
                      draw=blue!50!white,
                      node distance=.05cm,
                      trapezium stretches=true] {};
      \node          [name=first,
                      rounded corners,
                      line width=.05cm,
                      fill=blue!9!white,
                      minimum width=5cm,
                      minimum height=1cm,
                      draw=blue!50!white,
                      node distance=.05cm,
                      below=of trapezium.south] {};
      \node          [name=second,
                      rounded corners,
                      line width=.05cm,
                      fill=blue!9!white,
                      minimum width=5cm,
                      minimum height=1cm,
                      draw=blue!50!white,
                      node distance=.05cm,
                      below=of first.south] {};
      \node          [name=third,
                      rounded corners,
                      line width=.05cm,
                      minimum width=5cm,
                      fill=blue!9!white,
                      draw=blue!50!white,
                      minimum height=1cm,
                      node distance=.05cm,
                      below=of second.south] {};
      \node          [name=fourth,
                      rounded corners,
                      line width=.05cm,
                      minimum width=5cm,
                      fill=blue!9!white,
                      draw=blue!50!white,
                      minimum height=1cm,
                      node distance=.05cm,
                      below=of third.south] {};
      \node          [circle,
                      fill=white,
                      xshift=-5mm,
                      name=firstCircle,
                      draw=blue!9!white,
                      minimum size=0.5cm] at (first.east) {};
      \node          [circle,
                      fill=white,
                      xshift=-5mm,
                      node distance=1cm,
                      draw=blue!9!white,
                      name=secondCircle,
                      minimum size=0.5cm] at (second.east) {};
      \node          [circle,
                      fill=white,
                      xshift=-5mm,
                      name=thirdCircle,
                      draw=blue!9!white,
                      minimum size=0.5cm,
                      node distance=20pt] at (third.east) {};
      \node          [name=forthCircle,
                      circle,
                      fill=white,
                      xshift=-5mm,
                      node distance=1cm,
                      draw=blue!9!white,
                      minimum size=0.5cm] at (fourth.east) {};
      \node          [name=fifth,
                      rectangle,
                      fill=white,
                      xshift=5mm,
                      draw=blue!9!white,
                      minimum width=.35cm,
                      minimum height=.8cm] at (first.west) {};
    \end{tikzpicture}
  \end{landscape}
\end{document}

Sample of (current) output:

output

Sample of desired output:

desired

2
  • 1
    That is called slanting in TikZ language: xslant though you can just place another trapezium with the right angle settings to create a parallelogram… or you just draw a quadrilateral where your specify the four corners. Dec 26, 2022 at 3:59
  • 1
    That said, I would use a path picture here with one filled path that's missing the stripes and the circle. (There are always many ways to do thing in TikZ/graphics.) Dec 26, 2022 at 4:01

2 Answers 2

2

Dear Thanos as Qrrbrbirlbel commented above a way to do it's to use trapezium shape rather than rectangle. Just for beginning based on your code:

\documentclass{article}
\usepackage{tikz}
\usepackage{lscape}
\usepackage{nopageno}
\usepackage{pdflscape}
\usetikzlibrary{shapes.geometric,positioning}
\usepackage{geometry}
\geometry{
    a4paper,
    total={170mm,257mm},
    left=20mm,
    top=20mm,
}

\begin{document}
    \begin{landscape}
        \begin{tikzpicture}
            \node at (0,0) [trapezium,
            name=trapezium,
            rounded corners,
            line width=.05cm,
            minimum width=5cm,
            fill=blue!9!white,
            minimum height=1cm,
            draw=blue!50!white,
            node distance=.05cm,
            trapezium stretches=true] {};
            \node          [name=first,
            rounded corners,
            line width=.05cm,
            fill=blue!9!white,
            minimum width=5cm,
            minimum height=1cm,
            draw=blue!50!white,
            node distance=.05cm,
            below=of trapezium.south] {};
            \node          [name=second,
            rounded corners,
            line width=.05cm,
            fill=blue!9!white,
            minimum width=5cm,
            minimum height=1cm,
            draw=blue!50!white,
            node distance=.05cm,
            below=of first.south] {};
            \node          [name=third,
            rounded corners,
            line width=.05cm,
            minimum width=5cm,
            fill=blue!9!white,
            draw=blue!50!white,
            minimum height=1cm,
            node distance=.05cm,
            below=of second.south] {};
            \node          [name=fourth,
            rounded corners,
            line width=.05cm,
            minimum width=5cm,
            fill=blue!9!white,
            draw=blue!50!white,
            minimum height=1cm,
            node distance=.05cm,
            below=of third.south] {};
            \node          [circle,
            fill=white,
            xshift=-5mm,
            name=firstCircle,
            draw=blue!9!white,
            minimum size=0.5cm] at (first.east) {};
            \node          [circle,
            fill=white,
            xshift=-5mm,
            node distance=1cm,
            draw=blue!9!white,
            name=secondCircle,
            minimum size=0.5cm] at (second.east) {};
            \node          [circle,
            fill=white,
            xshift=-5mm,
            name=thirdCircle,
            draw=blue!9!white,
            minimum size=0.5cm,
            node distance=20pt] at (third.east) {};
            \node          [name=forthCircle,
            circle,
            fill=white,
            xshift=-5mm,
            node distance=1cm,
            draw=blue!9!white,
            minimum size=0.5cm] at (fourth.east) {};
            \node[trapezium,
            trapezium left angle=70, 
            trapezium right angle=110,
            fill=white,
            xshift=6mm,
            draw=blue!9!white,
            inner xsep=0.3pt,%<- you can control shape width from here
            minimum height=.8cm] at (first.west) {};
            \node[trapezium,
            trapezium left angle=70, 
            trapezium right angle=110,
            fill=white,
            xshift=12mm,
            draw=blue!9!white,
            inner xsep=0.3pt,%<- you can control shape width from here
            minimum height=.8cm] at (first.west) {};
        \end{tikzpicture}
    \end{landscape}
\end{document}
2
  • By the way you could achieve your target using a much more smaller code by just defining a complete rectangle with it's trapeziums and circle and just copying it four times at different points.
    – miltos
    Dec 26, 2022 at 9:12
  • 1
    Thanks a lot @miltos. It works perfectly. I am not that experienced with Tikz unfortunately. Regarding the code how to short it I am thinking of using a foreach loop with xshift. Thanks again for the solution. It really helps me to move forward to the next task :).
    – Thanos
    Dec 26, 2022 at 13:30
2

I took the liberty to create a pic and path picture approach.

The pic house that takes a list of integer numbers create a pic with one roof (trapezium) and as many stories (the rectangles) as numbers are in its argument. The numbers in the argument correspond to the number of stripes (the slanted rectangles) in each rectangle.

So, pic {house={6, 2, 2, 2}} creates a house that has four stories with the top one having six and the others having two stripes.

The very first node that will not show up (path only) has a custom height where .5mm corresponds to the node distance and 1cm corresponds to the height of the stories and the roof. This setup creates a node that encloses the whole house and takes on the name of the pic and also dictates where and how the pic is placed. Long story short: The pic will be handled like a rectangular node that fits tightly around it

Note: The path picture only works well when the house (its stories) has not been rotated.

Code

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,positioning}
\makeatletter % https://github.com/pgf-tikz/pgf/issues/1177
\newcommand*\tikzfixpathpicture{\tikz@transform\let\tikz@transform=\relax}
\makeatother
\tikzset{
  house/stripes/.code={\tikzfixpathpicture
    \fill[sharp corners, blue!9!white, even odd rule]
                (path picture bounding box.south west)
      rectangle (path picture bounding box.north east)
      ([xshift=+-5mm]path picture bounding box.east) circle[radius=+2.5mm]
      [xslant=.3333, shift=(path picture bounding box.west)]
      foreach \houseStripe in {1,...,#1}{
        (5mm*\houseStripe,-3.5mm) rectangle ++ (2.5mm,7mm)};},
  house/common/.style={
    rounded corners, line width=+.5mm, minimum width=+5cm, minimum height=+1cm,
    draw=blue!50!white, node contents=},
  house/roof/.style={
    house/common, shape=trapezium, fill=blue!9!white, trapezium stretches=true},
  house/story/.style={house/common, shape=rectangle, node distance=+.5mm},
  house/.pic={
    \pgfmathtruncatemacro\stories{dim({#1})}
    \node [house/common, path only, sharp corners,
      minimum height={\stories*.5mm+(\stories+1)*1cm}, name=, alias=@];
    \node [house/roof, name=-roof, at=(@.north), anchor=north, alias=@];
    \foreach[count=\houseCount] \houseStripes in {#1}
      \node[house/story, name=-story-\houseCount,alias=@,below=of @,
        path picture=\tikzset{house/stripes=\houseStripes}];}}
\begin{document}
\tikz\pic {house={6,2,2,2}};

\begin{tikzpicture}
\pic (A) {house={6,2,2,2}};
\pic (B) [right=of A] {house={4,1}};
\draw[thick, red] (A-roof) -- (B-roof);
\draw (A) -- (B);
\end{tikzpicture}
\end{document}

Output

enter image description here

1
  • Thanks a lot @Qrrbrbirlbel. It is very interesting that you build it in this way. I was experimenting with something similar but much much more simpler :) (I am not that skilled on Latex as you :).) Thanks again for your time and effort in sharing knowledge. :)
    – Thanos
    Dec 28, 2022 at 13:41

You must log in to answer this question.

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