Auto line break with very long word within table
You could load the xurl
package and encase the long number in a \url{...}
"wrapper".
(The following code uses a tabularx
environment since I'm not familiar with longtabu
.)
\documentclass{article}
\usepackage{tabularx,xurl}
\urlstyle{same}
\begin{document}
\noindent
\begin{tabularx}{\textwidth}{@{} lX @{}}
\hline
\textbf{Head 1} & \textbf{Head 2} \\
\hline
12:18:52 & this is a description for the event \\
\hline
12:18:52 &
\url{11111111111111111111111111111111111111222222222222222222222222222222222222222223333333333333333333333333333333333344444444444444444444455555555555555555555555555555555666666666666666666666666666777777777777777777777778888888888888888}\\
\hline
\end{tabularx}
\end{document}
Another solution with seqsplit
, xltabular
, which combines the functionalities of longtable
and tabularx
, and makecell
to define some vertical padding of cells in the table:
\documentclass{article}
\usepackage{seqsplit, makecell, xltabular}
\begin{document}
{\setcellgapes[b]{3pt}
\setcellgapes[t]{2pt}\makegapedcells
\noindent\begin{xltabular}{\textwidth}{|c|X|}%|
\hline
\textbf{Head 1} &
\textbf{Head 2}
\\ \hline
12:18:52 & this is a description for the event \\\hline
12:18:52 & this is a description for the event \\\hline
12:18:52 & this is a description for the event this is a description for the event this is a description for the event this is a description for the event this is a description for the event this is a description for the event this is a description for the event this is a description for the event this is a description for the event this is a description for the event this is a description for the event this is a description for the event this is a description for the event this is a description for the event this is a description for the event this is a description for the event this is a description for the event this is a description for the event \\\hline
12:18:52 & \seqsplit{ 111111111111111111111111111111111111112222222222222222222222222222222222222222233333333333333333333333333333333333444444444444444444444%
55555555555555555555555555555555666666666666666666666666666777777777777777777777778888888888888888} \\\hline
\end{xltabular}}
\end{document}
The problem is that the number is not in the list of words that tex uses to determine possible break points of words, but one can manually add them by placing \-
at each point where the number can be broken across lines:
\documentclass{article}
\usepackage[english]{babel}
\begin{document}
\begin{tabular}{|p{1cm}|p{5cm}|}
This text will be wrapped & Some more text \\\hline
this & 1\-111\-111\-1111\-111\-111\-11\-111\-111\-111\-111\-111\-111\-122\-22\-222\-22\-222\-22\-22\-222\-22\-22\\\hline
\end{tabular}
\end{document}