0

I want legend = {text = {} in multi lines The text of the legend is very long and I want to divide it into multi lines

\tikz \datavisualization [scientific axes=clean]

[
visualize as smooth line=Gaussian,
Gaussian={pin in data={text={$e^{-x^2}$},when=x is 1}}
]
data [format=function] {
    var x : interval [-7:7] samples 51;
    func y = exp(-\value x*\value x);
}
[
visualize as scatter,
legend={south east outside},
scatter={
    style={mark=*,mark size=1.4pt,text width=1.5cm,cells={align=left}},
    label in legend={text={ $\sum_{i=1}^{10} x_i$   , where         $x_i \sim U(-1,1)$
            }}}
]
data [format=function] {
    var i : interval [0:1] samples 20;
    func y = 0;
    func x = (rand + rand + rand + rand + rand +
    rand + rand + rand + rand + rand);
};

1 Answer 1

1

What always works in such cases is to add a simple tabular.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{datavisualization}
\usetikzlibrary{datavisualization.formats.functions}
\begin{document}
\begin{tikzpicture}
\datavisualization[scientific axes=clean]
  [
  visualize as smooth line=Gaussian,
  Gaussian={pin in data={text={$e^{-x^2}$},when=x is 1}}
  ]
  data [format=function] {
      var x : interval [-7:7] samples 51;
      func y = exp(-\value x*\value x);
  }
  [
  visualize as scatter,
  legend={south east outside},
  scatter={
      style={mark=*,mark size=1.4pt,text width=1.5cm,cells={align=left}},
      label in legend={text={\begin{tabular}[t]{l}
  $\sum\limits_{i=1}^{10} x_i$, where \\        
  $x_i \sim U(-1,1)$
  \end{tabular}}}}
  ]
  data [format=function] {
      var i : interval [0:1] samples 20;
      func y = 0;
      func x = (rand + rand + rand + rand + rand +
      rand + rand + rand + rand + rand);
  };
\end{tikzpicture}
\end{document}

enter image description here

If you have more of those, you may want to change the node styles.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{datavisualization}
\usetikzlibrary{datavisualization.formats.functions}
\begin{document}
\begin{tikzpicture}[cells={nodes={align=left}}]
\datavisualization[scientific axes=clean]
  [
  visualize as smooth line=Gaussian,
  Gaussian={pin in data={text={$e^{-x^2}$},when=x is 1}}
  ]
  data [format=function] {
      var x : interval [-7:7] samples 51;
      func y = exp(-\value x*\value x);
  }
  [
  visualize as scatter,
  legend={south east outside},
  scatter={
      style={mark=*,mark size=1.4pt,text width=1.5cm,cells={align=left}},
      label in legend={text={$\sum\limits_{i=1}^{10} x_i$, where \\        
  $x_i \sim U(-1,1)$}}}
  ]
  data [format=function] {
      var i : interval [0:1] samples 20;
      func y = 0;
      func x = (rand + rand + rand + rand + rand +
      rand + rand + rand + rand + rand);
  };
\end{tikzpicture}
\end{document}

In any case, it would be great if you could in the future provide complete documents that start with \documentclass, end with \end{document} and contain just enough packages and libraries to be compiled. This makes it easier to look at your question(s).

1
  • I am sorry for not putting all the code, thanks. Regards
    – ebjargu
    Nov 18, 2019 at 11:40

You must log in to answer this question.

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