24

Adding child nodes to child nodes in TikZ Mindmap has some example code, where German words are not hyphenated correctly. I was trying to fix it by using inputenc (for Umlaute) and \usepackage[ngerman]{babel}. Unfortunately it has no effect on hyphenation.

What must be changed?

Below you can see a Working Example of it, showing forced hyphenation and no hyphenation: close up of compiled MWE

\documentclass{article}
    \usepackage[ngerman]{babel}
    \usepackage{tikz}
    \usetikzlibrary{mindmap,trees}

    \begin{document}
    \begin{tikzpicture}
    \path[mindmap,concept color=black,text=white]
        node[concept] {Die Wahrnehmung}
        [clockwise from=0]
        child[concept color=green!50!black] {
        node[concept] {Sensorische Prozesse}
        [clockwise from=90]
        child { node[concept] {Schwellen} 
child {node[concept] {Unterschiedsschwelle}}
child {node[concept] {Unter\-schieds\-schwel\-le}}
}
} 
child[concept] { node[concept] {Klassifikation} };
\end{tikzpicture}
\end{document}

2 Answers 2

36

The reason is that TeX doesn't hyphenate the first word in a paragraph. Inserting \hspace{0pt} for example would enable hyphenation, because then the word is not at the very beginning:

child {node[concept] {\hspace{0pt}Unterschiedsschwelle}}
2
  • Insightful answer! I didn't think of that rule because it applies so rarely.
    – Unapiedra
    Commented Feb 23, 2012 at 18:31
  • Can anyone tell me, if it's possible to add \hspace{0pt} automatically to the beginning of the code for every node content? Thanks!
    – rolfn
    Commented Feb 12, 2016 at 8:30
5

One can abuse the font= key in the node's options, to add the \hspace{0pt} macro at the beginning of the node. However this overwrites previous font keys, if present.

child {node[concept,font={\hspace{0pt}}] {Unterschiedsschwelle}}

In order to preserve the existing font keys, you can define the following in the preamble

\makeatletter
\tikzset{add to font/.code={\expandafter\def\expandafter\tikz@textfont\expandafter{\tikz@textfont#1}}}
\makeatother

then use it as

child {node[concept,add to font={\hspace{0pt}}] {Unterschiedsschwelle}}
child {node[concept,add to font={\hspace{0pt}}] {Unter\-schieds\-schwel\-le}}

to obtain

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .