Create a table with LaTeX

A simple version of the table:

\documentclass[12pt]{article}

\renewcommand*{\arraystretch}{1.2}

\begin{document}
\noindent
\begin{tabular}{|c|*{12}{c}}
  \hline
  Alloy & Ni & Cr & Co & Mo & W & Al & Ti & Ta & Re & Nb & V & Hf \\
  \hline
  \multicolumn{13}{|l}{First generation}\\
  \hline
  PWA 1480  & 62.5 & 10  & 5   &     & 4   & 5   & 1.5 & 12 \\
  Ren\'e N4 & 62.6 & 9   & 8   & 2   & 6   & 3.7 & 4.2 & 4   &   & 0.5 \\
  CMSX-2    & 66.6 & 8   & 4.6 & 0.6 & 7.9 & 5.6 & 0.9 & 5.8 \\
  SRR 99    & 66.5 & 8.5 & 5   &     & 9.5 & 5.5 & 2.2 & 2.8 \\
  \hline
  \multicolumn{13}{|l}{Second generation}\\
  \hline
  PWA 1484  & 59.4 & 5   & 10  & 2   & 6   & 5.6 &     & 9   & 3 \\
  Ren\'e N5 & 61.8 & 7   & 8   & 2   & 5   & 6.2 &     & 7   & 3 &     & & 0.2 \\
\end{tabular}
\end{document}

(The missing follwing lines of the table are left as exercise for the reader.)

Result

Finetuning:

  • *{12}{c} is a shortcut for cccccccccccc.

  • In tabulars the line distances are managed by struts with a height and depth that sums up to a text line. With horizontal lines, the text might be too near to the lines, thus \renewcommand*{\arraystretch}{1.2} increases thesse struts by 20 percent.

  • Alternative is using the length \extrarowheight, This amount is added to a row height in a table, e.g.:

    \usepackage{array}
    \setlength{\extrarowheight}{.2ex}
    
  • If you want to align the numbers at the dot, then take a look at packages dcolumn or siunitx.


Here, the figure labels are printed as Table x.y where x is the section number and y is a table number within section x.

\documentclass{article}

\usepackage[hmargin=3cm,vmargin=3.75cm]{geometry} % Here, only used to get rid of a overfull \hbox warning.
\usepackage{booktabs,dcolumn}                     % Tables.
\usepackage[figureposition=bottom]{caption}       % Float captions.

