My pgfplots ylabel text is too long and looks strange. Can I make it multiline?
Asked
Active
Viewed 2.7k times
1 Answers
58
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}

Jake
- 232,450
\pgfversionin a test document, which will print the version number in the output. – Jake Oct 26 '12 at 14:01\pgfversionand\pdftexbannerinto a test-tex: "TikZ Version: 2.0" and "This is pdfTeX, Version 3.1415926-1.40.11-2.2 (TeX Live 2010) kpathsea version 6.0.0". – John Oct 26 '12 at 14:19