Graphics, Figures & TablesTricky table formatting

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Daqpan
Posts: 1
Joined: Thu Jan 20, 2011 5:11 pm

Tricky table formatting

Post by Daqpan »

Hi there

I have a table as follows:

Code: Select all

\begin{center}
\begin{table}
\begin{tabular}{ | p{2cm} | p{2cm} | p{2cm} | p{3.0cm} | p{3.6cm} |}
\hline
Beam \newline(pi mm rad) & $K$ & $\delta K$ & With Correlations \newline ($10^{5}$ Muons) & Without Correlations \newline ($10^{6}$ Muons)
\\
\hline
0.2 & 0.32324 & 11111 & 1.1 & 0\\\hline
1.5 & 0.40207 & 22222 & 1.7 & 0\\\hline
2.5 & 0.358213 & 33333 & 1.3 & 0\\\hline
3.0 & 0.356524 & 0.0444 & 1.3 & 0\\\hline
4.0 & 0.28058 & 0.5555 & 0.8 & 0\\\hline
6.0 & 0.19506 & 0.6666 & 3.8 & 0\\\hline
8.0 & 0.32752 & 0.7777 & 1.1 & 0\\\hline
10.0 & 0.31260 & 0.8888 & 1.0 & 0\\\hline
\end{tabular}
\caption{Estimated number of muons required with and without correlations for a range of beam conditions. Correlations in our measured sample of muons have the effect of reducing the total number of muons required by an order of magnitude.}
\label{nummuonstable}
\end{table}
\end{center}
I've used the p format specification so that I can be sure that the table headings wrap to two lines when necessary.
I would also like to use c. I haven't found a way to use both p and c , can anyone help?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Tricky table formatting

Post by localghost »

Daqpan wrote:[…] I've used the p format specification so that I can be sure that the table headings wrap to two lines when necessary.
I would also like to use c. I haven't found a way to use both p and c , can anyone help?
Please always provide a minimal example that is compilable as provided. Most of your problems can be solved with some minor tweaks to your table structure. The amazing siunitx package provides the alignment of the digits and formatting of numbers.

Code: Select all

\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[includeheadfoot,margin=2cm]{geometry}
\usepackage[%
  font=small,
  labelfont=bf,
  tableposition=top
]{caption}
\usepackage{booktabs,multirow}
\usepackage[%
  exponent-product=\cdot,
  load-configurations=abbreviations,
  output-decimal-marker={.}
]{siunitx}

\begin{document}
  \begin{table}[!ht]
    \centering
%    \small    % decrease font size if necessary
    \caption{Estimated number of muons required with and without correlations for a range of beam conditions. Correlations in our measured sample of muons have the effect of reducing the total number of muons required by an order of magnitude.}\label{tab:nummuons}
    \begin{tabular}{*5{S}} \toprule
      {Beam} & {\multirow{2}{*}{$K$}} & {\multirow{2}{*}{$\delta K$}} & {With Correlations} & {Without Correlations} \\
      {(pi mm rad)} & & & {(\num{e5} Muons)} & {(\num{e6} Muons)} \\ \midrule
      0.2 & 0.32324 & 11111 & 1.1 & 0 \\
      1.5 & 0.40207 & 22222 & 1.7 & 0 \\
      2.5 & 0.358213 & 33333 & 1.3 & 0 \\
      3.0 & 0.356524 & 0.0444 & 1.3 & 0 \\
      4.0 & 0.28058 & 0.5555 & 0.8 & 0 \\
      6.0 & 0.19506 & 0.6666 & 3.8 & 0 \\
      8.0 & 0.32752 & 0.7777 & 1.1 & 0 \\
      10.0 & 0.31260 & 0.8888 & 1.0 & 0 \\\bottomrule
    \end{tabular}
  \end{table}
\end{document}
You should avoid vertical lines to improve the legibility of tables. For more information see the manuals of the involved packages.


Best regards and welcome to the board
Thorsten
Post Reply