1

I would like to break a line inside a node.

The code below does not give the desired result:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{tikz-qtree} %-----questo è il pacchetto interessante
\tikzset{edge from parent/.style=
{draw,
edge from parent path={(\tikzparentnode.south)
-- +(0,-8pt)
-| (\tikzchildnode)}}}

\begin{document}

\begin{tikzpicture}
\Tree [.CP [.NP \node(wh){what}; ]
[.C$'$ [.I did ]
[.\node[draw]{IP};
[.NP [.Det the ] [.N cat ] ]
[.VP [.V sit ]
[.PP [.P on ]
[.\node[draw]{Comunicaz\\all interesting\\denied of\\activate of....};
[.NP [.Det a ] [.N book ] ]
[.PP [.P about ] [.NP \node(t){$t$}; ] ] ] ] ] ] ] ]
\draw[semithick,->] (t)..controls +(south west:5) and +(south:5)..(wh);
\end{tikzpicture}

\end{document}

How can I obtain a normal box without extending its size to accommodate all words)?

  • 2
    Potentially relevant – Christopher Sep 7 '15 at 8:55
  • Default is single line for nodes. Key align can be used to activate line breaks, e.g.: \node[draw,align=left]{...}. However, there is no place for such a large node in your diagram. – Heiko Oberdiek Sep 7 '15 at 8:55
  • You can also use text width=<some width> if you want the lines to be broken automatically. (I'm assuming here you want manual breaks as that is what your code shows.) – cfr Sep 7 '15 at 11:15
3

As Heiko Oberdiek commented, fitting a large node into your diagram is rather awkward. If you can't think of a better representation you can always shrink the text inside your large node using \tiny or various. Line breaks can be added in a number of ways, if you just want to manually add line breaks the you can use align.

\documentclass{standalone}
\usepackage{tikz}
\usepackage{tikz-qtree} %-----questo è il pacchetto interessante
\tikzset{edge from parent/.style=
{draw,
edge from parent path={(\tikzparentnode.south)
-- +(0,-8pt)
-| (\tikzchildnode)}}}

\begin{document}

\begin{tikzpicture}
\Tree [.CP [.NP \node(wh){what}; ]
[.C$'$ [.I did ]
[.\node[draw]{IP};
[.NP [.Det the ] [.N cat ] ]
[.VP [.V sit ]
[.PP [.P on ]
[.\node[draw, font=\tiny, align=center]{Comunicaz all interesting \\ denied of activate of....};
[.NP [.Det a ] [.N book ] ]
[.PP [.P about ] [.NP \node(t){$t$}; ] ] ] ] ] ] ] ]
\draw[semithick,->] (t)..controls +(south west:5) and +(south:5)..(wh);
\end{tikzpicture}

\end{document}

enter image description here

  • 1
    Why tabular? The additional \tabcolseps at the left and right need to be removed: {@{}c@{}}. Also the curly braces after \tiny can be removed, because \tiny does not expect an argument. Alternative: \node[draw, font=\tiny, align=center] {Comunicaz ...} – Heiko Oberdiek Sep 7 '15 at 9:19
  • @HeikoOberdiek Quite right, I forgot the add in the @{}. I didn't know you could specify the font as tiny as such. – Christopher Sep 7 '15 at 9:23
  • @HeikoOberdiek Would you like to provide an answer and I'll retract this one. – Christopher Sep 7 '15 at 9:26
  • Then I would already have written an answer. Can you improve the answer, thus that I can upvote? – Heiko Oberdiek Sep 7 '15 at 9:48
  • @HeikoOberdiek Updated as requested, I was just trying to be polite. – Christopher Sep 7 '15 at 9:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.