[Tex/LaTex] How to reduce table row height

spacingtables

I use the following code to render a table in LaTeX. But the problem is that the default row height is too big for me. I want to be able to specify the row height. How can i do it?

\begin{tabular}{|p{5cm}|p{2.5cm}|}
  \hline
  File  & size \\ \hline
       hello_world & 1mb\\  \hline
       helloworld2 kB & 64kb \\
  \hline
\end{tabular}

Can someone please help.

Best Answer

One option could be using a modified \arraystretch:

enter image description here

\documentclass{article}
\begin{document}
\begin{tabular}{|p{5cm}|p{2.5cm}|}
  \hline
  File  & size \\ \hline
       hello\_world & 1mb \\  \hline
       helloworld2 kB & 64kb \\
  \hline
\end{tabular}

\bigskip

\renewcommand{\arraystretch}{0.8}% Tighter
\begin{tabular}{|p{5cm}|p{2.5cm}|}
  \hline
  File  & size \\ \hline
       hello\_world & 1mb \\  \hline
       helloworld2 kB & 64kb \\
  \hline
\end{tabular}

\bigskip

\renewcommand{\arraystretch}{1.5}% Wider
\begin{tabular}{|p{5cm}|p{2.5cm}|}
  \hline
  File  & size \\ \hline
       hello\_world & 1mb \\  \hline
       helloworld2 kB & 64kb \\
  \hline
\end{tabular}
\end{document}

Also see Column padding in tables for more options on horizontal and vertical padding.


For centered horizontal alignment of the columns, you could use the column specifier c (which will default to a natural-width column) or use >{\centering\arraybackslash}p{<len>}. For centered vertical alignment of the columns, you could use the column specifier m{<len>}. For both, use >{\centering\arraybackslash}m{<len>}. The last two settings require the array package:

enter image description here

\documentclass{article}
\usepackage{array}% http://ctan.org/pkg/array
\begin{document}
\begin{tabular}{|>{\centering\arraybackslash}m{5cm}|>{\centering\arraybackslash}m{2.5cm}|}
  \hline
  File  & size \\ \hline
       hello\_world & 1mb \\  \hline
       helloworld2 kB & 64kb \\
  \hline
\end{tabular}

\bigskip

\renewcommand{\arraystretch}{0.8}% Tighter
\begin{tabular}{|>{\centering\arraybackslash}m{5cm}|>{\centering\arraybackslash}m{2.5cm}|}
  \hline
  File  & size \\ \hline
       hello\_world & 1mb \\  \hline
       helloworld2 kB & 64kb \\
  \hline
\end{tabular}

\bigskip

\renewcommand{\arraystretch}{1.5}% Wider
\begin{tabular}{|>{\centering\arraybackslash}m{5cm}|>{\centering\arraybackslash}m{2.5cm}|}
  \hline
  File  & size \\ \hline
       hello\_world & 1mb \\  \hline
       helloworld2 kB & 64kb \\
  \hline
\end{tabular}
\end{document}
Related Question