I have the following table and would like to have the first column (only) reduced so that the whole table is the same width as the text. I don't want to use p{...cm}
because I want the table to fit the text automatically. However, I tried using it anyway, but found it doesn't work if I place it in 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}
Where should I place p{...cm}
for it to work?
How can I have the first column width automatically adjust to have the table fit the text?
Thank you for your help!
Best Answer
First, by using
tabularx
you can set a width of the table and insert aX
column. The latter is basically likep
, butwith its width automatically set to the width needed to get a table with the given width. Here ist is used for the first column.By changing the column declaration, so that there are vertical lines between all columns, the
\multicolumn
s for the last five lines can be removed. But the first two lines now need\multicolumn
s to get rid of the unwanted vertical lines.And finally
\multirow{5}{*}...
has to be changed to\multirow{5}{=}...
so it takes the width of the column.