9

I want to draw parallelograms with fixed angle, width and height, but it seems that trapezium in PGF/TikZ cannot specific the height without changing angles.

\documentclass[tikz]{standalone}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
\tikzstyle{every node}=[trapezium, draw, minimum width=3cm,
trapezium left angle=120, trapezium right angle=60]

\node[trapezium stretches body]
    at (0,0) {A};

\node[trapezium stretches body, rotate=-30]
    at (0,1.5) {A rotate $-30^\circ$};

\node[minimum height=1cm, trapezium stretches body]
    at (5,0) {B};

\node[minimum height=1cm, trapezium stretches body, rotate=-30]
    at (5,1.8) {B rotate $-30^\circ$};

\node[minimum height=1cm]
    at (0,-2) {C};

\node[minimum height=1cm, rotate=-30]
    at (0,-4) {C rotate $-30^\circ$};

\node[minimum height=1cm, trapezium stretches]
    at (5,-2) {D};

\node[minimum height=1cm, trapezium stretches, rotate=-30]
    at (5,-4) {D rotate $-30^\circ$};

\end{tikzpicture}
\end{document}

The output:enter image description here

I want a vertically fat version of A with the same width.

A and B have different angles, just adding "minimum height". Rotated version of A has vertical west/east sides, that's what I need. Rotated version of B does not have vertical west/east sides, however, I do need a "higher" parallelogram with the same angles and width as A.

C: Removing "trapezium stretches body" results in a parallelogram whose width and height out of control. D: Replacing "trapezium stretches body" with "trapezium stretches" helps nothing.

  • 2
    Welcome to TeX.sx! As new user without image posting privileges simply include the image as normal and remove the ! in front of it to turn it into a link. A moderator or another user with edit privileges can then reinsert the ! to turn it into an image again. – Qrrbrbirlbel Apr 05 '13 at 06:43
  • While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it.

    This is especially important for tikz as there are numerous libraries.

    – Peter Grill Apr 05 '13 at 06:49
  • Can you also include your goal? Because only rotate=-30 uses a fixed point on the shape border of the node. So if the size changes the rotation axis changes. You can use rotate around if that's you wish. But it might be something else you are after. – percusse Apr 05 '13 at 07:11
  • 1
    You could make answering your question easier if you use the every node or the every trapezium node style for common options (angles, minimum width). – Qrrbrbirlbel Apr 05 '13 at 07:21
  • 1
    Drawing a parallelogram (trapezium) and drawing the Shape trapezium is different. You have some constraints with the shape because in this case you use a node. It is not the same question. – Alain Matthes Apr 05 '13 at 07:32
  • @percusse: I want a vertically fat version of result of this statement. That is, larger height, but not changing the width. – user2014859 Apr 05 '13 at 07:37
  • @AlainMatthes: Otherwise, how can I put a node inside a defined parallelogram? Texts should be sloped along the slopy sides. – user2014859 Apr 05 '13 at 07:43
  • In your case, if you need to add a text or if you need to place others shapes relatively to the first one, it's preferable to find a solution with node/shape. But if you need to use a very specific shape, you only need to know a specific point (center/ barycenter,...) to place a node inside. It's not very elegant but it's possible and you can draw everything. I wrote this comment because there is always a confusion with node/shapes and simple shapes (no text, no anchor etc.) – Alain Matthes Apr 05 '13 at 07:52

1 Answers1

11

Maybe the following can explain better what is happening. The strange thing happening when the text is getting shorter and the node is getting higher and getting shorter as the text gets longer is due to the constraints being respected.

\documentclass[tikz]{standalone}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
\tikzstyle{every node}=[trapezium, draw, minimum width=3cm,
trapezium left angle=120, trapezium right angle=60]

\node[trapezium stretches=false,minimum height=1cm]
    at (0,0) {A};

\node[trapezium stretches=false,minimum height=1cm]
    at (0,1.5) {\fbox{A long }};

\node[trapezium stretches=false,minimum height=1cm]
    at (0,3) {\fbox{A long text}};

\draw[thick,green,|-|] (-1.5,-.5) -- (1.5,-0.5);
\draw[thick,green,|-|] (-1.5,0.5) -- (-1.5,-0.5);

\draw[thick,blue,|-|] (-1.5,1) -- (1.5,1);
\draw[thick,blue,|-|] (-1.5,1) -- (-1.5,2);

\draw[thick,red,|-|] (-1.5,2.5) -- (1.5,2.5);
\draw[thick,red,|-|] (-1.5,2.5) -- (-1.5,3.5);

\end{tikzpicture}
\end{document}

without the body stretch

We see that the minimum width and minimum height is respected and then if there is any room then the node is getting higher because there is no constraint for that. In other words there is only constraint on the minima not maxima hence in the bottom example minima is respected and then the angles are tried to match. If the node is shorter and the angles are fixed then minimum height won't be respected etc. Hence for this there are some options are proposed namely the stretch options. If we turn all the false keys to true, we get

enter image description here

So the angel of the shape is deformed to comply with the constraints. Similarly the trapezium stretches body key only stretches the width. But if the angle is set then it's a matter of respecting the constraints and then checking if the angle is feasible. So a different type of constraint is needed. This might be using labels at the center anchor or drawing it on top of the nodes regardless of the size etc.

percusse
  • 157,807
  • 1
    Thanks very much! It seems that when trapezium stretches=false, the angle is respected, even min height (or min width?) may not be respected. When trapezium stretches=true, the angle may not respected. While trapezium stretches body=true and minimum height and mini width are specified at the same time, the angle may not be respected again. <\br> I am beginner in pgf/tikz, but I found it amazing every time a new elegant design was discovered. Thanks to all of your. I am trying to draw by mathematical formulas. – user2014859 Apr 05 '13 at 13:55