How to Autosize TikZ Mindmap Nodes to Fit Their Text
At a glance
- 1. Remove size floors
Check for minimum size, minimum width, or minimum height settings that force every concept to be large.
- 2. Use natural sizing
Let each node size itself from its text and padding; set minimum size to zero if a mindmap style imposes a larger minimum.
- 3. Control wrapping
Use text width when you want long labels to wrap, and remember it sets the text-box width rather than an automatic maximum.
- 4. Check the result
Compile and adjust inner sep for padding or text width for line breaks.
TikZ nodes are usually sized from their text automatically. If mindmap concepts all appear the same size, a style is likely setting a minimum size or fixed dimensions. Remove that constraint to let the node shape respond to its label.
For long labels, decide whether you want each label to stay on one line or wrap within a chosen width. These are different goals: natural sizing follows the text’s actual dimensions, while text width sets the width of the text box and can produce more consistent wrapping.
What determines a node’s size?
A node’s dimensions come from its text box, the shape’s geometry, and its padding. The inner sep option adds space between the text and the node boundary. Options such as minimum size, minimum width, and minimum height set lower bounds, so the node can be larger than its text requires.
In a mindmap, the concept style and level-specific styles can set these minimums. Look for settings such as concept/.style, root concept/.style, or level 1 concept/.style. If a style sets minimum size=3cm, for example, even a short label will be placed in a node at least that large.
Let the concepts size themselves
Append sizing options to the mindmap’s concept style so existing mindmap styling is retained. Setting minimum size=0pt removes a positive minimum size, while inner sep controls the padding. The following is a complete example:
\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{mindmap}
\begin{document}
\begin{tikzpicture}[
mindmap,
concept/.append style={
minimum size=0pt,
inner sep=3mm,
align=center
}
]
\node[concept, concept color=blue!60]
{A root\\with a longer label}
child[concept color=orange!70] {
node[concept] {Short label}
}
child[concept color=green!55] {
node[concept] {A longer child\\label}
};
\end{tikzpicture}
\end{document}
This uses the mindmap library from TikZ, loaded by \\usetikzlibrary{mindmap}. The concept/.append style adjustment preserves the library’s concept styling while removing a positive minimum size. The explicit line breaks show that labels can have different text heights; the circular nodes then adapt to their contents, with the specified padding.
If your document defines a fixed size in a more specific style, such as level 1 concept, adjust that style too. A more specific style can override a general concept setting.
Wrap long labels deliberately
Without a text width, a long label may stay on one line and make its node wide. To wrap it, set text width on that node:
node[concept, text width=2.5cm] {A longer label that wraps}
For a circular node, the circle must enclose the resulting text box, so its diameter depends on the box’s width and height. A fixed text width can therefore make several nodes similar in width, even though their heights—and hence their circle sizes—may differ. Use a width that suits the labels, or insert \\ where you want line breaks for more direct control.
align=center centers multiple lines; it does not choose a wrapping width by itself. Also, text width is not a maximum width that TikZ selects automatically: it sets the text box width you specify.
Common mistakes
- Keeping a fixed minimum size:
minimum size,minimum width, orminimum heightcan prevent short labels from producing smaller nodes. Remove or reduce the relevant constraint. - Changing only the padding: Smaller
inner sepmakes nodes tighter, but it cannot override a large minimum size. - Expecting automatic wrapping: A node without
text widthdoes not necessarily wrap a long label to a convenient width. Set a width or insert line breaks. - Setting a global text width accidentally: A text width applied to every concept makes all text boxes share that width. Apply it only where wrapping is needed if you want node widths to vary.
- Overriding mindmap styles unintentionally: Replacing
conceptwith a new style can discard its existing color or shape settings. Using.append styleis a convenient way to add sizing options without replacing the style.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.