3

I'm currently writing a thesis where hyphenation is not allowed with exception to tables. Disable Text hyphenation is working fine using:

\usepackage[none]{hyphenat}
\sloppy

Now the problem is that inside tabularx the words are larger than column width and they flow into the next column. I tried using RaggedRight while defining columns:

\newcolumntype{Z}{>{\RaggedRight\centering\arraybackslash\hspace{0pt}}X}

But still the text is not being hyphenated. Any ideas?

Requirements:

  1. No Hyphenations throughout the whole document
  2. Text in a table's column should not flow into the neighboring column

Below is a Mwe and a screenshot. Thanks

\documentclass[a4paper,12pt,oneside]{scrbook}
\usepackage{blindtext}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp}
\usepackage{ngerman}
\usepackage[none]{hyphenat}
\sloppy

\usepackage{tabularx}
\usepackage{ragged2e}
\usepackage{booktabs}
\usepackage{ltablex}

\newcolumntype{Z}{>{\RaggedRight\centering\arraybackslash\hspace{0pt}}X}
%Used for multicolumn
\newcolumntype{M}{>{\RaggedRight\arraybackslash\hspace{0pt}}c}
\newcolumntype{L}{>{\RaggedRight\arraybackslash\hspace{0pt}}l}

\begin{document}
\chapter{Intro}
\blindtext

\begin{tabularx}{\linewidth}{|Z|Z|Z|Z|Z|Z|Z|}
\hline
 & \multicolumn{2}{M|}{ \textbf{Anzahl TADs}} & \textbf{Verlustrate} & \textbf{Erfolgsdefinition} & \textbf{Misserfolgsdefinition} & \textbf{Entzündungserscheinung} \\ \hline
\textbf{Publikation} & \textbf{Insgesamt} & \textbf{Verlust} &  &  &  &  \\ \hline
Jung et al., 2009 & 30 & 2 & 6,7\% &  & Mangel an Osseointegrität, Mobilität des Implantates  & milde Mukositis \\ \hline
Jung et al., 2010 & 41 & 1 & 2,4\% & keine Implantatmobilität, keine unerwünschte Bewegung der Suprakonstruktion &  &  \\ \hline
\end{tabularx}
\end{document}

Bad hyphenation in tabularx

  • The setup of the Z column type, viz., \newcolumntype{Z}{>{\RaggedRight\centering\arraybackslash\hspace{0pt}}X}, can't be correct. Either omit \centering or omit \Raggedright and replace \centering with \Centering. – Mico Nov 29 '16 at 23:53
  • Sorry I meant "disabling text hyphenation". Corrected it in the text – Moataz Elmasry Nov 30 '16 at 0:15
4
The `hyphenat` package disables hyphenation by setting \hyphenpenalty=10000\exhyphenpenalty=10000

So if you want to temprary enable hyphenation, set these to sensible values (e.g. 25), This is a bit lower than usual, but in a small column we want to encourage hyphenation a bit more than in regular text.

\newcommand{\HY}{\hyphenpenalty=25\exhyphenpenalty=25}
\newcolumntype{Z}{>{\HY\centering\arraybackslash\hspace{0pt}}X}
\newcolumntype{M}{>{\HY\RaggedRight\arraybackslash\hspace{0pt}}c}
\newcolumntype{L}{>{\HY\RaggedRight\arraybackslash\hspace{0pt}}l}
  • I'll try this in the morning, but it looks very promising. In tables I only care that the text does not flow into the next columns. Thanks – Moataz Elmasry Nov 30 '16 at 1:07
  • 1
    @MoatazElmasry This is the most sensible way to handle the request. – Yiannis Lazarides Nov 30 '16 at 3:41
2

