# Printing columns

**URL:** <https://www.ruby-forum.com/t/printing-columns/143194>\
**Category:** Ruby\
**Created:** [July 16, 2008, 6:55am UTC](https://www.ruby-forum.com/t/printing-columns/143194 "2008-07-16T06:55:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mariachi77](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d2c977/32.png) [@mariachi77](https://www.ruby-forum.com/u/mariachi77)\
**Post date:** [July 16, 2008, 6:55am UTC](https://www.ruby-forum.com/t/printing-columns/143194/1 "2008-07-16T06:55:52Z")

</div>

I’m trying to print some data to the terminal in columns and haven’t  
seen a way to do it properly. I’ve tried “fred”.center(80) to try and  
center the text at column 80 but when I start entering data before  
“fred” it starts to push “fred” over to the right.

Is there a way to print at a specific column regardless of what text is  
on the same line before hand or after?

---

<div class="post-metadata">

**Author:** ![mariachi77](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d2c977/32.png) [@mariachi77](https://www.ruby-forum.com/u/mariachi77)\
**Post date:** [July 16, 2008, 6:58am UTC](https://www.ruby-forum.com/t/printing-columns/143194/2 "2008-07-16T06:58:09Z")

</div>

I just worked it out, I was using a + instead of the proper , to  
separate my text.

EG:  
wrong way  
print “hi” + “fred”.center(80)

proper way  
print “hi”, “fred”.center(80)

Michael Pope wrote:

> I’m trying to print some data to the terminal in columns and haven’t  
> seen a way to do it properly. I’ve tried “fred”.center(80) to try and  
> center the text at column 80 but when I start entering data before  
> “fred” it starts to push “fred” over to the right.
> 
> Is there a way to print at a specific column regardless of what text is  
> on the same line before hand or after?

---

<div class="post-metadata">

**Author:** ![mariachi77](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d2c977/32.png) [@mariachi77](https://www.ruby-forum.com/u/mariachi77)\
**Post date:** [July 16, 2008, 7:11am UTC](https://www.ruby-forum.com/t/printing-columns/143194/3 "2008-07-16T07:11:17Z")

</div>

Michael Pope wrote:

> I’m trying to print some data to the terminal in columns and haven’t  
> seen a way to do it properly. I’ve tried “fred”.center(80) to try and  
> center the text at column 80 but when I start entering data before  
> “fred” it starts to push “fred” over to the right.
> 
> Is there a way to print at a specific column regardless of what text is  
> on the same line before hand or after?

Use an excape char sequence to move forward?

$ ruby -e ‘print “0123456789”\*8; print “\r”; puts  
“fred”.center(80).gsub(" ", “\e[C”)’  
01234567890123456789012345678901234567fred23456789012345678901234567890123456789
