# New line in pgfplots/tikz not displaying in TeX

I have a multiple-line legend entry to preserve the width of my figure. I can use \newline in Matlab and the legend entry is split between two lines. When I produce a .tikz of the figure however, I can't figure out how to get a new line... It appears there was a similar issue or the same issue github of matlab2tikz but when I use this syntax the same issue arises where Matlab shows the multi-line legend entry but LaTeX doesn't. Am I missing a package or writing the syntax wrong ?

LaTeX code generated by matlab2tikz to display the multiline legend (\newline works in matlab, tried "\n" and tried removing all of the \text{}'s which didn't help - the \newline command is just ignored by LaTeX):

\addlegendentry{$\text{R}_{\text{Darcy,pwr}}\text{ = [1.26x10}^{\text{10}}\text{, 3.76x10}^{\text{9}}\text{] (1/m)**\newline** MAE=1.14x10}^{\text{-2}}\text{(g/min)}$};

Unfortunately I can't post images because I don't have 10 repuation... sorry about the links:

Matlab output:

LaTeX output:

• Welcome. Please provide a MWE. – cacamailg May 21 '13 at 23:41
• Welcome to TeX.SE. It would be helpful if you composed a fully compilable MWE including \documentclass and the appropriate packages that sets up the problem. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. – Peter Grill May 21 '13 at 23:44
• You can use \parbox for the this case. – cacamailg May 21 '13 at 23:44
• try using fig2texPS matlab script that does good job in converting figures to tex , also , Matlab outputs .eps(vector graphics and you can use figure without worry about quality) – vveliev May 22 '13 at 0:09

Updated

According to @Jake's comment, adding the key [align=left] will allow one to type multiple lines in the legend (I guess this is the same for entering multi-line texts in a TikZ node):

\addlegendentry[align=left]{
$\text{R}_\text{Darcy,pwr}=[1.26 \times 10^{10},\; 3.76\times 10^9]$ \\
$\text{(1/m)MAE}=1.14\times 10^{-2} \text{ (g/min)}$
}


A working example:

\documentclass{article}

\usepackage{pgfplots}
\usepackage{amsmath}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
legend style={at={(1.1,-0.1)},
cells={anchor=west}, % left-align cell content
}]

\addlegendentry{$\downarrow\Delta P$, 1$^{st}$ cycle}

\addlegendentry{DGM $\delta'_{\text{air}}=4.8\times 10^{-8}$ m-kPa}

$\text{R}_\text{Darcy,pwr}=[1.26 \times 10^{10},\; 3.76\times 10^9]$ \\
$\text{(1/m)MAE}=1.14\times 10^{-2} \text{ (g/min)}$