2

I'm trying to make a table with text, but i've got problems with wrapping in the cells. Please help me, below is the code that i've used:

\usepackage{longtable}
\begin{landscape}
\section{Risico's}

\begin{center}
\begin{longtable}{| p{1cm} | p{2cm} | p{2cm} | p{2cm} | p{2cm} | p{2cm} | p{2cm} | p{2cm} |}
\caption{Risicoanalyse}\\
\hline
\textbf{Risiconummer} & \textbf{Risico} & \textbf{Kans optreden} & \textbf{Impact} & \textbf{Risicogetal} & \textbf{Preventieve maatregelen} & \textbf{correctieve maatregelen} \\
\hline
\endfirsthead
\multicolumn{7}{c}%
{\tablename\ \thetable\ -- \textit{Vervolg van de vorige pagina}} \\
\hline
\textbf{Risiconummer} & \textbf{Risico} & \textbf{Kans optreden} & \textbf{Impact} & \textbf{Risicogetal} & \textbf{Preventieve maatregelen} & \textbf{correctieve maatregelen} \\
\hline
\endhead
\hline \multicolumn{7}{r}{\textit{Vervolg op de volgende pagina}} \\
\endfoot
\hline
\endlastfoot
 asfdfasfasdfdf & asdfasfdasfdsa fadsfaafdssdfdsfasdf & asdfasdfa sfsadfasf & adfafas dfsafsdf & adfasfas dfasdfsa & 6 & 7
\end{longtable}
\end{center}
\end{landscape}

2 Answers2

3

What you're experiencing is the fact that (pdf)TeX doesn't hyphenate the very first word of a paragraph. The word "Risiconummer" is the first (and also only) word in what is, to TeX, a (logical) paragraph.

You have two options:

  • Switch from pdfLaTeX to LuaLaTeX; LuaTeX has no problems hyphenating the first word of a paragraph.

  • Prefix the column in question with >{\hspace{0pt}}. This "tricks" TeX into believing that "Risiconummer" is not the very first word of the paragraph.

enter image description here

\documentclass{article}
\usepackage[dutch]{babel}
\usepackage{pdflscape}
\usepackage{longtable,array,ragged2e}
\newcolumntype{P}[1]{>{\RaggedRight\arraybackslash\hspace{0pt}}p{#1}}
\begin{document}

\begin{landscape}
\section{Risico's}

\begin{longtable}{| P{1cm} | P{2cm} | P{2cm} | P{2cm} | P{2cm} | P{2cm} | P{2cm} | P{2cm} |}
\caption{Risicoanalyse}\\
\hline
\textbf{Risiconummer} & \textbf{Risico} & \textbf{Kans optreden} & \textbf{Impact} & \textbf{Risicogetal} & \textbf{Preventieve maatregelen} & \textbf{correctieve maatregelen} \\
\hline
\endfirsthead
\multicolumn{7}{c}%
{\tablename\ \thetable\ -- \textit{Vervolg van de vorige pagina}} \\
\hline
\textbf{Risiconummer} & \textbf{Risico} & \textbf{Kans optreden} & \textbf{Impact} & \textbf{Risicogetal} & \textbf{Preventieve maatregelen} & \textbf{correctieve maatregelen} \\
\hline
\endhead
\hline \multicolumn{7}{r}{\textit{Vervolg op de volgende pagina}} \\
\endfoot
\hline
\endlastfoot
 asfdfasfasdfdf & asdfasfdasfdsa fadsfaafdssdfdsfasdf & asdfasdfa sfsadfasf & adfafas dfsafsdf & adfasfas dfasdfsa & 6 & 7
\end{longtable}

\end{landscape}

\end{document}
Mico
  • 506,678
0

I propose to use the ltablex package, which brings the functionalities of longtable to tabularx. It will make wider columns (the widest will be approx. 3 cm). However you can see the narrower first column really needs help hyphenating words. You can use a smaller font size, play with the value oftabcolsep and/or change the ratio of column widths. Here are two examples:

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage{array, booktabs, siunitx, lscape}
\sisetup{table-number-alignment = center, parse-numbers = false}

\usepackage{ltablex}
\usepackage{ragged2e}
\renewcommand{\tabularxcolumn}[1]{>{\RaggedRight\small\arraybackslash}m{#1}}

\begin{document}

\begin{landscape}
  \section{Risico's}
  \keepXColumns
  \setlength\tabcolsep{3pt}
  \begin{tabularx}{\linewidth}{|>{\hsize=0.58\hsize}X | *{7}{>{\hsize=1.06\hsize}X|}}
    \caption{Risicoanalyse}\\
    \hline
    \textbf{Risiconummer} & \textbf{Risico} & \textbf{Kans optreden} & \textbf{Impact} & \textbf{Risicogetal} & \textbf{Preventieve maatregelen} & \textbf{Correctieve maatregelen} \\
    \hline
    \endfirsthead
    \multicolumn{7}{c}%
    {\tablename\ \thetable\ -- \textit{Vervolg van de vorige pagina}} \\
    \hline
    \textbf{Risiconummer} & \textbf{Risico} & \textbf{Kans optreden} & \textbf{Impact} & \textbf{Risicogetal} & \textbf{Preventieve maatregelen} & \textbf{correctieve maatregelen} \\
    \hline
    \endhead
    \hline \multicolumn{7}{r}{\textit{Vervolg op de volgende pagina}} \\
    \endfoot
    \hline
    \endlastfoot
    asfdfasfas\-dfdf & asdfasfdasfdsa fadsfaafdssdfdsfasdf & asdfasdfa sfsadfasf & adfafas dfsafsdf & adfasfas dfasdfsa & 6 & 7
  \end{tabularx}

  \begin{tabularx}{\linewidth}{|>{\hsize=0.86\hsize}X | *{7}{>{\hsize=1.02\hsize}X|}}
    \caption{Risicoanalyse}\\
    \hline
    \textbf{Risiconummer} & \textbf{Risico} & \textbf{Kans optreden} & \textbf{Impact} & \textbf{Risicogetal} & \textbf{Preventieve maatregelen} & \textbf{Correctieve maatregelen} \\
    \hline
    \endfirsthead
    \multicolumn{7}{c}%
    {\tablename\ \thetable\ -- \textit{Vervolg van de vorige pagina}} \\
    \hline
    \textbf{Risiconummer} & \textbf{Risico} & \textbf{Kans optreden} & \textbf{Impact} & \textbf{Risicogetal} & \textbf{Preventieve maatregelen} & \textbf{correctieve maatregelen} \\
    \hline
    \endhead
    \hline \multicolumn{7}{r}{\textit{Vervolg op de volgende pagina}} \\
    \endfoot
    \hline
    \endlastfoot
    asfdfasfas\-dfdf & asdfasfdasfdsa fadsfaafdssdfdsfasdf & asdfasdfa sfsadfasf & adfafas dfsafsdf & adfasfas dfasdfsa & 6 & 7
  \end{tabularx}
\end{landscape}

\end{document} 

enter image description here

Bernard
  • 271,350
  • Recall also that TeX (except LuaTeX) never hyphenates the first word of a paragraph. – Mico Feb 17 '17 at 14:19
  • @Mico: If necessary, it can be hyphenated manually. B.t.w., I've just found out I posted the first version of the code, which doesn't correspond to the image (fixed) – Bernard Feb 17 '17 at 14:26