
表形式のテキストを自動的に改行したいのですが、そのために「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}
しかし、2 つの単語の間に大きなスペース (図の赤い線でマーク) があるため、出力は私が望んでいるものとは正確に一致しません。誰かこれを修正する方法を知っていますか? ありがとうございます。
答え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}