我希望表格中的文本自动换行,我使用'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}