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:

enter image description here

LaTeX output:

enter image description here

  • 2
    Welcome. Please provide a MWE.
    – cacamailg
    May 21, 2013 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. May 21, 2013 at 23:44
  • 1
    You can use \parbox for the this case.
    – cacamailg
    May 21, 2013 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, 2013 at 0:09

1 Answer 1



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):

  $\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:




  legend style={at={(1.1,-0.1)},
  cells={anchor=west}, % left-align cell content

\addplot coordinates {(0,0) (1,1)};
\addlegendentry{$\downarrow\Delta P$, 1$^{st}$ cycle}

\addplot coordinates {(0,1) (1,2)};
\addlegendentry{DGM $\delta'_{\text{air}}=4.8\times 10^{-8}$ m-kPa}

\addplot coordinates {(0,2) (1,3)};
  $\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)}$



enter image description here

  • I apologize for not including a MWE but really appreciate you showing the figure. This answered my question plus some because the "\times" looks better than "x" thanks! May 22, 2013 at 3:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .