テキストに合わせて1列を自動調整する

テキストに合わせて1列を自動調整する

次のような表があり、最初の列 (のみ) を縮小して、表全体の幅がテキストと同じになるようにしたいと考えています。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最後の 5 行の を削除できます。ただし、最初の 2 行では、\multicolumn不要な垂直線を取り除くために が必要になります。

そして最後に、列の幅を取得するよう\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}

関連情報