% Globally set table float position.
\makeatletter
  \providecommand*\setfloatlocations[2]{\@namedef{fps@#1}{#2}}
\makeatother
\setfloatlocations{table}{htbp}

% Redefine table counter.
\makeatletter
  \@addtoreset{table}{section}
\makeatother
\renewcommand*\thetable{\arabic{section}.\arabic{table}}

% Simplify notation.
\newcolumntype{d}[1]{D{.}{.}{#1}}
\newcommand*\mc[1]{\multicolumn{1}{c}{#1}}
\newcommand*\mcTwo[1]{\multicolumn{2}{l}{#1}}

\begin{document}

\section{First section}
Something.

\begin{table}
\centering
 \caption{A data table.}
 \label{tbl:1}
  \begin{tabular}{c c}
   A & B \\
   C & D
  \end{tabular}
\end{table}

\begin{table}
\centering
 \caption{A data table.}
 \label{tbl:2}
  \begin{tabular}{c c}
   E & F \\
   G & H
  \end{tabular}
\end{table}

\section{Second section}
Something.

\begin{table}
\centering
 \caption{A data table.}
 \label{tbl:3}
  \begin{tabular}{c d{2.1} d{2.1} d{2.1} d{1.1} d{1.1} d{1.2} d{1.1} d{1.1} d{1.1} d{1.1} d{1.0} d{1.2}}
   \toprule
    Alloy & \mc{Ni} & \mc{Cr} & \mc{Co} & \mc{Mo} & \mc{W} & \mc{Al} & \mc{Ti} & \mc{Ta} & \mc{Re} & \mc{Nb} & \mc{V} & \mc{Hf} \\
   \midrule
    \mcTwo{First generation} & & & & & & & & & & & \\
   \midrule
    PWA~1480    & 62.5 & 10   &  5   & \mc{---} & 4        & 5    & 1.5      & 12   & \mc{---} & \mc{---} & \mc{---} & \mc{---} \\[1ex]
    Ren{\'e}~N4 & 62.6 &  9   &  8   & 2        & 6        & 3.7  & 4.2      &  4   & \mc{---} & 0.5 & \mc{---} & \mc{---}      \\[1ex]
    CMSX-2      & 66.6 &  8   &  4.6 & 0.6      & 7.9      & 5.6  & 0.9      &  5.8 & \mc{---} & \mc{---} & \mc{---} & \mc{---} \\[1ex]
    SRR~99      & 66.5 &  8.5 &  5   & \mc{---} & 9.5      & 5.5  & 2.2      &  2.8 & \mc{---} & \mc{---} & \mc{---} & \mc{---} \\
   \midrule
    \mcTwo{Second generation} & & & & & & & & & & & \\
   \midrule
    PWA~1484    & 59.4 &  5   & 10   & 2        & 6        & 5.6  & \mc{---} &  9   & 3        & \mc{---} & \mc{---} & \mc{---} \\[1ex]
    Ren{\'e}~N5 & 61.8 &  7   &  8   & 2        & 5        & 6.2  & \mc{---} &  7   & 3        & 0.5      & \mc{---} & 0.2      \\[1ex]
    CMSX~4      & 61.8 &  6.5 &  9   & 0.6      & 6        & 5.6  & 1        &  6.5 & 3        & \mc{---} & \mc{---} & 0.1      \\[1ex]
    CMSX~6      & 70.4 & 10   &  5   & 3        & \mc{---} & 4.8  & 4.7      &  2   & \mc{---} & \mc{---} & \mc{---} & 0.1      \\
   \midrule
    \mcTwo{Third generation} & & & & & & & & & & & \\
   \midrule
    CMSX-10     & 69.6 &  2   &  3   & 0.4      & 5        & 5.7  & 0.2      &  8   & 6        & 0.1      & \mc{---} & 0.03     \\[1ex]
    Ren{\'e}~N6 & 57.4 &  4.2 & 12.5 & 1.4      & 6        & 5.75 & 0        &  7.2 & 5.4      & 0        & 0        & 0.15     \\
   \bottomrule
  \end{tabular}
\end{table}

\end{document}

output

Update

Another way of creating the table is using the S column from siunitx;

\documentclass{article}

\usepackage[
%  locale = DE % if you want a comma as decimal separator instead of a dot
]{siunitx}
%\usepackage[version = 3]{mhchem} % typesetting chemical formulae using \ce{}
\usepackage{booktabs}

\newcommand*\mcTwo[1]{\multicolumn{2}{l}{#1}}

\begin{document}

\begin{tabular}{
  c
  *{3}{S[table-format = 2.1]}
  *{2}{S[table-format = 1.1]}
       S[table-format = 1.2]
  *{4}{S[table-format = 1.1]}
       S[table-format = 1]
       S[table-format = 1.2]
}
 \toprule
  Alloy       & {Ni} & {Cr} & {Co} & {Mo}  & {W}   & {Al} & {Ti}  & {Ta} & {Re}  & {Nb}  & {V}   & {Hf}  \\
 \midrule
  \mcTwo{First generation} & & & & & & & & & & & \\
 \midrule
  PWA~1480    & 62.5 & 10   &  5   & {---} & 4     & 5    & 1.5   & 12   & {---} & {---} & {---} & {---} \\[1ex]
  Ren{\'e}~N4 & 62.6 &  9   &  8   & 2     & 6     & 3.7  & 4.2   &  4   & {---} & 0.5   & {---} & {---} \\[1ex]
  CMSX-2      & 66.6 &  8   &  4.6 & 0.6   & 7.9   & 5.6  & 0.9   &  5.8 & {---} & {---} & {---} & {---} \\[1ex]
  SRR~99      & 66.5 &  8.5 &  5   & {---} & 9.5   & 5.5  & 2.2   &  2.8 & {---} & {---} & {---} & {---} \\
 \midrule
  \mcTwo{Second generation} & & & & & & & & & & & \\
 \midrule
  PWA~1484    & 59.4 &  5   & 10   & 2     & 6     & 5.6  & {---} &  9   & 3     & {---} & {---} & {---} \\[1ex]
  Ren{\'e}~N5 & 61.8 &  7   &  8   & 2     & 5     & 6.2  & {---} &  7   & 3     & 0.5   & {---} & 0.2   \\[1ex]
  CMSX~4      & 61.8 &  6.5 &  9   & 0.6   & 6     & 5.6  & 1     &  6.5 & 3     & {---} & {---} & 0.1   \\[1ex]
  CMSX~6      & 70.4 & 10   &  5   & 3     & {---} & 4.8  & 4.7   &  2   & {---} & {---} & {---} & 0.1   \\
 \midrule
  \mcTwo{Third generation} & & & & & & & & & & & \\
 \midrule
  CMSX-10     & 69.6 &  2   &  3   & 0.4   & 5     & 5.7  & 0.2   &  8   & 6     & 0.1   & {---} & 0.03  \\[1ex]
  Ren{\'e}~N6 & 57.4 &  4.2 & 12.5 & 1.4   & 6     & 5.75 & 0     &  7.2 & 5.4   & 0     & 0     & 0.15  \\
 \bottomrule
\end{tabular}

\end{document}

(Personally, I prefer this method.)

Tags:

Tables