Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fixed-width table on non-fixed-width environment 1

Status
Not open for further replies.

Sleidia

Technical User
May 4, 2001
1,284
FR


Hi guys :)

I have this text string :

Code:
|-----------------------------------------------------------------------------------|
|         Date d'hebergement  |        Saison  |  Prix de la nuitee  |  Sous-total  |
|-----------------------------------------------------------------------------------|
|     Jeudi 20 Decembre 2007  |  Basse saison  |         105         |     105      |
|-----------------------------------------------------------------------------------|
|  Vendredi 21 Decembre 2007  |  Basse saison  |         67          |     135      |
|-----------------------------------------------------------------------------------|
|    Samedi 22 Decembre 2007  |  Haute saison  |         75          |     225      |
|-----------------------------------------------------------------------------------|
|  Dimanche 23 Decembre 2007  |  Haute saison  |         75          |     300      |
|-----------------------------------------------------------------------------------|
|                             |                |       Total :       |   300 eur.   |
|-----------------------------------------------------------------------------------|

But inside an email, it looks like this :

|-----------------------------------------------------------------------------------|
| Date d'hebergement | Saison | Prix de la nuitee | Sous-total |
|-----------------------------------------------------------------------------------|
| Jeudi 20 Decembre 2007 | Basse saison | 105 | 105 |
|-----------------------------------------------------------------------------------|
| Vendredi 21 Decembre 2007 | Basse saison | 67 | 135 |
|-----------------------------------------------------------------------------------|
| Samedi 22 Decembre 2007 | Haute saison | 75 | 225 |
|-----------------------------------------------------------------------------------|
| Dimanche 23 Decembre 2007 | Haute saison | 75 | 300 |
|-----------------------------------------------------------------------------------|
| | | Total : | 300 eur. |
|-----------------------------------------------------------------------------------|



The question is : in what way should I edit this table in order to have
it keep almost the same appearance when displayed with a non-fixed-width font?
Using _ instead of - does help but it's not perfect.

Thanks for the help!
 
put the table inside <pre></pre> tags

or use a fixed width font.
make sure that all spaces are non-breaking too

you might also want to use html tables since this will be an html email problem, i'll wager.
 

Hi Jpadie, :)

I intend to make it only text formatted mail, not HTML.
So, tags are out of question.

So, if I understand well, if the recipient doesn't have
a fixed font set up by defaut on his mail client, the table
would never look good?

No turn around?
 
i think that's right, yes. but it's bizarre to have a text email reader without a fixed font, no?

and some clients will view the mail in an html mail reader. so it might be better to send multipart with properly formatted html.
 
By default it's a proportional font that is set up on Outlook.
I bet most Outlook users never saw a fixed-width font.

And, viewing mails with HTML formatting on doesn't prevent a text-only mail from being read, so I don't get what you're trying to say :(

Yes, I could send as HTML mail but I would like to have the table displayed properly when the recipient settings are :
Text only + proportional font.

Damn, I hate computers so much today :(
 
And, viewing mails with HTML formatting on doesn't prevent a text-only mail from being read, so I don't get what you're trying to say :(

what i meant was that if the client was html aware, you could ensure good formatting by sending a multipart email and this would not prejudice (and worse than currently) a text email and a text client.

just a thought, but rather than spaces, could you use a tab to create a semblance of alignment? i think it would be only left alignment achievable here. i don't know what tabstops are typically assumed by email clients though.
 
Just an update in order to share the solution I found the best.

I chose to use PHPMAILER and to make it send an HTML mail
with the whole content enclosed in <pre></pre>
The alternate content is simply the html version with tags
removed. Attached to the messge is the html file with the <pre> tags.

Thus, whenever the mail client is in plain text mode or html
mode, the user can view the table perfectly shaped inside the
<pre> tags.
 
You could also have made a applyPadding() function which would pad the shorter strings with &nbsp; x sizediff from the longer one.

eg:

"This string is long"
"***short string****"

Where * would be &nbsp;

This would give you a clear text, but you might still have font issues :S

Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top