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:
inner sep=1pt
? – Mark Wibrow Apr 29 '13 at 15:23inner sep
is0pt
, the node contents are5pt 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). Theminimum height
is1.81mm=5.14993pt
, so the new width is50.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