Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

\documentclass{minimal}
\usepackage{pgf}

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

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)

share|improve this question
    
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

2 Answers 2

up vote 4 down vote accepted

egreg's solution or perhaps a minipage

\pgftext[y=-20pt]{\begin{minipage}{5cm}can haz line \\ break plz?\end{minipage}} 
share|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).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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