Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question

migrated from stackoverflow.com Nov 20 '11 at 19:03

This question came from our site for professional and enthusiast programmers.

2 Answers 2

up vote 11 down vote accepted

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}
share|improve this answer

Check out the tabls package!

share|improve this answer
5  
Could you elaborate a bit on how this package helps? An example would be great. –  doncherry Nov 20 '11 at 19:19
    
load the package ... and you'll see. That's all –  Herbert Nov 20 '11 at 19:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.