I have the following table with column linewidth. I want to set the font size of the table to some specific value. Several suggestions say that a code like p{0.4in}
will work. I tried p{0.18\linewidth}{0.4in}
but it is not working. How to fix this? Thanks in advance.
\begin{table}[H]
\centering
\setlength{\tabcolsep}{0.2em} % for the horizontal padding
\caption{A table}
\label{tab:42}
\resizebox{\textwidth}{!}{%
\begin{tabular}{ |p{0.18\linewidth} | p{0.20\linewidth} |}
%Head row starts************
\hline
Column1 & Column2 \\
\hline
Data1 & Data2 \\
\hline
\end{tabular}%
}
\end{table}
Best Answer
As @DavidCarlisle has already pointed out in a comment, nobody should ever employ
\resizebox
to force the tabular-like material to occupy a given width, say,\linewidth
. Instead, use atabularx
or atabular*
environment to set the overall width. That way, you'll avoid getting wildly inconsistent font sizes across tables.If you must still adjust the font size, you may use one of LaTeX's many font size changing macros. The following screenshot shows the effects of employing
\Large
,\large
,\normalsize
(the default),\small
,\footnotesize
, and\scriptsize
.