Generalproblem with table

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
coyote_001
Posts: 2
Joined: Sun Sep 21, 2008 10:44 pm

problem with table

Post by coyote_001 »

this is my 1st post, so hello to everyone !!!! 8-)

I have a little problem with a tabular table I've made....

I will post the code first

Code: Select all

\begin{table}[h]
\begin{center}

  \begin{tabular}{|r@{$\ \pm \ $}l||r@{$\ \pm \ $}l|}
    \hline
    \multicolumn{2}{|c||}{\textbf{Current}}		& \multicolumn{2}{|c|}{\textbf{Magnetic Field}}\\
    \multicolumn{2}{|c||}{\textbf{$I \pm \delta I  (A) ^1$}}	& \multicolumn{2}{|c|}{\textbf{$ B \pm \delta B  (mT) ^2$} }\\
    \hline
	0.00	& 0,01	& 17.46	& 0,01\\
    \hline
	1.00	& 0,01	& 87.6	& 0,1\\
    \hline
	2.01	& 0,01	& 169.6	& 1\\
    \hline
	2.95	& 0,01	& 248  	& 1\\
    \hline
	4.04	& 0,01	& 337	        & 1\\
    \hline
	5.00	& 0,01	& 418	        & 1\\
    \hline
	6.00	& 0,01	& 497 	& 1\\
    \hline
	6.95	& 0,01	& 578	        & 1\\
    \hline
	8.00	& 0,01	& 648	        & 1\\
    \hline
	9.14	& 0,01	& 709	        & 1\\
    \hline
	10.13	& 0,01	& 755 	& 1\\
    \hline
  \end{tabular}
  \caption{Magnetic field}
  \label{bathmonomisi}
\end{center}
\end{table}

The problem is that the data in the two columns is not centered......

thanks in advance
George

Recommended reading 2024:

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

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Annabel
Posts: 14
Joined: Mon Jun 16, 2008 3:21 pm

problem with table

Post by Annabel »

Hi Coyote_001

Welcome to the forum. The \begin{center} and \end{center} only places your table in the center of a page, but does not center your cells. \multicolumn{2}{|c||} only centers your column headings, but cell contents of the four columns are placed to the right, left, right, and left, which exactly makes the \pm symbol in the middle of the content of the first and second column and the third and fourth column. You could try something like:
\begin{table}[h]
\begin{center}

\begin{tabular}{|c||c|}
\hline
\textbf{Current} & \textbf{Magnetic Field}\\
\textbf{$I \pm \delta I (A) ^1$} & \textbf{$ B \pm \delta B (mT) ^2$}\\
\hline
0.00 $\pm$ 0,01 & 17.46 $\pm$ 0,01\\
\hline
1.00 $\pm$ 0,01 & 87.6 $\pm$ 0,1\\
%add the other content
\hline
10.13 $\pm$ 0,01 & 755 $\pm$ 1\\
\hline
\end{tabular}
\caption{Magnetic field}
\label{bathmonomisi}
\end{center}
\end{table}
This should not produce the output you want however. Therefore, I suggest to create a table with two columns and two rows, and remove \multicolumn. In the left cell of the second row you should create a minipage environment in which you place the content of the first two columns and in the right bottom cell, you should place a minipage environment with the content of the third and fourth column.

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

problem with table

Post by localghost »

Perhaps the dcolumn package from the tools bundle can help you.

Code: Select all

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage[english]{babel}
\usepackage[centering,includeheadfoot,margin=2cm]{geometry}
\usepackage[font=small,labelfont=bf]{caption}
\usepackage{array,booktabs,dcolumn}
\usepackage{txfonts}

\parindent0em
\newcolumntype{P}{D{+}{\;\pm\;}{4}}

\begin{document}
  \begin{table}[!ht]
    \centering
    \caption{Magnetic field}\label{bathmonomisi}
    \begin{tabular}{PP} \toprule
      \multicolumn{1}{c}{\textbf{Current}} & \multicolumn{1}{c}{\textbf{Magnetic Field}} \\
      \multicolumn{1}{c}{\textbf{$I \pm \delta I  (A) ^1$}} & \multicolumn{1}{c}{\textbf{$ B \pm \delta B  (mT) ^2$} } \\ \midrule[1pt]
      0.00+0.01 & 17.46+0.01 \\ \midrule
      1.00+0.01 & 87.6+0.1 \\ \midrule
      2.01+0.01 & 169.6+1 \\ \midrule
      2.95+0.01 & 248+1 \\ \midrule
      4.04+0.01 & 337+1 \\ \midrule
      5.00+0.01 & 418+1 \\ \midrule
      6.00+0.01 & 497+1 \\ \midrule
      6.95+0.01 & 578+1 \\ \midrule
      8.00+0.01 & 648+1 \\ \midrule
      9.14+0.01 & 709+1 \\ \midrule
      10.13+0.01 & 755+1 \\ \bottomrule
    \end{tabular}
  \end{table}
\end{document}
The documentation of dcolumn will tell you more. If you want to produce clear and readable tables, you should avoid vertical lines.


Best regards and welcome to the board
Thorsten¹
Post Reply