# Different x starting position of text

**URL:** https://discourse.processing.org/t/different-x-starting-position-of-text/27308
**Category:** Coding Questions
**Created:** [January 23, 2021, 4:23pm UTC](https://discourse.processing.org/t/different-x-starting-position-of-text/27308 "2021-01-23T16:23:53Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Ida](https://avatars.discourse-cdn.com/v4/letter/i/ed655f/32.png) [@Ida](https://discourse.processing.org/u/Ida)
#### Post date: [January 23, 2021, 4:23pm UTC](https://discourse.processing.org/t/different-x-starting-position-of-text/27308/1 "2021-01-23T16:23:53Z")

</div>

Hey,  
My code draws a text line by line to the screen in different sizes, but the lines seem to start at a different x position according to the text size. Also the first line begins at a different x position. Could somebody explain me why this is happening and how I could change that?

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/9/91ac71d26c418702f6b6575769c963c8a2af3183.png)  
Many thanks in advance!

```auto
PFont font;

String [] lines;
int index = 0;
int xvalue;

void setup() {
  size(600, 400);
  font = createFont("UtopiaStd-Regular", 20);

  String everything; 
  everything = "Hab’ ich mich nicht an den ganz historischen Energien der Umwelt, die uns so ausgiebig zu lachen machten, so wenig begrenzt sie waren, selbst ergetzt? Hab’ ich nicht – o was gibt der Einzelne, daß er über sich schimpfen darf! Ich will, lieber Freund, ich verspreche dir’s ich will mich stärken, will nicht mehr ein bißchen Elend, das uns das Einverständnis vorlegt, wiederholen wie ich’s immer getan habe; ";
  lines = splitTokens(everything, ",.?!;:");
  textFont(font);
  frameRate(2);
}

void draw() {
  background(0);
  int y=7; 
  int x = 10;
  for (int index=0; index<lines.length; index++) {
        if(random(100) > 50){
     xvalue=20;
}
else {
    xvalue = 40;   
}
    textSize(xvalue);
    float a1= textAscent() + textDescent(); 
    y+=a1;
    text(lines[index], x, y);    
  }
  noLoop();
}
void keyPressed() {
  redraw();
}

```

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [January 23, 2021, 4:59pm UTC](https://discourse.processing.org/t/different-x-starting-position-of-text/27308/2 "2021-01-23T16:59:29Z")

</div>

I think it’s because the first letter in the line is ’ ’ (space).

Check with `if( lines[index].charAt(0) == ' ') println("space");`

if so remove the first sign

---

<div class="post-metadata">

### Author: ![Ida](https://avatars.discourse-cdn.com/v4/letter/i/ed655f/32.png) [@Ida](https://discourse.processing.org/u/Ida)
#### Post date: [January 23, 2021, 5:22pm UTC](https://discourse.processing.org/t/different-x-starting-position-of-text/27308/3 "2021-01-23T17:22:01Z")

</div>

Yes this explains why the first word starts at a different position!  
Thank you 🙂

Do you know how I could say, that all lines with text size = 40 start for example at x= -10? To also compensate the optical difference of the starting point?

Kind regards,  
Ida

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [January 23, 2021, 5:50pm UTC](https://discourse.processing.org/t/different-x-starting-position-of-text/27308/4 "2021-01-23T17:50:40Z")

</div>

Hello,

To cut the first letter away look at: [substring() / Reference / Processing.org](https://www.processing.org/reference/String_substring_.html)

or use trim() command:

` text(lines[index].trim(), x, y);`

Then your question isn’t necessary anymore. [all lines with text size = 40 start for example at x= -10?]

* * *

**Your Question**

> [@Ida](#):
>
> Do you know how I could say, that all lines with text size = 40 start for example at x= -10?

in the part of the if-clause where you say xvalue = 40 add in your code: x= -10

Are you in a class with Sophie?

Warm regards,

Chrisir

* * *

**Full Code:**

The full code uses trim() AND x= -10 which doesn’t make sense…

```auto

PFont font;

String [] lines;
int index = 0;
int xvalue;

void setup() {
  size(600, 400);
  font = createFont("UtopiaStd-Regular", 20);

  String everything; 
  everything = "Hab’ ich mich nicht an den ganz historischen Energien der Umwelt, die uns so ausgiebig zu lachen machten, so wenig begrenzt sie waren, selbst ergetzt? "
    +"Hab’ ich nicht – o was gibt der Einzelne, daß er über sich schimpfen darf! Ich will, lieber Freund, ich verspreche dir’s ich will mich stärken, will nicht mehr ein bißchen Elend, das uns das Einverständnis vorlegt, "
    +"wiederholen wie ich’s immer getan habe; ";
  lines = splitTokens(everything, ",.?!;:");
  textFont(font);
  frameRate(2);
}

void draw() {
  background(0);
  int y=7; 
  int x = 10;
  for (int index=0; index<lines.length; index++) {
    if (random(100) > 50) {
      xvalue=20;
    } else {
      xvalue = 40;
      x=-10;
    }
    textSize(xvalue);
    float a1= textAscent() + textDescent(); 
    y+=a1;
    text(lines[index].trim(), x, y);
  }
  noLoop();
}
void keyPressed() {
  redraw();
}
//

```
