如果我改变minimum height=...
一个trapezium
节点,宽度也会改变。
标准矩形节点不会发生这种情况。
\documentclass[border=0pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{positioning, shapes.geometric, shapes.misc, matrix}
\begin{document}
\begin{tikzpicture}[
basenode/.style={
draw=lightgray, align=center,
text=black, very thick,
text height=1.75ex, text depth=.25ex,
text width=7em,
},
inout/.style={
basenode,
minimum height=5ex,
trapezium,
trapezium left angle=60,
trapezium right angle=120,
},
inout2/.style={
basenode,
minimum height=7ex,
trapezium,
trapezium left angle=60,
trapezium right angle=120,
},
instruction/.style={
basenode,
minimum height=5ex,
rounded corners,
},
instruction2/.style={
basenode,
minimum height=7ex,
rounded corners,
},
]
\matrix[
matrix of nodes, row sep=7ex, column sep=7em,
anchor=base
]{
|[inout]|\texttt{trapezium} & with \texttt{minimum height=5ex}\\
|[inout2]|\texttt{trapezium} & with \texttt{minimum height=7ex}\\
|[instruction]|\texttt{rectangle} & with \texttt{minimum height=5ex}\\
|[instruction2]|\texttt{rectangle} & with \texttt{minimum height=7ex}\\
};
\end{tikzpicture}
\end{document}
答案1
这是已知问题。在 tikz 和 pgf 手册中,您可以在第 697 页找到以下内容:
/pgf/trapezium stretches=boolean (默认 true)
此键控制 pgf 是否允许在考虑任何最小尺寸规范时独立放大梯形的宽度和高度。这最初是错误的,确保形状在放大时“看起来相同但更大”。
通过将 hbooleani 设置为 true,梯形可以水平或垂直拉伸。
其中一个例子:
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}[
my node/.style={trapezium, fill=#1!20, draw=#1!75, text=black},
trapezium stretches=true % <---
]
\draw [help lines] grid (3,2);
\node [my node=red] {A};
\node [my node=green, minimum height=1.5cm] at (1, 1.25) {B};
\node [my node=blue, minimum width=1.5cm] at (2, 0) {C};
\end{tikzpicture}
\end{document}