# How to center a text with Luxor

**URL:** <https://discourse.julialang.org/t/how-to-center-a-text-with-luxor/55125>\
**Category:** Visualization\
**Tags:** question, luxor\
**Created:** [February 12, 2021, 8:33am UTC](https://discourse.julialang.org/t/how-to-center-a-text-with-luxor/55125 "2021-02-12T08:33:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [February 12, 2021, 8:33am UTC](https://discourse.julialang.org/t/how-to-center-a-text-with-luxor/55125/1 "2021-02-12T08:33:46Z")

</div>

I am trying to create simple images with a text made of a few digits on the center.  
The problem is that I need to manually offset the position, is there a way to make it “centered” in a visual sense, i.e. where the span from the extreme of the digit and the border is thesame in the 4 directions ?

I have tried so far the above snippet:

```julia
using Luxor

Drawing(300, 300, "hello-world.png")
origin()
background("white")
fontface("Avenir-Black")
fontsize(160)
sethue("red")
textcentered("123", 0, 0)
sethue("black")
text("123",Point(-17, 60), halign=:center,valign=:center)
finish()
preview()

```

This results in the following image, where you can see that the the red text is not centered, and I have to manually adjust it:  
 ![hello-world](https://global.discourse-cdn.com/julialang/original/3X/3/c/3c63fba302d0c5fd21a768bf092998a6d9289fa6.png)

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [February 12, 2021, 10:04am UTC](https://discourse.julialang.org/t/how-to-center-a-text-with-luxor/55125/2 "2021-02-12T10:04:43Z")

</div>

Fonts aren’t perfectly aligned - I often nudge them to optically align them:

 ![Screenshot 2021-02-12 at 10.03.24](https://global.discourse-cdn.com/julialang/original/3X/2/b/2bbfa70d50008d5069b6abbddd5cc608324efb8a.png)

(also, it’s `valign=:middle`.)

---

<div class="post-metadata">

**Author:** ![dcastel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dcastel/32/10692_2.png) [@dcastel](https://discourse.julialang.org/u/dcastel)\
**Post date:** [July 13, 2021, 6:54am UTC](https://discourse.julialang.org/t/how-to-center-a-text-with-luxor/55125/3 "2021-07-13T06:54:38Z")

</div>

I was really wondering about an improved solution for this as well. Glad to see I wasn’t the only one struggeling. 🙂

![Screenshot 2021-07-12 at 21.23.27](https://global.discourse-cdn.com/julialang/original/3X/a/a/aaf0dade6875def9e780d932a044f43db6e05da9.png)

But furthermore I’m still curious as to how the placement works because I get this weird placement also with monospaced fonts:

![Screenshot 2021-07-13 at 08.52.25](https://global.discourse-cdn.com/julialang/original/3X/2/b/2b63b7187e9a40441e30896045d96bf3b6457de9.png)

Could I maybe create a consistent bordered text by splitting the word up in letters and positioing those seperately? 🤔

I might dive into trying that in a bit because I’d like to finish this logo I’m making. 🙂

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [July 13, 2021, 7:51am UTC](https://discourse.julialang.org/t/how-to-center-a-text-with-luxor/55125/4 "2021-07-13T07:51:27Z")

</div>

I think this is a different issue from the original poster, who needed to use the correct keyword. I think you might be after “text as path”, converting text to graphic paths so that you can fill and stroke them separately? (documentation [here](http://juliagraphics.github.io/Luxor.jl/stable/howto/text/#Text-to-paths)).

 ![Screenshot 2021-07-13 at 08.39.55](https://global.discourse-cdn.com/julialang/original/3X/c/1/c10b1347c3825b028aed0f33905429a1aaeec3a7.png)

```julia
@draw begin
    fontsize(100)
    fontface("Avenir-Black")
    sethue("black")
    textoutlines("Wormhole", O, :fillpreserve, halign=:center)
    sethue("red")
    setline(3)
    strokepath()
end

```

Splitting the text up into separate letters is straightforward - use `textextents()` to get the dimensions of each character. If you look at the code for `textcurve()` you get an idea of how to do it:

 ![Screenshot 2021-07-13 at 08.48.54](https://global.discourse-cdn.com/julialang/original/3X/2/1/214d9789a6903b55883f78a18c317d0a3cf36658.jpeg)

---

<div class="post-metadata">

**Author:** ![dcastel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dcastel/32/10692_2.png) [@dcastel](https://discourse.julialang.org/u/dcastel)\
**Post date:** [July 18, 2021, 8:22am UTC](https://discourse.julialang.org/t/how-to-center-a-text-with-luxor/55125/5 "2021-07-18T08:22:14Z")

</div>

A nice that solves simply. Thanks again cormullion. 🙂
