I have data (generated from a database, not manually typed in) that mostly fits into a table cell with fixed width, but sometimes overflows because there are long words for which no hyphenation is found.

The problem can be demonstrated with the following example:

1 & Cell where normal hyphenation is possible ÄÖÜ \\
2 & CellwherenormalhyphenationisnotpossiblebutshouldwrapinsteadofoverflowÄÖÜ

My requirements are:

  1. Text never overflows the cell (assuming some minimum width such that at least a handful characters have place)
  2. First priority measure to achieve 1. is the normal hyphenation
  3. If 2. fails, it is allowed to break the word at any character, so fill the line and break just before overflow would happen (disregarding normal hyphenation rules)

In the example, the overflow in cell 1 is prevented by measure 2., the normal hyphenation. The second cell overflows. I would like to have this cell treated by measure 3.

For the answer please consider:

  • Package seqsplit didn't help me
  • The custom macro \wrap proposed in the answer to seqsplit - keep spaces comes near my wish, but can't handle the non-ascii characters ÄÖÜ (independent if they are input with utf8 input encoding or with \"A\"O\"U)
  • As the text comes from a database, no manual editing of the cell content is wanted.

One of my ideas was to insert \linebreak[0] after every character, to tell LaTeX that a break can be made if no better opportunities exist. But this doesn't work like intended.

Thanks for your suggestions!

  • I suspect you need to play with the penalties and glue. Commented Oct 14, 2014 at 15:39

2 Answers 2


You can make a trial setting , see if you have any over large boxes, then if so loop through character by character adding \penalty0 and re-set.

enter image description here

   \ifdim\wd\z@>\dimexpr\hsize+4pt\relax% compensate for hfuzz and not checking for shrink


\else\ifcat\noexpand\tmp\active% only active character utf8 chars

\def\foowrap@sp{\afterassignment\foowrap@\let\tmp= }



1 & \foo{Cell where normal hyphenation is possible ÄÖÜ}\\
2 & \foo{CellwherenormalhyphenationisnotpossiblebutshouldwrapinsteadofoverflowÄÖÜ}


You can use \text_map_inline:nn that respects Unicode characters.


  \hspace{0pt plus 1fil}% add a filling space
  \hspace{0pt plus -1fil}% remove the filling space

  \text_map_inline:nn { #1 } { ##1\breakandspace }

1 & Cell where normal hyphenation is possible ÄÖÜ \\
2 & \longcell{CellwherenormalhyphenationísnotpossiblébutshöuldwrapinsteadofoverflowÄÖÜ}

enter image description here

(See history for an older answer)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .