TransWikia.com

legend={text={ multi line

TeX - LaTeX Asked by Jota Aguilar on December 21, 2020

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);
};

One Answer

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}
  $sumlimits_{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={$sumlimits_{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).

Answered by user194703 on December 21, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP