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 have made following table which is not looking elegant. Could anybody help me in making it more better. Following is the tex code that I have used.

\documentclass[12pt]{article}
\usepackage{latexsym}
\usepackage{amsmath, times, amsfonts, mathrsfs, amssymb}
\usepackage{amsmath, times, amsfonts, mathrsfs, amssymb}
\begin{document}
\begin{table}[htbp]
\small \caption{\small Computation of number of iterations and error norms for Example 4.2:}
\centering
\begin{tabular}{c c c c c c c}
\hline
 Value of $\beta$ &  $k$  & $\|A^{-1} - X_{k}\|_2$ & $\|X_k  - X_{k-1}\|_2$   \\ [0.3ex] % inserts table
 &  & & &   &  & \\
 %
\hline
 0.9  & 0  &  0.489897948556636  & 0.462668212869655  \\
 & 1 &   0.044911860348910 & 0.044385148438250 \\
 & 2 &  6.418447480230614e-004 & 6.417891668548070e-004  \\
 & 3 &   5.683044758299918e-008 &   5.683044739894235e-008  \\
  & 4 &   1.861900614935455e-016 &   1.861900614935455e-016  \\
   & 5 &   0 &   0 \\  [1ex]
\hline
\end{tabular}
\label{table:nonlin}
\end{table}
\end{document}

After running it looks like this

share|improve this question
1  
Are the 15 digits all significant? –  egreg May 5 '13 at 19:01
    
@egreg Ya they are significant. I have to use them. –  srijan May 5 '13 at 19:02
1  
I told you, that 15th digit was a 8 not an 9, your fired. –  Nicholas Hamilton May 5 '13 at 20:20

1 Answer 1

up vote 15 down vote accepted

This seems a job for booktabs and siunitx. The first provides good horizontal rules with appropriate spacing, the second is specialized in typesetting numbers with or without units of measure.

Type S columns make alignments at the decimal point; one can specify the number format:

table-format=1.15

means one digit for the integer part and 15 for the fractional part;

table-figures-exponent=2

means "keep two digits for the exponent";

table-sign-exponent=true

means that the exponent can be negative.

\documentclass[12pt]{article}
\usepackage{amsmath,amsfonts,mathrsfs,amssymb}
\usepackage{newtxtext,newtxmath} % better than "times"
\usepackage{booktabs} % pretty tables
\usepackage{siunitx}  % number formatting

\begin{document}

\begin{table}[htbp]
\centering\small 

\caption{Computation of number of iterations and error norms for Example 4.2}
\medskip

\begin{tabular}{
  c
  c
  *{2}{
   S[table-format=1.15,
     table-figures-exponent=2,
     table-sign-exponent=true]
  }
}
\toprule
Value of $\beta$ &
  $k$ &
  {$\|A^{-1} - X_{k}\|_2$} &
  {$\|X_k  - X_{k-1}\|_2$} \\
\midrule
0.9 & 0 &  0.489897948556636      & 0.462668212869655      \\
    & 1 &  0.044911860348910      & 0.044385148438250      \\
    & 2 &  6.418447480230614e-004 & 6.417891668548070e-004 \\
    & 3 &  5.683044758299918e-008 & 5.683044739894235e-008 \\
    & 4 &  1.861900614935455e-016 & 1.861900614935455e-016 \\
    & 5 &  0                      & 0                      \\
\bottomrule
\end{tabular}
\label{table:nonlin}
\end{table}
\end{document}

enter image description here

share|improve this answer
    
Thanks for the answer. When I am running tex code It is saying Enter file name. –  srijan May 5 '13 at 19:40
    
The table-format option is just a wrapper/parser for various table- keys, one can also use table-format=1.15e-2. –  Qrrbrbirlbel May 5 '13 at 19:41
    
@srijan What file doesn't LaTeX find? –  egreg May 5 '13 at 19:43
    
I get ERROR: Package xkeyval Error: "table-format" undefined in families "key". I get the same with the two others as well. However, @srijan could also get ERROR: LaTeX Error: File "newtxtext.sty" not found. –  Pål GD May 5 '13 at 21:58
    
@PålGD I'm afraid you have an outdated TeX distribution –  egreg May 5 '13 at 22:03

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.