4

In this MWE, I can put a minimu size by hand, but how determine it automaticaly: let say max width of the two nodes + 4pt on each side ?

enter image description here

\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}
Tarass
  • 16,912

1 Answers1

4

Does it helps? The idea was taken from Roelof's answer to How to right align a table in a tikz picture and joined with Caramdir's answer to Why can't I use max() here?

\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}

enter image description here

Ignasi
  • 136,588