[Tex/LaTex] How does LaTeX make line-breaking for word that can not fit in cell

line-breakinglongtabletables

Often in my tables LaTeX doesn't want to line-break a word that can not fit in a cell.

How I can teach it to split such a word?

As you can see in my example below the same word in some cases will be split, in another cases not.

I want to teach LaTeX to split all words (that can not fit on the page) automatically.

Can you help me?

Some example:

\begin{longtable}{|p{0.1\textwidth} | p{0.3\textwidth}|} \hline
Text                       & Remarks   \\ \hline
new zoogeographical region &           \\ \hline
zoogeographical region     &           \\ \hline
\end{longtable}

enter image description here

Best Answer

The issue seems to be that LaTeX doesn't hyphenate the first word in a paragraph. I don't know if there's a way to enable that globally, but in your case, adding \hspace{0pt} without a space afterwards solves the issue:

\documentclass{article}
\usepackage{longtable}

\begin{document}
\begin{longtable}{|p{0.1\textwidth} | p{0.3\textwidth}|} \hline
Text                       & Remarks   \\ \hline
new zoogeographical region &           \\ \hline
\hspace{0pt}zoogeographical region     &           \\ \hline
\end{longtable}
\end{document}

output


To automate this process and apply \hspace{0pt} to every cell (in a column) to simplify automated table generation, you can use the >{...} syntax from the array package, which adds ... to the beginning of every cell in the respective column. Here are the lines I had to change/add in comparison to the MWE above.

...
\usepackage{array}
...
\begin{longtable}{|>{\hspace{0pt}}p{0.1\textwidth} | p{0.3\textwidth}|} \hline
...

(The output looks the same.)