# tikz - trapezium node - fix angle and height, adjustable width

Using TikZ, I want to draw trapezium nodes all of which have a fixed height and angle(s), but whose widths vary. I can't find any combination of parameters that does what I want. Specifically, with trapezium stretches=false, the angle is correct but the widths are ridiculously large. With trapezium stretches=true or trapezium stretches body=true, the widths are correct but the angles are all wrong.

A similar problem seems to have been discussed at Drawing parallelogram with fixed angle, width and height?, but I don't see an answer in there, only talk about why the obvious thing doesn't work, which frankly I don't care, I'm only interested in what to change so that it does work. (One clarification, though: these trapezoidal bars need to be nodes so that they can be addressed in the larger document, for labeling and so on. Also, I'm setting the size of the node with \rule because when I tried to do it exclusively with minimum width I got division-by-zero errors. It appears that a trapezium node cannot be empty.)

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\usepackage[active,pdftex,tightpage]{preview}
\PreviewEnvironment[]{tikzpicture}
\begin{document}
\begin{tikzpicture}[x=5mm,y=5mm,every node/.style={
trapezium, trapezium angle=67.5, draw,
inner sep=0pt, outer sep=0pt,
minimum height=1.81mm, minimum width=0pt
}]
\node [] at (0,9) {\rule{1pt}{0.1pt}};
\node [] at (0,8) {\rule{5pt}{0.1pt}};
\node [] at (0,7) {\rule{10pt}{0.1pt}};
\node [trapezium stretches] at (0,6) {\rule{1pt}{0.1pt}};
\node [trapezium stretches] at (0,5) {\rule{5pt}{0.1pt}};
\node [trapezium stretches] at (0,4) {\rule{10pt}{0.1pt}};
\node [trapezium stretches body] at (0,3) {\rule{1pt}{0.1pt}};
\node [trapezium stretches body] at (0,2) {\rule{5pt}{0.1pt}};
\node [trapezium stretches body] at (0,1) {\rule{10pt}{0.1pt}};
\end{tikzpicture}
\end{document}


which renders as:

-
What happens if you use inner sep=1pt? –  Mark Wibrow Apr 29 '13 at 15:23
@MarkWibrow The trapezium is then more likely to be the right width (it still becomes ridiculously wide with very small inner contents) but is too tall. –  Zack Apr 29 '13 at 15:48
Consider the second trapezium in your code. As the inner sep is 0pt, the node contents are 5pt x .1 pt. This means the total trapezium width is (5+2*.1*cot(67.5))/.1=50.828 times the height. This factor is used when the trapezium is scaled to some minimum height to make the shape "look the same but bigger" (PGF 2.10 manual p423). The minimum height is 1.81mm=5.14993pt, so the new width is 50.828*5.149=261.713pt (9.199cm). This is technically the correct behaviour, but I concede it does produce shapes that would be unanticipated even with a close reading of the manual. –  Mark Wibrow Apr 29 '13 at 16:39

maybe like this:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\usepackage[active,pdftex,tightpage]{preview}
\PreviewEnvironment[]{tikzpicture}
\begin{document}
\begin{tikzpicture}[x=5mm,y=5mm,every node/.style={
trapezium, trapezium angle=67.5, draw,
inner ysep=5pt, outer sep=0pt,
minimum height=1.81mm, minimum width=0pt
}]
\node[inner xsep=6pt] at (0,5){};
\node[inner xsep=5pt] at (0,4){};
\node[inner xsep=4pt] at (0,3){};
\node[inner xsep=3pt] at (2,5){};
\node[inner xsep=2pt] at (2,4){};
\node[inner xsep=1pt] at (2,3){};
\end{tikzpicture}
\end{document}


see pag. 422 of the TikZ manual (there are more chunks of code you could remove, I left them there since I was not sure you actually need them for other purposes)

-
This doesn't work in the larger context: specifically, that minimum height=1.81mm? Is meant to be the fixed height of the trapezoid, regardless of the width. also, what were you trying to point me to on page 422 of the TikZ manual? I don't see anything enlightening. –  Zack Apr 28 '13 at 23:17
that was an example, you can set set the ysep to a different value or remove it completely so that the height will be fixed at 1.81mm, and you can still control the width with the inner xsep (also in mm if you wish). I pointed you to the part of the manual where it explains that the node label can be empty, since you thought it cannot. –  dcmst Apr 29 '13 at 7:49
I'm aware that the node label is supposed to be allowed to be empty, but if I write a trapezium-shaped node with empty contents and zero inner ysep, I get a division-by-zero error. –  Zack Apr 29 '13 at 13:12
the reason why is explained in those pages, that's why I linked them :) –  dcmst Apr 29 '13 at 13:13
Would you please just spell out for me what you are trying to communicate? I have read page 422 several times now and I do not see anywhere it says that \node [trapezium, inner sep=0pt, minimum width=10pt] {}; is expected to produce a division by zero error. To the contrary, as far as I can tell, it implies that that should work Just Fine. –  Zack Apr 29 '13 at 13:28

One possibility would be to use text width to control the width; using one argument for a new mytrap style, you the can use the style like this:

\node [mytrap=<width>] at (<position>) {};


A complete example:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
%\usepackage[active,pdftex,tightpage]{preview}
%\PreviewEnvironment[]{tikzpicture}
\begin{document}
\begin{tikzpicture}[x=5mm,y=5mm,
mytrap/.style={
trapezium, trapezium angle=67.5, draw,inner xsep=0pt,outer sep=0pt,
minimum height=1.81mm, text width=#1
}]
\foreach \ancho [count=\xi] in {5,10,...,100}
\node [mytrap=\ancho pt] at (0,-\xi) {};
\end{tikzpicture}
\end{document}


-
This appears to work in a toy test. I need to see if it also works in my larger document (which will involve careful revision to remove the kludge-around I came up with last night) before accepting, though. –  Zack Apr 29 '13 at 15:50