0

I would like to attach several labels with annotations to a (square) node (the node has the text "32" here).

However, the labels (they have draw) should lie seamlessly together and should all have the same width as the node (with 32).

How do I achieve a suitable font size for the labels? (The label texts should all have the same font size.)

Or what is the best way to do this?

enter image description here

\documentclass[margin=5pt]{standalone}

\usepackage{tikz}

\begin{document} \begin{tikzpicture}[font=\footnotesize\sffamily, very thin, NumStyle/.style={minimum size=4mm, inner sep=0pt, draw}, LabelStyle/.style={minimum width=4mm, draw, font=\sffamily\tiny, inner xsep=0.5pt, inner ysep=1pt}, ]

\node[NumStyle, fill=red, text=white, label={[LabelStyle, scale=0.7% try ? ]below:{1. Place}}, label={[LabelStyle, fill=yellow, name=P]above:{even (1/9)}}, label={[LabelStyle, fill=purple, yshift=2.7mm]{high (3/9)}}, ]{32}; \end{tikzpicture} \end{document}

cis
  • 8,073
  • 1
  • 16
  • 45
  • 1
    See the tikz manual, part about shapes. There is one rectangle which you can split into many parts. This is the geometry I read from your question. – MS-SPO May 01 '23 at 15:23
  • 1
    @MS-SPO Ah, you mean the shape 'rectangle split'. Which offers multiple own options. I didn't even know that shape. Very good idea, I should be able to do something with that. – cis May 01 '23 at 16:06
  • Right. Couldn‘t recall the name. Feel free to present an answer if it works the way you like it. – MS-SPO May 01 '23 at 16:29

2 Answers2

2

Here's a way to do it:

  • neglecting font
  • using the part fill as list option
  • the manual has more examples using nodes directly
  • making the boxes wider is easy via textwidth

result

\documentclass[10pt,border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}

\begin{document}

\begin{tikzpicture}

\node [rectangle split, rectangle split parts=4,draw,
       rectangle split part fill=
       {red!80!blue,yellow,red,white}]
{
    high (3/9)
    \nodepart{two} 
        even (1/9)
    \nodepart{three}
        \textbf{\textcolor{white}{\LARGE{32}}}
    \nodepart{four}
        1. Place
};

\end{tikzpicture}

\end{document}

MS-SPO
  • 11,519
  • Thx! I posted a following-up question here: https://tex.stackexchange.com/q/684495/46023 – cis May 01 '23 at 18:56
0

Here's an other way to do it:

  • define minimum width, height (for rectangles) and size for square
  • place with absolute coordinates, doing some math by hand/head
  • could be automized by using the calc library etc.

result

\documentclass[10pt,border=3mm]{standalone}
\usepackage{tikz}
%\usetikzlibrary{shapes.multipart}

\begin{document}

\begin{tikzpicture} [rc/.style={draw,minimum height=1cm,minimum width=3cm}, sq/.style={draw,minimum size=2cm}]

 \node [rc,fill=red!80!blue]    at (0,0) {high (3/9)};
 \node [rc,fill=yellow]         at (0,-1) {even (1/9)};
 \node [sq,fill=red]            at (0,-2.5) {\textbf{\textcolor{white}{\LARGE{32}}}};
 \node [rc]                     at (0,-4) {1. Place};

\end{tikzpicture}

\end{document}

MS-SPO
  • 11,519
  • Thx, but the the parts 'should all have the same width '. So 'rectangle split' is the more elegant way. – cis May 01 '23 at 19:05
  • I think, that‘s easy to solve: just adjust minimum size=3cm in the answer, and shift the last node a little. – MS-SPO May 01 '23 at 19:18