TikZ Mindmap: How can I make nodes autosize to fit the text?

2,266

I think you can simply add

text width=

to the style for every node. The mindmap style applies styles for each level of the tree which set the width of the text. You could override these separately per level, but if you want to do this generally, just adding it for all nodes seems to make more sense.

This produces

shrink-to-fit nodes

Code:

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{mindmap}
\tikzset{
    every node/.append style={concept, text width=, rectangle, minimum size=0cm, inner sep=2mm},
}
\begin{document}
\begin{tikzpicture}[mindmap,text=white]
  \node {Orangutans} child { node {Aardvarks} child { node {Bees} } };
\end{tikzpicture}
\end{document}
Share:
2,266

Related videos on Youtube

Make42
Author by

Make42

Updated on January 03, 2020

Comments

  • Make42
    Make42 over 2 years

    How can I have the size of a mindmap node be calculated automatically by TikZ such that the text inside fits nicely inside? With inner sep=... I am able to have the height fit in such a way, but not the width. Btw.: I am using rectangles as nodes, not the standard circles.

    \documentclass[tikz,border=5]{standalone}
    \usetikzlibrary{mindmap}
    
    \tikzset{
        every node/.append style={concept, rectangle, minimum size=0cm, inner sep=2mm}
    }
    
    \begin{document}
    
    \begin{tikzpicture}[mindmap,text=white]
    \node {O} child { node {A} };
    \end{tikzpicture}
    
    \end{document}
    
    • cfr
      cfr over 6 years
      Please post a minimum working example (MWE). How are we to guess what you've done or how you've configured a non-standard mind map if you don't show us?
    • Make42
      Make42 over 6 years
      @cfr: I don't quite see the necessity in this case, but here you go.
    • cfr
      cfr over 6 years
      Well, it makes it much easier to answer. How else can I know what you've done?
    • cfr
      cfr over 6 years
      I like the rectangular style. I never realised you can do this. Does it work with the gradual change of colour in connections between the nodes? I guess it should? I guess it would be nice if the transition to the connection could be smoother, though. It keeps reminding me of Dairy Milk ads.