22

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.

1

1 Answer 1

39

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}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .