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.

I have a some data plotted with pgfplots. I would like to make the title two lines. Can this be done? I tried adding \\ in the title command but that did nothing. Additionally, I couldn't find anything in the manual.

In my axis command, I have the option title = {text \\ text} where I want to split the title.

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat = 1.10}
\begin{document}
\begin{tikzpicture}
\begin{axis}[title = {text \\ text}]
\addplot[smooth, samples = 100, domain = 0:2] (\x, 2);
\end{axis}
\end{document}
share|improve this question
    
Along with describing the problem, It would be helpful if you composed a fully compilable MWE including \documentclass and the appropriate packages that sets up the problem. –  Peter Grill May 13 at 2:14
    
@PeterGrill I didn't really think this question needed a MWE. –  dustin May 13 at 2:15
    
Adding a MWE makes the question much clearer and eliminates the need for the person trying to help you to have to set it up and check that what they are proposing actually will work for you. I think perhaps egerg and DavidCarlisle can give you an answer without a MWE, but I don't think most others can. –  Peter Grill May 13 at 2:25

1 Answer 1

up vote 4 down vote accepted

Add align=center does the trick:

enter image description here

Code:

\documentclass[tikz, border=2pt]{standalone}
\usepackage{pgfplots}
%\pgfplotsset{compat = 1.10}
\begin{document}
\begin{tikzpicture}
\begin{axis}[align =center, title = {text \\ text}]
\addplot[smooth, samples = 100, domain = 0:2] (\x, 2);
\end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
    
Is there a way to do this with compat = 1.10? –  dustin May 13 at 2:24
1  
@dustin Use \pgfplotsset{compat = 1.10, title/.append style={align =center} } –  Harish Kumar May 13 at 2:26
    
@dustin: It should work. I don't have the latest version but so I cant test it but I am pretty sure it'll work. Let me know if it doesn't. –  Peter Grill May 13 at 2:26
    
It works on 1.10. I thought maybe it wouldn't since it was commented out. –  dustin May 13 at 2:27

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.