22

I try to make XeLaTeX hyphenate the German word "Sicherheitsbeauftragter". I tried several values for x in \tolerance=x and instances of \hyphenation{Si-cher-heits-be-auf-trag-ter}. Nothing worked. MWE:

\documentclass{article}
\usepackage{polyglossia}
\setmainlanguage{german}
\usepackage{array}
\usepackage{ragged2e}
\hyphenation{Si-cher-heits-be-auf-trag-ter} 
\begin{document}
\begin{tabular}{>{\RaggedRight}p{7.7em}@{|}}
Sicherheitsbeauftragter\\
Technischer Leiter
\end{tabular}
\end{document}

Screenshot of hyphenation not working

I also tried babel instead of polyglossia and pdfLaTeX instead of XeLaTeX but except for how the "|" looks, there is no difference.

2 Answers 2

20

\hspace{0pt} right before Sicherheitsbeauftragter allows TeX to break the word, because TeX does not hyphenate the first word in a paragraph. (AFAIK this had made the implementation easier and in English with the many short words, it wasn't much of a problem.)

Since the \hspace inserts a break point at this place, this can be avoided by \nobreak in horizontal mode:

\leavevmode\nobreak\hspace{0pt}Sicherheitsbeauftragter

Or the star form of \hspace can be used:

\hspace*{0pt}Sicherheitsbeauftragter

This can be automated (see Herbert's comment) in the column description:

\begin{tabular}{>{\RaggedRight\hspace*{0pt}}p{7.7em}@{|}}
6
  • Also \selectlanguage{german} should be issued before \hyphenation or, maybe preferably, the command should be between \begin{otherlanguage*} and \end{otherlanguage*}.
    – egreg
    Apr 13, 2013 at 18:05
  • @egreg The OP has used \setmainlanguage{german} (package polyglossia). Apr 13, 2013 at 18:08
  • or use \begin{tabular}{>{\RaggedRight\hspace{0pt}}p{7.7em}@{|}}
    – user2478
    Apr 13, 2013 at 18:08
  • @HeikoOberdiek Try adding \showthe\language just before \hyphenation, you'll get 0.
    – egreg
    Apr 13, 2013 at 18:22
  • @egreg It's 30 for me after \begin{document}. \hyphenation is no longer necessary, the hyphenation with the ngerman patterns (loadhyph-de-1996 or dehyphn-x-2012-05-30) is correct. Apr 13, 2013 at 18:30
14

You can also suggest places for hyphenation using \-. The following works for me.

\documentclass{article}
\usepackage{polyglossia}
\setmainlanguage{german}
\usepackage{array}
\usepackage{ragged2e}
\begin{document}
\begin{tabular}{>{\RaggedRight}p{7.7em}@{|}}
Sicherheits\-be\-auf\-tragter\\
Technischer Leiter
\end{tabular}
\end{document}
3
  • 2
    The problem here is, that the word is read from a source file, in which "\-" shouldn't occur (aka readable to non-texies).
    – Toscho
    Apr 15, 2013 at 11:56
  • Ah, then in that case Heiko's answer is a much more suitable solution.
    – erik
    Apr 16, 2013 at 2:42
  • This (\-) worked for me with no package. I used it for one specific word that was refusing to break. Useful trick.
    – PatrickT
    Jul 13, 2018 at 8:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .