使用“p”類型列來控製表格中的自動換行符的問題

使用“p”類型列來控製表格中的自動換行符的問題

我希望表格中的文字自動換行,我使用'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} 

在此輸入影像描述

相關內容