# In table cell, how to break long words after “::” or “_”?

I have a software program can generate tables which may be very long and may contains words with many letters,so i use longtabu package. Some words may look like this:

AAA_BBB_CCCC_DDDDD_CC

aaa::Asldfjasldfjlasdfjasld

So I use \allowbreak\_ and \allowbreak\:: to break the long words in certain table cell. But the problem is, if the word after underscore or colon is too long, it can not be breaked. Longtabu can break long words, but not words after underscore or colon... And these long words are generated by software program, I can not add any break by hand.

So how to break it? Below is the code and pdf.

\documentclass[a4paper,leqno,twoside]{article}
\usepackage[utf8]{inputenc}

\title{dd}

\usepackage{tabu}
\usepackage{longtable}
\usepackage{supertabular}
\usepackage{hyperref}
\begin{document}

\maketitle

\section{Introduction}

\subsection{asdf asdfasf asdfasd}

\begin{longtabu} to \textwidth {|>{\footnotesize}X[1 , p ] |>{\footnotesize}X[1 , p ] | >{\scriptsize}X[1 , p ]| >{\footnotesize}X[2 , p ]|>{\footnotesize}X[1 , p ]|>{\footnotesize}X[1 , p ]|}

\caption{asdf asfas}\\

\hline

\textbf{aaaaaa;\newline asdfasd} & \textbf{asdfasdf;\newline asdfasdf;\newline asdfasdf;\newline asdfa;\newline asdfasdfasfasfasdf\newline} & \footnotesize\textbf{asdfasdfas} & \textbf{asdfasdfs} & \textbf{asdfasdf;\newline asdfasdfasdf asdf asdfas} & \textbf{asdfasdfasd} \\

\hline

&&&\\\hline

\end{longtabu}

\end{document}


• Isn't this a similar question like this, from your obviously 2nd account: tex.stackexchange.com/questions/197958/…?
– user31729
Aug 27 '14 at 21:18
• Not relevant to the question, but if you have two accounts please ask the StackExchange staff to do a merge Aug 27 '14 at 21:20
• @ChristianHupfer The reason I write it again, because you said i need post a code. Now i post it here, the old question you can delete it. Aug 27 '14 at 21:23
• @postit: The annoying thing is, that you continously use two accounts ;-)
– user31729
Aug 27 '14 at 21:24
• @ChristianHupfer, because I changed the computer, then the account is changed(eventhough the same name), which i did not expect it Aug 27 '14 at 21:26

You need to make TeX think it is starting a new word after these breaks so that allows hyphenation of the following part. \hspace{0pt} will accomplish such a break. It is best to collect your code for this in to custom commands for the behaviour you wish to allow at the given punctuation mark:

\documentclass[a4paper,leqno,twoside]{article}
\usepackage[utf8]{inputenc}

\title{dd}

\usepackage{tabu}
\usepackage{longtable}
\usepackage{supertabular}
\usepackage{hyperref}

\newcommand{\uscbr}{\allowbreak\_\allowbreak\hspace{0pt}}
\newcommand{\ccbr}{\allowbreak::\hspace{0pt}}

\begin{document}

\maketitle

\section{Introduction}
There is a story

\subsection{asdf asdfasf asdfasd}

\begin{longtabu} to \textwidth {|>{\footnotesize}X[1 , p ] |>{\footnotesize}X[1 , p ] | >{\scriptsize}X[1 , p ]| >{\footnotesize}X[2 , p ]|>{\footnotesize}X[1 , p ]|>{\footnotesize}X[1 , p ]|}

\caption{asdf asfas}\\

\hline

\textbf{aaaaaa;\newline asdfasd} & \textbf{asdfasdf;\newline asdfasdf;\newline asdfasdf;\newline asdfa;\newline asdfasdfasfasfasdf\newline} & \footnotesize\textbf{asdfasdfas} & \textbf{asdfasdfs} & \textbf{asdfasdf;\newline asdfasdfasdf asdf asdfas} & \textbf{asdfasdfasd} \\

\hline

\hypertarget{ABCDoABCoABCDoABCDDoABBoE}{ABCD\uscbr ABC\uscbr
ABBVASDFASDDDD\uscbr ABC\uscbr ABC\uscbr A}&&Caa:: CaaaaaaaBddddd\ccbr