9

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
    Mar 25 '11 at 22:41
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};
4

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.
    Mar 2 '21 at 21:48
3

Increase the value for text width conveniently.

2

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. Jan 14 '16 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
    Jan 21 '16 at 21:38

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.