1

I have problems with hyphenation in multirow text cells, again. In some cases, this totally gets ignored even though using hyphenation.

Bonus question would be, how do I tell \hyphenation to hyphenate "ß", since its Latex code \ss{} is not allowed as an argument. Any ideas?

Thank you in advance for your help!

\documentclass[11pt]{article}

\usepackage[latin1]{inputenc} 
\usepackage[T1]{fontenc}

\usepackage[ngerman]{babel}
\usepackage{tabularx}
\usepackage{multirow}
\usepackage{array}
\usepackage{ragged2e}

\newcolumntype{P}[1]{>{\RaggedRight\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{x}{>{\RaggedRight\arraybackslash\hspace{0pt}}X}


\hyphenation{Ein-fluss-gr\"o-\ss en}
\hyphenation{So-zio-\"oko-no-mische}
\hyphenation{An-ge-bots-spe-zi-fi-sche}


\begin{document}

\begin{table}[htb] 
\centering
\setlength{\tabcolsep}{4mm}
\renewcommand{\arraystretch}{1.2}

\begin{tabularx}{\textwidth}{|P{5.1em}|P{19.2em}|}

\hline
\multirow{7}{3.6em}
{\hspace{0pt}Demographische Einflussgrößen} & Alter \\*
 & Geschlecht \\*
 & Erwerbstätigkeit \\*
 & Schulbildung \\*
 & Einschränkung der Mobilität \\*
 & Einschränkung der Sinne \\*
 & Sprachbarrieren \\\hline

\multirow{4}{3.6em}
{\hspace{0pt}Sozioökonomische} & Beruf\\*
 & Einkommen \\*
 & Haushaltsstruktur \\*
 & Pkw-Verfügbarkeit \\\hline

\multirow{9}{3.6em}
{\hspace{0pt}Psychologische Einflussgrößen} & Motive \\*
 & Wertvorstellungen \\*
 & Lern- und Gewöhnungseffekte \\*
 & Kognitive Prozesse \\*
 & Kenntnis des Ortes \\*
 & Kenntnis des Systems \\* 
 & Image des Verkehrsmittels \\*
 & Subjektive Produktpräferenzen \\*
 & \hangindent=1em Einstellung zu angebotsspezifischen Einflussgrößen \\\hline

\multirow{2}{3.6em}
{\hspace{0pt}Angebotsspezifische}
 & Verfügbarkeit der Verkehrsmittel \\*
 & \hangindent=1em Zur Verfügung stehende Informationen \\\hline

 \multirow{5}{3.6em}
 {\hspace{0pt}Situationsspezifische Einflussgrößen}  & Gepäcktransport \\*
 & Fahrradmitnahme \\*
 & Tageszeit \\*
 & Jahreszeit \\*
 & Wetter \\\hline
\end{tabularx}

\caption{Einflussgrößen}

\end{table}

\end{document}

enter image description here

  • 1
    Is there any chance you could switch to LuaLaTeX? The reason I ask is that LuaLaTeX, unlike pdfLaTeX and XeLaTeX, has no problems hyphenating the first word of a (logical) paragraph. – Mico Mar 22 '17 at 16:28
  • I'm not sure what that means for the rest of my document, thus I'd rather refrain from trying it - especially 1 week before my thesis' deadline. – D. Duesen Mar 22 '17 at 16:59
  • 1
    A simple solution would be to simply hard-code the breaks, like so: Sozio\"oko- nomische (note the space after the hyphen). I do this often when not satisfied with LaTeX's line-breaking in tables. Also maybe try \raggedright instead of \RaggedRight. – Michael Palmer Mar 22 '17 at 17:07
  • I tried \hspace{0pt}Sozioöko\- \mbox{nomische} Einfluss\- größen, but then "nomische" is too wide for the cell leading to an arbitrary vskip for whatever reason. Any way to get rid of this? Simply substracting vspace doesn't work, unfortunately. – D. Duesen Mar 22 '17 at 17:28
3

There seems to be a weird (read: unfortunate) interaction between the multirow, tabularx, and ragged2e packages. I suggest you ditch the multirow machinery entirely and use side-by-side tabular environments in the two columns of the tabularx environment.

In the following screenshot, you will immediately notice the difference in linespacing between the left-hand and right-hand columns. That's because of the instruction \renewcommand{\arraystretch}{1.2} that's in your code and which I didn't remove. You should probably remove this instruction or, at least, modify it to something like \renewcommand{\arraystretch}{1.1}.

enter image description here

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{tabularx,ragged2e}

\newcolumntype{P}[1]{>{\RaggedRight\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{x}{>{\RaggedRight\arraybackslash}X}

\hyphenation{an-ge-bots-spe-zi-fi-sche}

\newlength\mylength
\setlength{\mylength}{3.6em} % set usable width of first column
\begin{document}

\begin{table}[htb] 
\setlength{\tabcolsep}{4mm}
\renewcommand{\arraystretch}{1.2}

\begin{tabularx}{\textwidth}{|P{\mylength}|x|}
\hline
\begin{tabular}{@{}P{\mylength}@{}}
  Demographische Einflussgrößen 
\end{tabular} &
\begin{tabular}{@{}l}
  Alter \\
  Geschlecht \\
  Erwerbstätigkeit \\
  Schulbildung \\
  Einschränkung der Mobilität \\
  Einschränkung der Sinne \\
  Sprachbarrieren 
\end{tabular}\\ 
\hline
\begin{tabular}{@{}P{\mylength}@{}}    
  Sozioökonomische
\end{tabular} &
\begin{tabular}{@{}l}  
  Beruf\\
  Einkommen \\
  Haushaltsstruktur \\
  Pkw-Verfügbarkeit 
\end{tabular}\\ 
\hline
\begin{tabular}{@{}P{\mylength}@{}}    
  Psychologische Einflussgrößen
\end{tabular} &
\begin{tabular}{@{}l}    
  Motive \\
  Wertvorstellungen \\
  Lern- und Gewöhnungseffekte \\
  Kognitive Prozesse \\
  Kenntnis des Ortes \\
  Kenntnis des Systems \\ 
  Image des Verkehrsmittels \\
  Subjektive Produktpräferenzen \\ 
  Einstellung zu angebotsspezifischen Einflussgrößen 
\end{tabular}\\ 
\hline
\begin{tabular}{@{}P{\mylength}@{}}    
  Angebotsspezifische
\end{tabular} &
\begin{tabular}{@{}l}    
  Verfügbarkeit der Verkehrsmittel \\
  Zur Verfügung stehende Informationen
\end{tabular}\\ 
\hline
\begin{tabular}{@{}P{\mylength}@{}}    
  Situationsspezifische Einflussgrößen
\end{tabular} &
\begin{tabular}{@{}l}      
  Gepäcktransport \\
  Fahrradmitnahme \\
  Tageszeit \\
  Jahreszeit \\
  Wetter 
\end{tabular}\\
\hline
\end{tabularx}
\caption{Einflussgrößen}
\end{table}
\end{document}
| improve this answer | |
  • Incidentally, I set the (usable) width of the first column of the tabularx environment to 3.6em simply because that's what you were doing in your code. Speaking for myself, I think it would be more desirable to set the width to ca. 5em. – Mico Mar 23 '17 at 8:42
  • Thanks a lot, that's a different way from what I'd have considered. I might give it a try, when my ugly workaround "\hspace{0pt}Sozioöko\- \mbox{nomische} Einfluss\- größen" doesn't work. Any idea for how to avoid the vertical skip before "nomische" (overfull cell width, even though not looking like it)? – D. Duesen Mar 23 '17 at 8:44
  • 1
    @D.Duesen - Yes: just remove the two instances of whitespace after \-. Note that you can also dispense with \hspace{0pt} and the \mbox wrapper. Thus, just write Sozioöko\-nomische Einfluss\-größen. – Mico Mar 23 '17 at 9:03
  • Thank you, this worked well! Do you know how to align these cell entries vertically? Using an "m" column does not work, unfortunately. – D. Duesen Mar 23 '17 at 9:36
  • 2
    @D.Duesen - The robustness of the multirow package is known to be less than perfect. That's why, in part, I chose to provide an answer that doesn't involve multirow at all. – Mico Mar 23 '17 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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