I have a list of rectangular blocks that have a text, color, and size (y start, y size, x start, and x size). I want the text to be in the center of the rectangle, such that it does not go outside of rectangle.
Currently I am using \\ in text to make sure the text fits, but this requires too much playing around, I would prefer them to fit automatically. Here is my current code:
\foreach \text/\color/\ystart/\ysize/\xstart/\xsize in \rectangularblocks {
\filldraw[fill=\color] (\xstart, \ystart) rectangle (\xstart+\xsize, \ystart+\ysize);
\draw (\xstart+\xsize/2, \ystart+\ysize/2) node[align=center] {\text};
}
Based on other answers I saw, this can be done in two ways:
- By turning on wrapping and bounding the text to the size of the rectangle.
- By scaling the text to fit in rectangle.
But I fail to come up with code that can do either (and keeping the text in the center of my rectangle). I would prefer #1 as it means I do not have to play around with \\ in my text.