1

I use longtabu package for creating tables, because the table can be very long (several pages) and i need automatic linebreak(or wordbreak) if the sentence(or a single word) in certain cell is too long.

In most cases, longtabu works well for my purpose. But, if a long word contains underscore, for example, AAA_BB_CCC_D_EEEEEE_FFF_GGGGG_HHHHHH (I replace _ as \\_ in latex), then the word can not be linebreaked and it cross out of the border of the cell to the next cell.

How can longtabu automatically break a long word with underscore? I want the very long word can automatically fit the length of a cell.

postit
  • 385

2 Answers2

1

You can add some potential breaking points to the long word by adding \- (if you want a hyphen when breaking} or \allowbreak (if you don't).

Examples

\fbox{\parbox[b]{5cm}{AAA\_BB\_CCC\_D\_EEE\-EEE\_FFF\_GGGGG\_HHHHHH}}
\fbox{\parbox[b]{5cm}{AAA\_BB\_CCC\_D\_EEEEEE\allowbreak \_FFF\_GGGGG\_HHHHHH}}

resulting in

enter image description here

more information at this related question

Harald
  • 1,349
1

You can also have a look at the hyphenat package which redefines the underscore \_ so that hyphenation can automatically occur. This adds a hyphen at the end of the line. This has the advantage that you don't have to manually add \- in every word with an underscore.

\documentclass[a4paper]{article}
\usepackage{hyphenat}

\begin{document}
\fbox{\parbox[b]{5cm}{AAA\_BB\_CCC\_D\_EEEEEE\_FFF\_GGGGG\_HHHHHH}}
\end{document}