表格的标题应该在左侧,并且标题和表格之间没有空格。F2 和 F3 应该分两行。第 1、3 和 4 列的内容居中。我希望它与附图中的表格完全一样。
这是我的代码
\documentclass{elsarticle}
\usepackage{booktabs}
\usepackage{amsmath}
\usepackage{siunitx}
\usepackage{booktabs, makecell, multirow}
\usepackage{caption}
\captionsetup[table]{format=plain,labelformat=simple,labelsep=period}%
\begin{document}
\begin{table}[]
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{@{}llll@{}}
\toprule
F & Formula & f(x) & Search range \\ \midrule
1 & $\begin{array} {lcl} f(x) & = & \sum_{i=1}^{n} \frac{x_i^{2}}{4000} - \prod_{i=1}^{n}cos(\frac{x_i}{\sqrt{i}}) + 1 \end{array}$ & 0 & [-100, 100]\\
2 & $\begin{array} {lcl} f(x) & = & \frac{\pi}{n}10\sin (\pi {y_1})
$+$ \sum_{i=1}^{n-1} {{( {{y_i} - 1})}^2}[{1 + 10{{\sin }^2}(\pi{y_{i + 1}})}] +(y_n -1)^{2}+\sum_{i=1}^{n}u(x_i,10,100,4) \end{array}$ & 0 & [-100, 100]\\
& $\begin{array} {lcl}
u(x)
u({x_i},a,k,m) =
\begin{cases}
k{({x_i} - a)^m} & \,\,\,\,\,\,\,\,\,{x_i} > a\\
0 & \,\,\,\,\,\,\,\,\,\, - a < {x_i} < a\\
k{( - {x_i} - a)^m} &\,\,\,\,\,\,\,\,\, {x_i} < - a
\end{cases} &
\end{array}$ \\
3 & $\begin{array} {lcl} f\left( x \right) = 0.1\left\{ {{{\sin }^2}(3\pi {x_1}) + \mathop \sum \limits_{i = 1}^{n - 1} {{\left( {{x_i} - 1} \right)}^2}\left[ {1 + {{\sin }^2}(3\pi {x_i} + 1)} \right] + {{({x_n} - 1)}^2}\left[ {1 + {{\sin }^2}(2\pi {x_n})} \right]} \right\} + \sum\limits_{i = 1}^n {u({x_i},5,100,4)}
\end{array}$ & 0 & [-100, 100]\\
\\ \bottomrule
\end{tabular}
\end{table}
\end{document}
答案1
像这样吗?
\documentclass{elsarticle}
\usepackage{booktabs,amsmath,caption,array}
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}
\newlength\mylen
\newcommand\myrange{$[-100, 100]$}
\settowidth\mylen{\myrange}
\usepackage{newtxtext,newtxmath}
\captionsetup[table]{format=plain,
labelfont=bf,
labelsep=newline,
singlelinecheck=false,
skip=0pt}
\begin{document}
\begin{table}
\caption{Table caption here.}
\label{my-label}
$\begin{array}{@{} clcC{\mylen} @{}}
\toprule
\text{F} & \multicolumn{1}{c}{\text{Formula}}
& f_{\min} & \text{Search} \text{range} \\
\midrule
\text{F1} &
\begin{aligned}
&f(x) = \frac{1}{4000}\sum_{i=1}^{n} x_i^2
-\prod_{i=1}^n \cos\Bigl(\frac{x_i}{\sqrt{i}}\Bigr) + 1
\end{aligned}
& 0 & \myrange\\
\cmidrule{1-4}
\text{F2} &
\begin{aligned}
&f(x) = \Bigl\{ \frac{\pi}{n} 10\sin (\pi y_1)
+ \sum_{i=1}^{n-1} (y_i - 1)^2
\bigl[ 1 + 10\sin^2(\pi y_{i+1}) \bigr] \\
&\qquad\quad+(y_n -1)^2 \Bigr\} +\sum_{i=1}^n u(x_i,10,100,4)\\
&y_i=1+\frac{x_i+1}{4} \\
&u({x_i},a,k,m) =
\begin{cases}
k(x_i - a)^m & x_i > a\\
0 & - a < x_i < a\\
k(-x_i- a)^m & x_i < - a
\end{cases}
\end{aligned}
& 0 & \myrange\\
\cmidrule{1-4}
\text{F3} &
\begin{aligned}
&f(x) = 0.1\Bigl\{ \sin^2(3\pi x_1) +
\sum_{i=1}^{n-1}(x_i-1)^2
\bigl[1 +\sin^2(3\pi x_i + 1) \bigr] \\
&\qquad\quad+(x_n-1)^2\bigl[1 +\sin^2(2\pi x_n)
\bigr] \Bigr\}
+ \sum_{i=1}^n u(x_i,5,100,4)
\end{aligned}
& 0 & \myrange\\
\bottomrule
\end{array}$
\end{table}
\end{document}
我所做的一些主要更改是(i)使用array
环境而不是tabular
环境,因为几乎所有的内容都在数学模式中;(ii)使用aligned
环境来容纳第 2 列中的公式;(iii)删除大量除了造成代码混乱之外没有任何作用的花括号,删除\,\,\,\,\,\,\,\,\,
;(iv)花括号和方括号没有自动调整大小,以及(v)为长公式选择不同的换行符。