# Aligning Multi-line Text (in Makie)

**URL:** <https://discourse.julialang.org/t/aligning-multi-line-text-in-makie/93012>\
**Category:** Visualization\
**Tags:** makie, glmakie\
**Created:** [January 16, 2023, 6:48am UTC](https://discourse.julialang.org/t/aligning-multi-line-text-in-makie/93012 "2023-01-16T06:48:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Whyborn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/whyborn/32/34755_2.png) [@Whyborn](https://discourse.julialang.org/u/Whyborn)\
**Post date:** [January 16, 2023, 6:48am UTC](https://discourse.julialang.org/t/aligning-multi-line-text-in-makie/93012/1 "2023-01-16T06:48:18Z")

</div>

Hi,

Is it possible to do multiline text alignment in Makie plots LaTeX equation style? For example, describing some fluid conditions, I would like to write text something like:

```julia
text!(ax, location, text = "p=100kPa\nT=300K\nRe_inf=1e6")

```

but align the text at the “=” sign. In a LaTeX environment you can align using the & symbol, but I haven’t been able to work it out using regular text or LaTeXStrings.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [January 16, 2023, 8:48am UTC](https://discourse.julialang.org/t/aligning-multi-line-text-in-makie/93012/2 "2023-01-16T08:48:47Z")

</div>

This doesn’t exist yet and should probably be handled by MathTeXEngine.jl. I encourage you to open an issue in that repository if one doesn’t exist already.

Maybe I can help you with some hacky workaround code, though. You can offset each text in a vector of texts separately, and you can find out how much to offset by going into the GlyphCollections in the lower layer of the plot object and finding out where the first `=` is placed:

```julia
fig, ax, t = text([1, 1, 1], [1, 1, 1],
    text = [
        L"x = y",
        L"x/y = 1",
        L"\sum{x} = x \times y",
    ],
    offset = [
        Vec2f(0, 0),
        Vec2f(0, -50),
        Vec2f(0, -100),
    ],
    fontsize = 25
)
gc_obs = t.plots[1][1]
gcs = gc_obs[]
eq_offsets = map(gcs) do gc
    idx = findfirst(1:length(gc.glyphs)) do i
        Makie.FreeTypeAbstraction.glyph_index(gc.fonts[i], '=') === gc.glyphs[i]
    end
    idx === nothing && error("Didn't find a '=' in a glyphcollection.")
    return gc.origins[idx][1]
end
max_offset = maximum(eq_offsets)
new_offsets = max_offset .- eq_offsets
t.offset[] = [Vec2f(n, y) for (n, (x, y)) in zip(new_offsets, t.offset[])]
fig

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/9/5/95f83be4ab255112bbdd3a4241cc82a0b84dc3ee.png)

This is just a proof of concept, the alignment would need to be adjusted as well and made automatic, but that’s how one could do it. The data structures used could also change at any time, they are not stable API.

---

<div class="post-metadata">

**Author:** ![Whyborn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/whyborn/32/34755_2.png) [@Whyborn](https://discourse.julialang.org/u/Whyborn)\
**Post date:** [January 17, 2023, 4:44am UTC](https://discourse.julialang.org/t/aligning-multi-line-text-in-makie/93012/3 "2023-01-17T04:44:32Z")

</div>

Thanks for the response, that code snippet worked perfectly for aligning the text. Unfortunately it seems to break the positioning of the text, I’ll see if I can work out why.

The MathTexEngine Github specifies that line breaks/wraps are currently not supported in in-line mode, but it looks like there’s a currently open issue on the matter.