(edited to incorporate Piet van Ostrum's idea of changing the hyphenation penalty parameters locally)

From the user guide of the hyphenat package:

The hyphenat package has an option called none. Use of this option prevents any hyphenation throughout the document. If TeX is prevented from hyphenating it may complain about bad line breaks and you may find bits of text sticking out into the margin. If you use this option you should also consider using \sloppy and/or \raggedright. [emphasis added]

Even though hyphenation is disabled globally via \usepackage[none]{hyphenat}, it is possible to re-enable it locally by resetting the hyphenation penalty parameters \hyphenpenalty and \exhyphenpenalty, as demonstrated in @PietvanOostrum's answer for the definition of the Z column type.

Incorporating this idea, while using \RaggedRight instead of \centering and using the babel package (with option ngerman) instead of the deprecated ngerman package. produces the following solution. Note that it's still a good idea to provide guidance as to what are the acceptable hyphenation points for some of the words that appear in the header row. Otherwise one would end up with cases such as Verlus-trate. Observe also the use of \cline to group the sub-headers under "Anzahl TADs".

enter image description here

\documentclass[a4paper,12pt,oneside]{scrbook}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
%\usepackage{ngerman} % 'ngerman' package is deprecated
\usepackage[ngerman]{babel}
\usepackage[none]{hyphenat} % suppress hyphenation *globally*
\sloppy 
\usepackage{tabularx,ragged2e}
\newcommand{\HY}{\hyphenpenalty=25\exhyphenpenalty=25} 
% re-enable hyphenation locally inside "Z" columns
\newcolumntype{Z}{>{\HY\RaggedRight\arraybackslash\hspace{0pt}}X} 

\begin{document}

\setlength\tabcolsep{3pt} % optional
\begin{tabularx}{\linewidth}{|Z|Z|l|Z|Z|Z|Z|}
\hline
\textbf{Publika\-tion} & 
\multicolumn{2}{l|}{\textbf{Anzahl TADs}} & 
\textbf{Verlust\-rate} & \textbf{Erfolgs\-definition} 
& \textbf{Miss\-erfolgs\-definition} & \textbf{Entzündungserscheinung} \\ 
\cline{2-3}
& \textbf{Insgesamt} & \textbf{Verlust} &  &  &  &  \\ 
\hline
Jung et~al. 2009 & 30 & 2 & 6,7\% &  & Mangel an Osseointegrität, Mobilität des Implantates  & milde Mukositis \\ 
\hline
Jung et~al. 2010 & 41 & 1 & 2,4\% & keine Implantatmobilität, keine unerwünschte Bewegung der Suprakonstruktion &  &  \\ 
\hline
\end{tabularx}
\end{document}
  • Hi Mico, thanks for your answer, but unfortunately this does not answer my question. I need to disable hyphenation for the whole document, but enable it inside tabularx. I updated the question with the r – Moataz Elmasry Nov 30 '16 at 0:19
  • Thanks for your very good remark regarding \centering. I'll try it in the morning. – Moataz Elmasry Nov 30 '16 at 0:20
  • @MoatazElmasry - If you don't want to disable hyphenation globally, you shouldn't load the hyphenat package with the option none. – Mico Nov 30 '16 at 0:21
  • Forget the last comment, I'll test your solution tomorrow. Thanks!! – Moataz Elmasry Nov 30 '16 at 0:31
  • 1
    Thanks Mico. This solved my problem. Also +1 for the nice example and ngerman remark. I'm giving the "Correct Answer" to Piet since he's the one who came up with the solution. Cheers – Moataz Elmasry Nov 30 '16 at 12:14
1

One possible solution is to set tables in separated documents, where you not use hyphenat package, compiles this documents and include to main document as pdf images:

Example of separate documents for tables:

\documentclass[a4paper,12pt,oneside]{scrbook}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp}
\usepackage{ngerman}

\usepackage{tabularx}
\usepackage{ragged2e}
\usepackage{booktabs}

\newcolumntype{C}{>{\Centering\arraybackslash\hspace{0pt}}X}
\newcolumntype{L}{>{\RaggedRight\arraybackslash\hspace{0pt}}X}

\usepackage[active,tightpage]{preview}
\setlength\PreviewBorder{1pt}

\begin{document}
\begin{preview}
\small
\setlength\tabcolsep{3pt}
\begin{tabularx}{\linewidth}{|*{7}{C|}}% or better to use L clumn type
    \hline
    &   \multicolumn{2}{c|}{\textbf{Anzahl TADs}} 
        &   \textbf{Verlustrate} 
            &   \textbf{Erfolgsdefinition} 
                &   \textbf{Misserfolgsdefinition} 
                    &   \textbf{Entzündungserscheinung}     \\ 
    \hline
\textbf{Publikation} 
    & \textbf{Insgesamt} 
        & \textbf{Verlust}              &   &  &  &         \\ 
    \hline
Jung et al., 2009    
    & 30 & 2 & 6,7\%    &   
         &  Mangel an Osseointegrität, Mobilität des Implantates  
            &   milde Mukositis                             \\ 
    \hline
Jung et al., 2010 
    & 41 & 1 & 2,4\%    &   keine Implantatmobilität, keine unerwünschte Bewegung der Suprakonstruktion                   &  &                \\ 
\hline
\end{tabularx}
\end{preview}
\end{document}

which gives:

enter image description here

Package preview is used for trimming table that hyphenation can better works. Obtained table pdf files than include in main document as

\begin{table}[htb]
    \caption{title of table}
\label{tab: ...}
    \includegraphics{path/table name}
\end{table}

Of course this method works fine for tables which can be placed on one page.

  • Thanks @Zarco but unfortunately the actual table does span over multiple pages, so this solution won't work for me – Moataz Elmasry Nov 30 '16 at 12:13

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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