# How to set font size in Latex table?

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} |}
\hline
Column1 & Column2 \\
\hline
Data1 & Data2 \\
\hline
\end{tabular}%
}
\end{table}

• Welcome to TeX.SX! Your question is somewhat contradictory. You mention wanting to change the font size to a specific value, but also mention suggestions such as p type columns, which itself do not alter the font size but the available width of a column. What exactly do you want to achieve here? Jun 5 '21 at 16:43
• If you want a decent looking table, start by getting rid of the \resizebox. Resizing tables will inevitably result in inconsistent fonts sizes and line widths throughout the document. Jun 5 '21 at 16:43
• @leandriis It is my mistake. I'm new to Latex and so much overwhelmed with numerous codes. How should I proceed if I avoid \resizebox? Jun 5 '21 at 17:01
• How to proceed depends on the expected output. How exactly should your table look like? How wide should your columns be and what kind of contents will they contain (short word, numbers, longer sencences, lists, or something entirely different). Please clarify. Jun 5 '21 at 17:30
• \resizebox{\textwidth}{!}{% makes it impossible to set any font size, start by removing that, then you can uae any latex size command you want such as \small or \footnotesize if you need the text to be smaller Jun 5 '21 at 17:33

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 a tabularx or a tabular* 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.

\documentclass{article}
\usepackage{tabularx}
\setlength\extrarowheight{2pt}
\begin{document}

\begin{table}[ht!]
\caption{A full-width \texttt{tabularx} environment at various font sizes\strut} \label{tab:42}

\Large
\begin{tabularx}\linewidth{ | X | X  |}
\hline
Column1 & Column2 \\
\hline
Data & \texttt{\textbackslash Large} \\
\hline
\end{tabularx}
\medskip

\large
\begin{tabularx}\linewidth{ | X | X  |}
\hline
Column1 & Column2 \\
\hline
Data & \texttt{\textbackslash large} \\
\hline
\end{tabularx}
\medskip

\normalsize % that's the default
\begin{tabularx}\linewidth{ | X | X  |}
\hline
Column1 & Column2 \\
\hline
Data & \texttt{\textbackslash normalsize} \\
\hline
\end{tabularx}
\medskip

\small
\begin{tabularx}\linewidth{ | X | X  |}
\hline
Column1 & Column2 \\
\hline
Data & \texttt{\textbackslash small} \\
\hline
\end{tabularx}
\medskip

\footnotesize
\begin{tabularx}\linewidth{ | X | X  |}
\hline
Column1 & Column2 \\
\hline
Data & \texttt{\textbackslash footnotesize} \\
\hline
\end{tabularx}
\medskip

\scriptsize
\begin{tabularx}\linewidth{ | X | X  |}
\hline
Column1 & Column2 \\
\hline
Data & \texttt{\textbackslash scriptsize} \\
\hline
\end{tabularx}
\end{table}
\end{document}