Simple question: I'm making a picture with PGF (basic layer, not TikZ) and I would like to add some text using \pgftext. The problem is that any \\ or \newline line breaks within the text are apparently ignored. Is there some way I can force a line break to appear?


  \pgftext{can haz line \\ break plz?}
  \pgftext[y = -20pt]{i made u a line \newline break but tex eated it}

This is not mentioned in the manual at all, and the only other discussion I can find is this post from comp.tex.pgf.user which doesn't actually include a solution, only the workaround of using a TikZ node with [align=...]. But, mostly for curiosity's sake, suppose using TikZ is off the table. Is it still possible to do line breaks? (I would think so, since TikZ itself must do it somehow)

  • could you put it in a tabular environment? something like \begin{tabular}{c}i made u a line \\ break but tex eated it\end{tabular}... – cmhughes Apr 29 '12 at 9:03
  • Or you could just wrap it in \shortstack{...} if it's not too complex. TikZ itself used a minipage, I think. – Jake Apr 29 '12 at 9:05

egreg's solution or perhaps a minipage

\pgftext[y=-20pt]{\begin{minipage}{5cm}can haz line \\ break plz?\end{minipage}} 
| improve this answer | |

Just a guess: \pgftext works with \hbox. So the answer might be

\pgftext{\vbox{\hbox{can haz line}\hbox{break plz?}}}

but probably

\pgftext{\begin{tabular}{@{}l@{}}can haz line\\break plz?\end{tabular}}

is handier (and can be wrapped up in a macro).

| improve this answer | |

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.