我正在尝试制作一个带有文本的表格,但在单元格换行方面遇到了问题。请帮助我,以下是我使用的代码:
\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}
答案1
您遇到的情况是 (pdf)TeX 不会对段落的第一个单词进行连字符处理。对于 TeX 而言,单词“Risiconummer”是(逻辑)段落中的第一个(也是唯一一个)单词。
您有两个选择:
从 pdfLaTeX 切换到 LuaLaTeX;LuaTeX 在对段落的第一个单词进行连字符连接时没有任何问题。
在相关列前面加上
>{\hspace{0pt}}
。这会“欺骗” TeX 相信“Risiconummer”不是段落的第一个单词。
\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}
答案2
我建议使用将ltablex
的功能引入 的软件包。它将使列更宽(最宽处约为 3 厘米)。但是,您可以看到较窄的第一列确实需要帮助来连字符。您可以使用较小的字体大小,调整 的值和/或更改列宽的比例。以下是两个示例:longtable
tabularx
tabcolsep
\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}