37

My pgfplots ylabel text is too long and looks strange. Can I make it multiline?

48

The ylabel can be adjusted like other nodes. The key you can use for this is ylabel syle={<options>}.

To make it multiline, you can either just provide a text alignment option, using align=<center/left/right/justify>, and then insert the line breaks manually with \\.

The second option is to provide a text width that the text should keep to, using text width=<width>, and it will automatically wrap around. By default, the text will be left aligned, but you can use the align key here, too.

\documentclass{minimal}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=6cm,
ylabel style={align=center}, ylabel=A very long\\long\\text as a label,
xlabel style={text width=2.5cm}, xlabel=This is a long xlabel]
\addplot {x^2};
\end{axis}
\end{tikzpicture}
\end{document}

pgfplots plot with multiline labels

  • 1
    @Jake Did anything change since you posted your answer? I get an error-message saying: "I do not know the key '/tikz/align' and I am going to ignore it." – John Oct 25 '12 at 23:55
  • 1
    @John: That sounds like you're using a very old version of TikZ. The current version is 2.1, you're probably using 2.0 (which is several years old). – Jake Oct 26 '12 at 9:10
  • @Jake This is odd because I downloaded TeXShop (Version 2.47) a couple of month ago. Why should the package include an outdated distribution? – John Oct 26 '12 at 13:52
  • @John: The Linux distribution Ubuntu still ships with TeX Live 2009 (for compatibility reasons, I believe). I don't know what the situation is on Macs. What TeX distribution are you using? And, more importantly, what version of TikZ? You can check your TikZ version by including the command \pgfversion in a test document, which will print the version number in the output. – Jake Oct 26 '12 at 14:01
  • 1
    @John: Okay, so you've got an outdated version of TeX Live and TikZ. The best thing to do what probably be to install TeX Live 2012. Alternatively, you could just update the TikZ package. – Jake Oct 26 '12 at 14:26

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.