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've couple of tables drawn using array; one of the sample is mentioned below: How can I automatically adjust table to get fit inside 50% of line-width?

 $\displaystyle \boldsymbol{\begin{array}{|*{20}{c|}}
\hline
   {Student} & \begin{gathered}
  Length{\text{ of the }} \hfill \\
  {\text{pendulum (cm)}} \hfill \\
\end{gathered}  & \begin{gathered}
  No.{\text{ }}of \hfill \\
  {\text{oscillations (n) }} \hfill \\
\end{gathered}  & \begin{gathered}
  {\text{Total time }} \hfill \\
  {\text{for(n) oscillation (s)}} \hfill \\
\end{gathered}  & \begin{gathered}
  {\text{Time period }} \hfill \\
  {\text{(s)}} \hfill \\
\end{gathered}   \\
\hline
   I & {64.0} & 8 & {128.0} & {16.0}  \\
   \hline
   {II} & {64.0} & 4 & {64.0} & {16.0}  \\
   \hline
   {III} & {20.0} & 4 & {36.0} & {9.0}  \\
   \hline
 \end{array}  }$
share|improve this question

1 Answer 1

up vote 4 down vote accepted

I don't understand why you're using array and math mode.

Here are three proposals. The first one suffers from too big column headers, the other two solve this problem by making a symbolic header.

The packages booktabs and siunitx are necessary only for the last table format.

\documentclass{article}
\usepackage{amsmath}
\usepackage{booktabs,siunitx}

\newcommand{\manyrows}[1]{%
  \begin{tabular}{@{}c@{}}\strut#1\strut\end{tabular}%
}
\newcommand{\coldesc}[3]{%
  \multicolumn{#1}{l}{\footnotesize #2: #3} \\
}

\begin{document}
\begin{table}[htp]
\centering
\begin{tabular}{|*{5}{c|}}
\hline
Student &
  \manyrows{Length of the \\ pendulum (cm)} &
  \manyrows{No. of \\ oscillations ($n$)} &
  \manyrows{Total time for ($n$) \\ oscillation(s)} &
  \manyrows{Time \\ period(s)} \\
\hline
I & 64.0 & 8 & 128.0 & 16.0 \\
\hline
II & 64.0 & 4 & 64.0 & 16.0 \\
\hline
III & 20.0 & 4 & 36.0 & 9.0 \\
\hline
\end{tabular}

\caption{This table is too wide}
\end{table}

\begin{table}[htp]
\centering

\begin{tabular}{|*{5}{c|}}
\hline
Student & (A) & (B) & (C) & (D) \\
\hline
I & 64.0 & 8 & 128.0 & 16.0 \\
\hline
II & 64.0 & 4 & 64.0 & 16.0 \\
\hline
III & 20.0 & 4 & 36.0 & 9.0 \\
\hline
\coldesc{5}{(A)}{Length of the pendulum (cm)}
\coldesc{5}{(B)}{No. of oscillations ($n$)}
\coldesc{5}{(C)}{Total time for ($n$) oscillation(s)}
\coldesc{5}{(D)}{Time period(s)}
\end{tabular}

\caption{This table is better}

\end{table}

\begin{table}[htp]
\centering

\begin{tabular}{
  l
  S[table-format=2.1]
  S[table-format=1.0]
  S[table-format=3.1]
  S[table-format=2.1]
}
\toprule
Student & {(A)} & {(B)} & {(C)} & {(D)} \\
\midrule
I & 64.0 & 8 & 128.0 & 16.0 \\
II & 64.0 & 4 & 64.0 & 16.0 \\
III & 20.0 & 4 & 36.0 & 9.0 \\
\bottomrule
\coldesc{5}{(A)}{Length of the pendulum (\si{cm})}
\coldesc{5}{(B)}{No. of oscillations ($n$)}
\coldesc{5}{(C)}{Total time for ($n$) oscillation(s)}
\coldesc{5}{(D)}{Time period(s)}
\end{tabular}

\caption{This table is even better}

\end{table}

\end{document}

enter image description here

share|improve this answer
    
Great... This was unexpected answer. This proves "common sense is not so common" :) Thank You once again... –  Pawan Mude Jan 3 at 16:29

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.