![使用“p”类型列控制表格中的自动换行的问题](https://linux22.com/image/358238/%E4%BD%BF%E7%94%A8%E2%80%9Cp%E2%80%9D%E7%B1%BB%E5%9E%8B%E5%88%97%E6%8E%A7%E5%88%B6%E8%A1%A8%E6%A0%BC%E4%B8%AD%E7%9A%84%E8%87%AA%E5%8A%A8%E6%8D%A2%E8%A1%8C%E7%9A%84%E9%97%AE%E9%A2%98.png)
我希望表格中的文本自动换行,我使用'p'类型的列来实现。
\documentclass{article}
\begin{document}
\begin{tabular}{p{2.5cm}|p{2.5cm}|p{2.7cm}|p{2.7cm}|p{2.5cm}}
\hline
\cline{1-6}
Genitourinary & Grade 1 & Grade 2 & Grade 3 & Grade 4 \\
\hline
Dysurie & Not therapy & Oral treatment (no narcotic analgesics) & Narcotic analgesics & Not \defined \\
Frequency & once/2h, twice pretherapy & once/1h &once/0.5h (more frequent than hourly) & Not defined \\
\hline
\end{tabular}
\hfill \break
\end{document}
答案1
如果您希望允许连字符,同时单词之间有正常间距,则可以\RaggedRight
在每列的开头使用该指令。
另外,既然你的表格几乎和 textwidth 一样大,为什么不使用tabularx
?你不必计算每列需要多宽才能适合text width
。
最后说明:由于\hline\cline
只制作较粗的线,因此您也可以加载makecell
并使用其\Xhline
命令来制作宽度可变的线。然后,您还可以使用该\makecell
命令来使列标题居中。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[showframe]{geometry}
\usepackage{ragged2e}
\usepackage{tabularx, makecell}
\setlength{\extrarowheight}{2pt}
\setlength{\tabcolsep}{3pt}%
\begin{document}
\centering \begin{tabular}{p{2.5cm}|>{\RaggedRight}p{2.5cm}|>{\RaggedRight}p{2.7cm}|>{\RaggedRight}p{2.7cm}|p{2.5cm}}
\hline
\cline{1-5}
Genitourinary & Grade 1 & Grade 2 & Grade 3 & Grade 4 \\
\hline
Dysurie & Not therapy & Oral treatment (no narcotic analgesics) & Narcotic analgesics & Not defined \\
Frequency & once/2h, twice pretherapy & once/1h &once/0.5h (more frequent than hourly) & Not defined \\
\hline
\end{tabular}
\vspace{1cm}
\begin{tabularx}{\linewidth}{>{\RaggedRight\arraybackslash}X*{4}{|>{\RaggedRight\arraybackslash}X}}
\Xhline{0.8pt}
Genitourinary & \makecell{Grade 1} & \makecell{Grade 2} & \makecell{Grade 3} & \makecell{Grade 4} \\
\hline
Dysurie & Not therapy & Oral treatment (no narcotic analgesics) & Narcotic analge\-sics & Not defined \\
Frequency & once/2h, twice pretherapy & once/1h &once/0.5h (more frequent than hourly) & Not defined \\
\hline
\end{tabularx}
\hfill \break
\end{document}