# LaTeX strings do not vertically align in Plots

**URL:** <https://discourse.julialang.org/t/latex-strings-do-not-vertically-align-in-plots/109304>\
**Category:** Visualization\
**Tags:** question, plots, latexstrings\
**Created:** [January 26, 2024, 1:23pm UTC](https://discourse.julialang.org/t/latex-strings-do-not-vertically-align-in-plots/109304 "2024-01-26T13:23:48Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ysfoo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ysfoo/32/51058_2.png) [@ysfoo](https://discourse.julialang.org/u/ysfoo)\
**Post date:** [January 26, 2024, 1:23pm UTC](https://discourse.julialang.org/t/latex-strings-do-not-vertically-align-in-plots/109304/1 "2024-01-26T13:23:48Z")

</div>

I’ve noticed that strings containing LaTeX do not vertically align when their contents differ:

```julia
using Plots
using LaTeXStrings
plot(
	[1 2 3], [1 2 3], 
	label=[L"text $g$" L"text $x$" "text"],
	legendcolumn=-1,
)

```

results in

 ![tmp](https://global.discourse-cdn.com/julialang/original/3X/2/9/29ee72a8e81457bbb881f6cc22be2bb57bfd938b.png)

The keyword argument `legend_font_valign` doesn’t change anything. Is there a known workaround, and if not, should I raise a GitHub issue with Plots?

---

<div class="post-metadata">

**Author:** ![devel-chm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/devel-chm/32/3572_2.png) [@devel-chm](https://discourse.julialang.org/u/devel-chm)\
**Post date:** [January 26, 2024, 2:50pm UTC](https://discourse.julialang.org/t/latex-strings-do-not-vertically-align-in-plots/109304/2 "2024-01-26T14:50:09Z")

</div>

Maybe put some vspace into the LaTeX strings?

---

<div class="post-metadata">

**Author:** ![ysfoo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ysfoo/32/51058_2.png) [@ysfoo](https://discourse.julialang.org/u/ysfoo)\
**Post date:** [January 26, 2024, 10:32pm UTC](https://discourse.julialang.org/t/latex-strings-do-not-vertically-align-in-plots/109304/4 "2024-01-26T22:32:25Z")

</div>

Just tried that - I don’t think the command is being recognised. I tried `\vphantom` too.

---

<div class="post-metadata">

**Author:** ![ysfoo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ysfoo/32/51058_2.png) [@ysfoo](https://discourse.julialang.org/u/ysfoo)\
**Post date:** [January 26, 2024, 10:35pm UTC](https://discourse.julialang.org/t/latex-strings-do-not-vertically-align-in-plots/109304/5 "2024-01-26T22:35:30Z")

</div>

Unfortunately, I’ve got plenty of use cases where a horizontal legend makes more visual sense (above is just a MWE).

If my legend is just plaintext (no LaTeX), the baselines do vertically align, where g doesn’t get ‘pushed up’ relative to x. I suppose the question I really should be asking is: why do the baselines not vertically align when LaTeX is present?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 26, 2024, 10:40pm UTC](https://discourse.julialang.org/t/latex-strings-do-not-vertically-align-in-plots/109304/6 "2024-01-26T22:40:55Z")

</div>

Sorry, I misunderstood the question and deleted my reply.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 26, 2024, 11:21pm UTC](https://discourse.julialang.org/t/latex-strings-do-not-vertically-align-in-plots/109304/7 "2024-01-26T23:21:23Z")

</div>

Note that the problem doesn’t seem to occur with the `pythonplot()` backend.

---

<div class="post-metadata">

**Author:** ![ysfoo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ysfoo/32/51058_2.png) [@ysfoo](https://discourse.julialang.org/u/ysfoo)\
**Post date:** [January 27, 2024, 7:29am UTC](https://discourse.julialang.org/t/latex-strings-do-not-vertically-align-in-plots/109304/8 "2024-01-27T07:29:21Z")

</div>

Thank you for the suggestion. Honestly, the number of plotting backends in Julia overwhelms me somewhat (new to Julia here), and I’d rather not have to switch backends whenever I run into an issue with one particular backend.

Aside: I would’ve thought that the default backend is the one that is regularly developed and maintained, but this is yet again adding to the list of “things that don’t work in the default backend”.

Back on topic: Is this issue worth raising on GitHub? I’m not sure if the lack of baseline alignment is a bug, or a fundamental limitation of the GR backend.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 27, 2024, 8:07am UTC](https://discourse.julialang.org/t/latex-strings-do-not-vertically-align-in-plots/109304/9 "2024-01-27T08:07:48Z")

</div>

Many people use Plots.jl for its convenience, but more demanding users prefer Makie.jl, which avoids the problems you face.

There should be related issues in github, so please search before creating a new one.

---

<div class="post-metadata">

**Author:** ![ysfoo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ysfoo/32/51058_2.png) [@ysfoo](https://discourse.julialang.org/u/ysfoo)\
**Post date:** [January 29, 2024, 3:06am UTC](https://discourse.julialang.org/t/latex-strings-do-not-vertically-align-in-plots/109304/10 "2024-01-29T03:06:00Z")

</div>

I’ve given Makie.jl a try, it does seem to have better features. Thanks!

---

<div class="post-metadata">

**Author:** ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)\
**Post date:** [January 29, 2024, 4:28am UTC](https://discourse.julialang.org/t/latex-strings-do-not-vertically-align-in-plots/109304/11 "2024-01-29T04:28:52Z")

</div>

> [@ysfoo](#):
>
> Thank you for the suggestion. Honestly, the number of plotting backends in Julia overwhelms me somewhat (new to Julia here), and I’d rather not have to switch backends whenever I run into an issue with one particular backend.

Honestly you are likely to.  
Being able to change back back-ends is a key feature of Plots.jl  
Its why people use Plots.jl and not GR.jl or PythonPlot.jl directly.  
It means if you find a big like this (which yes, you should report) you can easily swap to another backend while it gets fix.

There are not so many and its not so hard.  
There are fairly well summarised in the docs in the at a glance section  
[https://docs.juliaplots.org/stable/backends/](https://docs.juliaplots.org/stable/backends/)

But even shorter:

- The default backend (GR) is the fastest
- but the PythonPlot backend (i.e. matplotlib) is the most reliable (Its simply been around much longer, and has a bigger team)
- UnicodePlots is good if you need it in plaintext
- Plotly/PlotlyJS is good if you want interactivity like zoom, tooltips etc.

You can just ignore the other 3.

---

<div class="post-metadata">

**Author:** ![tamasgal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamasgal/32/27946_2.png) [@tamasgal](https://discourse.julialang.org/u/tamasgal)\
**Post date:** [January 29, 2024, 7:12am UTC](https://discourse.julialang.org/t/latex-strings-do-not-vertically-align-in-plots/109304/12 "2024-01-29T07:12:07Z")

</div>

I do not really want to make this even more off-topic but I could not resist to add my two cents 😉

I was a big fan of Plots.jl at the very beginning, many years ago, but more and more I realised that the one-fits-all solution does not cut it. Switching backends just because something did not work in one is not a good workaround. Plots will look different and it’s a mess to maintain a script which deals with different backends in the same process. It also happened multiple times that my plots broke or did look different when something was updated (either one of the backends or Plots.jl itself). That was just annoying…

In my opinion the **best plotting library for Julia is PGFPlotsX.jl**.

Yes, it has a very steep learning curve because it uses PGF/TikZ (so technically you have to learn that; the Julia package itself is easy!) and is of course very well integrated in TeX, which you use anyways if you are working in a scientific environment.  
PGFPlotsX.jl itself is just a very thin wrapper which allows you to use the **full PGF/TikZ** feature set, which has an awesome documentation with [almost 600 page PGFPLOTS Documentation](https://ctan.net/graphics/pgf/contrib/pgfplots/doc/pgfplots.pdf). If you are already a bit familiar with PGF/TikZ/TeX, you will have a fun time and easy start 😃  
I often use the [PGFPlots gallery](https://pgfplots.sourceforge.net/gallery.html) and once you get used to the PGFPlotsX abstraction logic, you can translate the examples in seconds to Julia code.

One of the biggest benefits of PGFPlots(X) is the amount of (PGF/TikZ/TeX) examples and discussions out there, no matter which language people are using 😉 The `[tikz-pgf]` tag on [tex.stackexchange.com](http://tex.stackexchange.com) has more than 34000 questions. Compare that to `[makie-jl]` with slightly more than 52 or `[plots.jl]` with about 200. This is not a surprise, given that PGF is almost 20 years old; and builds upon even older pillars.

Anwyas, Makie.jl (well, to be exact CairoMakie.jl and GLMakie.jl) is my second choice, mostly when it comes to interactivity or rendered 3D visualisations. Makie is great for teaching and it’s as easy to use as Plots.jl

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 29, 2024, 7:59am UTC](https://discourse.julialang.org/t/latex-strings-do-not-vertically-align-in-plots/109304/13 "2024-01-29T07:59:39Z")

</div>

For people who don’t have time, don’t work in research or write scientific publications, but need simple language with short keyword aliases to get some data QC job done, Plots.jl is often perfect.

By the way, the `pgfplotsx()` backend also has no problems with your example:

 ![Plots_pgfplotsx_LaTeXStrings_legend_text_alignment](https://global.discourse-cdn.com/julialang/original/3X/b/7/b7b480aa403fc753ed580064dbabc2798a04202f.png)
