10

How do I get the text does not break the line? I have

\begin{tikzpicture}
\node[align=left,text width=3cm] {Contemplando a contemporaneidade};
\end{tikzpicture}

enter image description here

but i need

enter image description here

1
  • 3
    Is there a reason why you can't just increase the text width? (By the way, your example code does not break the line if I put it into a article or minimal document. Do you set anything that influences the font size?)
    – Jake
    Commented Mar 25, 2011 at 22:41

4 Answers 4

10

Or don't specify the text width at all, just add a line break at the appropriate position.

\node[align=left] {Contemplando a\\contemporaneidade};
5

Instead of using align=left, you can use align=flush left. This seems to do exactly the same as align=left, but without the hyphenation.

\node[align=flush left,text width=3cm] {Contemplando a contemporaneidade};

I found this trick here: Manual/automatic line breaks and text alignment in TikZ nodes

1
  • Also works with align=flush center and align=flush right
    – David M.
    Commented Mar 2, 2021 at 21:48
3

Increase the value for text width conveniently.

3

We could use \hyphenchar\font as a global switcher; =1 turning on hyphenation, =-1 preventing hyphenation.

\documentclass[a4paper]{article}
\pagestyle{empty}
\usepackage{tikz}
\usepackage[english]{babel}
\begin{document}
\begin{tikzpicture}
\node[align=left,text width=2cm,draw] {Contemplando a contemporaneidade};
\end{tikzpicture}
\begin{tikzpicture}
\node[align=left,text width=2cm,draw] {%
  \hyphenchar\font=-1 % 1 or -1
  Contemplando a contemporaneidade
  };
\end{tikzpicture}
\hyphenchar\font=1 % 1 or -1
Regular document. Regular document. Regular document. Regular document. Regular document. Regular document. Regular document. 
\end{document}

mwe

2
  • Is the \hyphenchar\font=1 necessary to restore hyphenation, or is the \hyphenchar\font=1 actually localized? I ask because you called it a global switcher. At first glance, it seems to me that it would be a change valid only within the tikzpicture's scope. Commented Jan 14, 2016 at 14:36
  • @macmadness86 I am not 100% sure, but I think that I tried % \hyphenchar\font=1 and it wasn't working well. I am not TeXing these days, so I cannot try more experiments, I am sorry about that.
    – Malipivo
    Commented Jan 21, 2016 at 21:38

You must log in to answer this question.

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