[Tex/LaTex] A column that is too wide

tables

I have a table in which the header is making the last column too wide. How do I avoid this situation?

\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}


\usepackage{array}
\usepackage{makecell}


\setlength{\oddsidemargin}{0.0in}
\setlength{\evensidemargin}{0.0in} \setlength{\textwidth}{6.1in}
\setlength{\topmargin}{0.0in} \setlength{\textheight}{9in}


\begin{document}
\setlength\extrarowheight{2pt}
\begin{tabular}{|| c !{\vrule width0.8pt}c | c | c | c | c | c | c | c | c ||} \hline
\multicolumn{10}{|| c ||}{{\textbf{Force in newtons required to move an object \boldmath$x$ meters\unboldmath}}} \\ \Xhline{0.8pt}
    $x$     &   4   &   6   &   8   &   10  &   12  &   14  &   16  &   18  &   20  \\ \hline
    $f(x)$  &   5   &   5.8 &   7   &   8.8 &   9.6 &   8.2 &   6.7 &   5.2 &   4.1 \\ \hline
\end{tabular}

\end{document}

Best Answer

I suggest you use a tabularx environment instead of the basic tabular environment. Moreover, I think the nine data columns should have equal widths. Use a \settowidth instruction to calculate the required width of the tabularx. You may also want to get rid of all vertical lines, to give the table a more "open" look.

enter image description here

\documentclass{amsart}
\usepackage{bm,booktabs,tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}

\newcommand\myheader{\bfseries Force in Newton required to move an object $\bm x$ meters}

\newlength\mylength
\settowidth{\mylength}{\myheader}

\begin{document}

\noindent
\begin{tabularx}{\mylength}{@{} l *{9}{C} @{}} 
\toprule
\multicolumn{10}{@{}c@{}}{\myheader} \\ % re-use the \myheader macro
\midrule
$x$    & 4 & 6   & 8 & 10  &  12 & 14  & 16  & 18  & 20  \\ 
$F(x)$ & 5 & 5.8 & 7 & 8.8 & 9.6 & 8.2 & 6.7 & 5.2 & 4.1 \\
\bottomrule
\end{tabularx}

\end{document}

Addendum to address the OP's follow-up comment: If you do want the vertical bars, you can't use the line-drawing macros of the booktabs package. Instead, I suggest you insert (typographic) struts to provide a bit more vertical whitespace.

enter image description here

\documentclass{amsart}
\usepackage{bm,tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}

\newcommand\myheader{\bfseries Force in Newton required to move an object $\bm x$ meters}

\newlength\mylength
\settowidth{\mylength}{\myheader}
\addtolength{\mylength}{2\tabcolsep}
\addtolength{\mylength}{2\arrayrulewidth}

%% define a few struts
%% (from code by Claudio Beccari in TeX and TUG News, Vol. 2, 1993)
\newcommand\Tstrut{\rule{0pt}{2.9ex}}         % "top" strut
\newcommand\Bstrut{\rule[-1.2ex]{0pt}{0pt}}   % "bottom" strut
\newcommand\TBstrut{\Tstrut\Bstrut}           % "top-and-bottom" strut

\begin{document}

\noindent
\begin{tabularx}{\mylength}{ |l| *{9}{C|} } 
\hline
\multicolumn{10}{|c|}{\myheader\TBstrut} \\ % re-use the \myheader macro
\hline
$x$\TBstrut    & 4 & 6   & 8 & 10  &  12 & 14  & 16  & 18  & 20  \\
\hline 
$F(x)$\TBstrut & 5 & 5.8 & 7 & 8.8 & 9.6 & 8.2 & 6.7 & 5.2 & 4.1 \\
\hline
\end{tabularx}

\end{document}