Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
    
A tip: If you indent lines by 4 spaces or enclose words in backticks `, they'll be marked as code, as can be seen in my edit. You can also highlight the code and click the "code" button (with "{}" on it). –  hpesoj626 Oct 18 '12 at 7:26
add comment

1 Answer

up vote 10 down vote accepted

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.)

share|improve this answer
    
This seems to be a legit solution -- Heiko Oberdiek recommended it: tex.stackexchange.com/a/67764/4012 –  doncherry Oct 18 '12 at 7:35
    
I assume this is because the hspace now counts as the first "word" in the paragraph? I am looking at a similar situation, but I don't know beforehand what text is going to go in the table (Data generated through a script). Is there a way to globally change the hyphenation rule to include first words, or do so for the duration of a table? Throwing \hspace{0pt} in front of every single cell seems...ugly. –  Eric Oct 19 '12 at 16:32
    
@Eric I agree, but I don't know. Sounds like a good question to ask here on tex.sx: How can I globally enable hyphenation for the first word in a paragraph? –  doncherry Oct 19 '12 at 18:11
    
@Eric You might not need this solution anymore, but I added a way of adding the \hspace{0pt} in front of every cell automatically. –  doncherry Apr 8 '13 at 1:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.