我有一个表格,其中表头使得最后一列太宽。如何避免这种情况?
\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}
答案1
我建议您使用tabularx
环境而不是基本tabular
环境。此外,我认为九个数据列应该具有相同的宽度。使用\settowidth
指令来计算所需的宽度tabularx
。您可能还想摆脱所有垂直线,以使表格看起来更“开放”。
\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}
附录回应 OP 的后续评论:如果您确实想要竖线,则不能使用包的线条绘制宏booktabs
。相反,我建议您插入(印刷)支柱以提供更多垂直空白。
\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}
答案2
最后一列太宽,因为“标题”相对于表格其余部分的自然宽度来说太宽。我提出了一个单元格宽度相等的解决方案:它使用eqparbox
和tabularx
包并确保 tabularx 表格具有最小宽度。此外,我使用hhline
s 来使水平规则和双垂直规则正确相交。
\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{makecell}
\renewcommand\theadfont{\normalsize\bfseries\boldmath}
\usepackage{tabularx, eqparbox, hhline}
\setlength{\oddsidemargin}{0.0in}
\setlength{\evensidemargin}{0.0in} \setlength{\textwidth}{6.1in}
\setlength{\topmargin}{0.0in} \setlength{\textheight}{9in}
\begin{document}
\centering
\setcellgapes{4pt}\makegapedcells
\begin{tabularx}{\dimexpr\eqboxwidth{H}+2\tabcolsep+2\doublerulesep + 4\arrayrulewidth\relax}
{||c !{\vrule width0.8pt}*{9}{>{\centering\arraybackslash}X|}|}
\hline
\multicolumn{10}{||c||}{\eqmakebox[H]{\bfseries\boldmath Force required to move an object $x$ meters (in newtons)}} \\
\hhline{||*{10}{-}||}
\hhline{||*{10}{-}||}
$x$ & 4 & 6 & 8 & 10 & 12 & 14 & 16 & 18 & 20 \\
\hhline{||*{10}{-}||}
$f(x)$ & 5 & 5.8 & 7 & 8.8 & 9.6 & 8.2 & 6.7 & 5.2 & 4.1 \\
\hline
\end{tabularx}
\end{document}
答案3
看来您是 Latex 的新手。您标记表格的主要目的可以通过以下简单代码来实现。
\documentclass{amsart}
\usepackage{makecell}
\begin{document}
\begin{table}
\centering
\caption{Force in newtons required to move an object \boldmath$x$ meters\unboldmath}
\begin{tabular}{|| c !{\vrule width0.8pt}c | c | c | c | c | c | c | c | c ||} \hline
$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{table}
\end{document}
编辑:但是,如果您坚持将标题括在表格内,那么这是从源头衍生的另一种替代方法:关于 tex 的一个老问题
\documentclass{article}
\usepackage{bm,array}
\begin{document}
\newcolumntype{C}{>{\centering\arraybackslash}p{2em}}
\begin{table}
\centering
\begin{tabular}{|| c !{\vrule width0.8pt}C|C|C|C|C|C|C|C|C||}
\hline
\multicolumn{10}{|c|}{Force in newtons required to move an object \boldmath$x$ meters\unboldmath} \\
\hline
$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{table}
\end{document}