自動調整單列以適應文字

自動調整單列以適應文字

我有下表,希望(僅)減少第一列,以便整個表格與文字寬度相同。我不想使用,p{...cm}因為我希望表格自動適合文字。不過,我還是嘗試使用它,但發現如果我將它放在begin{tabular}{p{1cm}l|l|l|l|l|l}.

\documentclass{article}
\usepackage{multirow,blindtext}

\begin{document}

\blindtext

\begin{tabular}{ll|l|l|l|l|l|}
\cline{3-7}
& & \multicolumn{5}{|c|}{Going to ... dice matching}\\ \cline{3-7}
& & 1 & 2 & 3 & 4 & 5\\ \hline
\multicolumn{1}{|c|}{\multirow{5}{*}{From ... dice matching}} & 1 & 720/7776 
& 5400/7776 & 1500/7776 & 150/7776 & 6/7776\\ \cline{2-7}
\multicolumn{1}{|c|}{} & 2 & & 120/216 & 80/216 & 15/216 & 1/216\\ \cline{2-7}
\multicolumn{1}{|c|}{} & 3 & & & 25/36 & 10/36 & 1/36\\ \cline{2-7}
\multicolumn{1}{|c|}{} & 4 & & & & 5/6 & 1/6\\ \cline{2-7}
\multicolumn{1}{|c|}{} & 5 & & & & & 1\\
\hline
\end{tabular}

\end{document}

我應該把p{...cm}它放在哪裡才能發揮作用?如何讓第一列寬度自動調整以使表格適合文字?

感謝您的幫忙!

答案1

首先,透過使用tabularx您可以設定表格的寬度並插入一X列。後者基本上類似於p,但其寬度自動設定為獲取具有給定寬度的表格所需的寬度。這裡 ist 用於第一列。

透過更改列聲明,使所有列之間都有垂直線,\multicolumn可以刪除最後五行的 s。但前兩行現在需要\multicolumns 來消除不需要的垂直線。

最後\multirow{5}{*}...必須變更為\multirow{5}{=}...它佔用列的寬度。

\documentclass{article}
\usepackage{multirow,blindtext}
\usepackage{tabularx}

\begin{document}

\blindtext

\noindent
\begin{tabularx}{\textwidth}{|X|l|l|l|l|l|l|}
\cline{3-7}
\multicolumn{2}{c|}{} & \multicolumn{5}{c|}{Going to ... dice matching}\\ \cline{3-7}
\multicolumn{2}{c|}{} & 1 & 2 & 3 & 4 & 5\\ \hline
\multirow{5}{=}{From ... dice matching} & 1 & 720/7776 & 5400/7776 & 1500/7776 & 150/7776 & 6/7776\\ \cline{2-7}
 & 2 & & 120/216 & 80/216 & 15/216 & 1/216\\ \cline{2-7}
 & 3 & & & 25/36 & 10/36 & 1/36\\ \cline{2-7}
 & 4 & & & & 5/6 & 1/6\\ \cline{2-7}
 & 5 & & & & & 1\\
\hline
\end{tabularx}

\end{document}

相關內容