I have such table:

\begin{tabularx}{\textwidth}{ |p{0.5cm}|X|p{1cm}|p{0.8cm}|p{1.1cm}|p{0.9cm}|p{0.9cm}|p{1.2cm}|p{0.9cm}|p{0.9cm}|p{1.5cm}| }                                                                                                                  
    No. & Compound & Storage place & Shelf & Number & Calc mol & Cacl wt & Calc amount & Real mol & Real wt & Real amount \\                                                                                                                 
    1 & lasdsdasdasdasdasddasdllasfsdjfsd & Lab1 & 2 & 355235 & 85.000 & 92.006 & 1.33620 & 85.000 & 92.006 & 1.33620 g \\                                                                                                                   

How to wrap long word in second column? I would like to have table where text never ever overflow.

What I have now is:

enter image description here

What I would like to have:

enter image description here

Note: I'm using xelatex as compiler, I dont know if it makes difference.

  • 3
    First your table is too wide to fit in. Second, you may use \hspace{0pt} lasdsdasdasdasdasddasdllasfsdjfsd so that the long word is hyphenated. TeX doesn't hyphenate the first word. When you add \hspace{0pt}, you trick TeX to treat the long word as not the first word. – user11232 Aug 28 '14 at 9:53
  • @HarishKumar - I doubt that there are any hyphenation rules that provide sensible guidance regarding the hyphenation of the remarkable string "lasdsdasdasdasdasddasdllasfsdjfsd"... – Mico Aug 28 '14 at 9:58
  • 1
    @Mico TeX hypheantes "lasdsdasdasdasdasddasdllasfsdjfsd" but, no rules followed ;-) – user11232 Aug 28 '14 at 10:01
  • @HarishKumar - great, works as intended. Please post your answer so I can accept it. – marxin Aug 28 '14 at 10:14

Converting the comment into answer.

TeX doesn't hyphenate the first word. You can add \hspace{0pt}, and trick TeX to treat the long word as not the first word. Using \hspace{0pt} lasdsdasdasdasdasddasdllasfsdjfsd should do the job in the present case.

You may prefer to put it in the column definition itself like >{\hspace{0pt}}X thereby avoiding its specification in (each) cell.

  • 1
    >{\hspace{0pt}}X for the second column should avoid the need of specifying it explicitly in the cell. – egreg Aug 28 '14 at 10:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.