在这个 MWE 中,我可以手动放置最小尺寸,但是如何自动确定它:比如说两个节点的最大宽度 + 每边 4pt?
\documentclass[french]{article}
\usepackage{tikz}
\pgfkeys{/tikz/.cd,
BLS/.store in=\BLS,
BLS=\baselineskip
}
\begin{document}
\tikzset{%
TDPnode/.style={outer sep=0pt,inner sep=1pt,
minimum height=\BLS,draw},
TDPetq/.style={TDPnode,anchor=north east},
}
\begin{tikzpicture}[yscale=-1,
TDPetq/.append style={minimum width=1.5cm}
]
\node[TDPetq] (A0) at (0,0) {angle (degree)} ;
\node[TDPetq] (B0) at (0,\BLS) {temps (h)} ;
\end{tikzpicture}
\end{document}
答案1
这有帮助吗?这个想法来自 Roelof 对如何在 tikz 图片中右对齐表格并与 Caramdir 的回答相结合为什么我不能在这里使用 max()?
\documentclass[french]{article}
\usepackage{tikz}
\pgfkeys{/tikz/.cd,
BLS/.store in=\BLS,
BLS=\baselineskip
}
\begin{document}
\tikzset{%
TDPnode/.style={outer sep=0pt,inner sep=1pt,
minimum height=\BLS,draw},
TDPetq/.style 2 args={TDPnode,anchor=north east,
minimum width={max(width("#1"), width("#2"))+8pt}},
}
\begin{tikzpicture}[yscale=-1]
\node[TDPetq={angle (degree)}{temps (h)}] (A0) at (0,0) {angle (degree)} ;
\node[TDPetq={angle (degree)}{temps (h)}] (B0) at (0,\BLS) {temps (h)} ;
\begin{scope}[xshift=5cm]
\node[TDPetq={short}{second much longer}] (A0) at (0,0) {angle (degree)} ;
\node[TDPetq={short}{second much longer}] (B0) at (0,\BLS) {temps (h)} ;
\end{scope}
\end{tikzpicture}
\end{document}