1

I'm having difficulties perfectly centering (both horizontally and vertically) a few cells in my table. Here is a screenshot of what it looks like right now:

Screenshot of my table

The problem line is the one which begins with "Courant", "Champ magnétique", etc.

The text is rather centered, but is frustratingly slightly aligned to the left...

Here is my code:

\begin{table}[h]
\centering
\caption{Variation de l'amplitude de la force électromotrice en fonction du courant circulant dans des bobines d'Helmholtz à une fréquence de rotation de la bobine d'induction constante ($(40\pm2)$ Hz)}
\label{tableau1}
\begin{tabular}{|>{\centering\arraybackslash}m{1.25cm}|>{\centering\arraybackslash}m{1.25cm}|>{\centering\arraybackslash}m{1.25cm}|>{\centering\arraybackslash}m{1.25cm}|>{\centering\arraybackslash}m{1.3cm}|>{\centering\arraybackslash}m{1.3cm}|>{\centering\arraybackslash}m{2cm}|>{\centering\arraybackslash}m{2cm}|}
\hline
\multicolumn{2}{|>{\centering\arraybackslash}m{2.5cm}|}{Courant} & \multicolumn{2}{>{\centering\arraybackslash}m{2.5cm}|}{Champ magnétique} & \multicolumn{2}{>{\centering\arraybackslash}m{2.6cm}|}{Force électromotrice expérimentale (amplitude)} & \multicolumn{2}{>{\centering\arraybackslash}m{4cm}|}{Force électromotrice théorique (amplitude)} \tabularnewline
\hline
$I_1$ & $\Delta I_1$ & $B$ & $\Delta B$ & $\epsilon_{Exp. 0}$ & $\Delta \epsilon_{Exp. 0}$ & $\epsilon_{Th. 0}$ & $\Delta \epsilon_{Th. 0}$ \tabularnewline
\hline
(A) & (A) & (mT) & (mT) & (V) & (V) & (V) & (V) \tabularnewline
\hline
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \tabularnewline
\hline
0,55 & 0,04 & 0,50 & 0,04 & 0,10 & 0,04 & 0,90 & 0,02 \tabularnewline
\hline
1,00 & 0,04 & 0,91 & 0,05 & 0,20 & 0,04 & 0,16 & 0,04 \tabularnewline
\hline
1,50 & 0,05 & 1,36 & 0,07 & 0,28 & 0,04 & 0,25 & 0,05 \tabularnewline
\hline
2,00 & 0,05 & 1,81 & 0,08 & 0,39 & 0,04 & 0,32 & 0,07 \tabularnewline
\hline
2,50 & 0,06 & 2,3 & 0,1 & 0,47 & 0,04 & 0,41 & 0,09 \tabularnewline
\hline
3,20 & 0,06 & 2,9 & 0,1 & 0,57 & 0,04 & 0,5 & 0,1 \tabularnewline
\hline
3,52 & 0,07 & 3,2 & 0,1 & 0,66 & 0,04 & 0,6 & 0,1 \tabularnewline
\hline
\end{tabular}
\end{table}

Thanks!

3

To get the right wide of the \multicolumn you have to add the right \tabcolsep from the first column and the left from the second column to the both column widths. For example:

\multicolumn{2}{|>{\centering\arraybackslash}m{\dimexpr2.5cm+2\tabcolsep\relax}|}{Courant}

enter image description here

Code:

\documentclass[captions=tableabove]{scrartcl}

\usepackage{array}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\newcolumntype{T}[1]{M{\dimexpr#1+2\tabcolsep\relax}}

\begin{document}
\begin{table}[htb]
  \centering
  \caption{Variation de l'amplitude de la force électromotrice en fonction du courant circulant dans des bobines d'Helmholtz à une fréquence de rotation de la bobine d'induction constante ($(40\pm2)$ Hz)}
  \label{tableau1}
  \begin{tabular}{|*{4}{M{1.25cm}|}*{2}{M{1.3cm}|}*{2}{M{1.8cm}|}}
    \hline
    \multicolumn{2}{|T{2.5cm}|}{Courant} 
      & \multicolumn{2}{T{2.5cm}|}{Champ magnétique} 
      & \multicolumn{2}{T{2.6cm}|}{Force électromotrice expérimentale (amplitude)} 
      & \multicolumn{2}{T{3.6cm}|}{Force électromotrice théorique (amplitude)} \tabularnewline
    \hline
    $I_1$ & $\Delta I_1$ & $B$ & $\Delta B$ & $\epsilon_{Exp. 0}$ & $\Delta \epsilon_{Exp. 0}$ & $\epsilon_{Th. 0}$ & $\Delta \epsilon_{Th. 0}$ \tabularnewline
    \hline
    (A) & (A) & (mT) & (mT) & (V) & (V) & (V) & (V) \tabularnewline
    \hline
    0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \tabularnewline
    \hline
    0,55 & 0,04 & 0,50 & 0,04 & 0,10 & 0,04 & 0,90 & 0,02 \tabularnewline
    \hline
    1,00 & 0,04 & 0,91 & 0,05 & 0,20 & 0,04 & 0,16 & 0,04 \tabularnewline
    \hline
    1,50 & 0,05 & 1,36 & 0,07 & 0,28 & 0,04 & 0,25 & 0,05 \tabularnewline
    \hline
    2,00 & 0,05 & 1,81 & 0,08 & 0,39 & 0,04 & 0,32 & 0,07 \tabularnewline
    \hline
    2,50 & 0,06 & 2,3 & 0,1 & 0,47 & 0,04 & 0,41 & 0,09 \tabularnewline
    \hline
    3,20 & 0,06 & 2,9 & 0,1 & 0,57 & 0,04 & 0,5 & 0,1 \tabularnewline
    \hline
    3,52 & 0,07 & 3,2 & 0,1 & 0,66 & 0,04 & 0,6 & 0,1 \tabularnewline
    \hline
  \end{tabular}
\end{table}
\end{document}
1
  • \multicolumn{2}{|>{\centering\arraybackslash}m{\dimexpr2.5cm+2\tabcolsep\relax}|}{Courant} works perfectly! – Melian Aug 1 '14 at 14:32
1

As a possible solution I would use the package makecell. Voilà:

\documentclass[a4paper, 12pt]{article}

\usepackage[utf8]{inputenc}
\usepackage[english,french]{babel}
\usepackage{makecell}

\begin{document}

%makecell setting for fonts, spacing etc.
\setlength\rotheadsize{3cm}
\renewcommand\theadfont{\small}
\renewcommand\theadfont{\bfseries}
\renewcommand\theadset{\renewcommand\arraystretch{0.9}%
\setlength\extrarowheight{1pt}}
\renewcommand\cellalign{cc}
\renewcommand\cellgape{\Gape[1pt]}


\begin{table}[h]
\centering
\caption{Variation de l'amplitude de la force électromotrice en fonction du courant circulant dans des bobines d'Helmholtz à une fréquence de rotation de la bobine d'induction constante ($(40\pm2)$ Hz)}
\vspace{1ex}
\label{tableau1}
\begin{tabular}{*{8}{|m{1.25cm}}|}
\hline
\multicolumn{2}{|c|}{\thead{Courant}} & \multicolumn{2}{c|}{\thead{Champ\\ magnétique}} & \multicolumn{2}{c|}{\thead{Force\\ électromotrice\\ expérimentale\\ (amplitude)}} & \multicolumn{2}{c|}{\thead{Force\\ électromotrice\\ théorique\\ (amplitude)}} \tabularnewline
\hline
\makecell{$I_1$} & \makecell{$\Delta I_1$} & \makecell{$B$} & \makecell{$\Delta B$} & \makecell{$\epsilon_{Exp. 0}$} & \makecell{$\Delta \epsilon_{Exp. 0}$} & \makecell{$\epsilon_{Th. 0}$} & \makecell{$\Delta \epsilon_{Th. 0}$} \tabularnewline
\hline
\makecell{(A)} & \makecell{(A)} & \makecell{(mT)} & \makecell{(mT)} & \makecell{(V)} & \makecell{(V)} & \makecell{(V)} & \makecell{(V)} \tabularnewline
\hline
\makecell{0} & \makecell{0} & \makecell{0} & \makecell{0} & \makecell{0} & \makecell{0} & \makecell{0} & \makecell{0} \tabularnewline
\hline
\makecell{0,55} & \makecell{0,04} & \makecell{0,50} & \makecell{0,04} & \makecell{0,10} & \makecell{0,04} & \makecell{0,90} & \makecell{0,02} \tabularnewline
\hline
\makecell{1,00} & \makecell{0,04} & \makecell{0,91} & \makecell{0,05} & \makecell{0,20} & \makecell{0,04} & \makecell{0,16} & \makecell{0,04} \tabularnewline
\hline
\makecell{1,50} & \makecell{0,05} & \makecell{1,36} & \makecell{0,07} & \makecell{0,28} & \makecell{0,04} & \makecell{0,25} & \makecell{0,05} \tabularnewline
\hline
\makecell{2,00} & \makecell{0,05} & \makecell{1,81} & \makecell{0,08} & \makecell{0,39} & \makecell{0,04} & \makecell{0,32} & \makecell{0,07} \tabularnewline
\hline
\makecell{2,50} & \makecell{0,06} & \makecell{2,3} & \makecell{0,1} & \makecell{0,47} & \makecell{0,04} & \makecell{0,41} & \makecell{0,09} \tabularnewline
\hline
\makecell{3,20} & \makecell{0,06} & \makecell{2,9} & \makecell{0,1} & \makecell{0,57} & \makecell{0,04} & \makecell{0,5} & \makecell{0,1} \tabularnewline
\hline
\makecell{3,52} & \makecell{0,07} & \makecell{3,2} & \makecell{0,1} & \makecell{0,66} & \makecell{0,04} & \makecell{0,6} & \makecell{0,1} \tabularnewline
\hline
\end{tabular}
\end{table}
\end{document}

enter image description here

0

I re-designed the table, also using the makecell package for column heads, with S type columns, to have alignment on decimal comma (from siunitx) and finally threeparttable so that the caption has the same widthj as the table. No vertical lines, that's bad typographical practice:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{mathtools} 
\usepackage{array, tabularx}
\usepackage{booktabs}
\usepackage{ragged2e}
\newcolumntype{Y}{ >{\hsize=1.75\hsize}X}
\newcolumntype{Z}{ >{\hsize=.875\hsize\RaggedLeft}X}
\usepackage{caption}
\usepackage{makebox} 
\captionsetup{font = small}
\usepackage{makecell}
\renewcommand{\theadfont}{\upshape\bfseries\footnotesize}
\setcellgapes{3pt}
\makegapedcells
\usepackage{threeparttable}
\usepackage{siunitx}

\usepackage[french]{babel}

\begin{document}

\begin{table}[h]
    \begin{threeparttable}
\centering\sisetup{table-number-alignment = center, table-figures-integer=1, table-figures-decimal=2, locale = FR}
\caption{Variation de l'amplitude de la force électromotrice en fonction du courant circulant dans des bobines d'Helmholtz à une fréquence de rotation de la bobine d'induction constante ($(40\pm2)$ Hz)}
\label{tableau1}
\begin{tabular}{SSSSSSSS}
\Xhline{0.8pt}
 \multicolumn{2}{c}{\thead{Courant}} & \multicolumn{2}{c}{\thead{Champ\\magnétique}} & \multicolumn{2}{c}{\thead{Force\\ électromotrice\\ expérimentale\\ (amplitude)}} & \multicolumn{2}{c}{\thead{Force\\ électromotrice\\ théorique\\ (amplitude)}} \\[-0.5ex]
\hline\noalign{\vskip3pt}
{$I_1 $} & {$Δ I_1$} & {$B$} & {$Δ B$} & \clap{$ϵ_\mathrm{Exp. 0}$} & \clap{$Δ ϵ_\mathrm{Exp. 0} $} & \clap{$ϵ_\mathrm{Th. 0}$} & \clap{$Δ ϵ_\mathrm{Th. 0}$} \\[-0.4ex]
\multicolumn{2}{c}{\small(A)} & \multicolumn{2}{c}{\small(mT)} & \multicolumn{2}{c}{\small(V)} & \multicolumn{2}{c}{\small(V)} \\[0.6ex]
\hline\noalign{\vskip1pt}
{0} & {0} & {0} & {0} & {0} & {0} & {0} & {0} \\[1pt]
0,55 & 0,04 & 0,50 & 0,04 & 0,10 & 0,04 & 0,90 & 0,02 \tabularnewline
1,00 & 0,04 & 0,91 & 0,05 & 0,20 & 0,04 & 0,16 & 0,04 \tabularnewline
1,50 & 0,05 & 1,36 & 0,07 & 0,28 & 0,04 & 0,25 & 0,05 \tabularnewline
 2,00 & 0,05 & 1,81 & 0,08 & 0,39 & 0,04 & 0,32 & 0,07 \tabularnewline
 2,50 & 0,06 & 2,3 & 0,1 & 0,47 & 0,04 & 0,41 & 0,09 \tabularnewline
 3,20 & 0,06 & 2,9 & 0,1 & 0,57 & 0,04 & 0,5 & 0,1 \tabularnewline
 3,52 & 0,07 & 3,2 & 0,1 & 0,66 & 0,04 & 0,6 & 0,1 \tabularnewline
\Xhline{0.8pt}
\end{tabular}
\end{threeparttable}
\end{table}

\end{document} 

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.