我有一组数值优化的基准问题,我想将它们汇编成表格。该表由函数名称、函数定义、搜索范围和理论全局最优值组成。问题是方程式不适合表格。我使用的是 tabularx,如 MWE 中所示:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{tabularx}
\usepackage{geometry}
\geometry{
a4paper,
left=30mm,
right=25mm,
top=30mm,
bottom=30mm,
asymmetric
}
\begin{document}
\begin{table}
\begin{tabularx}{\textwidth}{|l|X|X|X|}
\hline
\textbf{Name} & \textbf{Definition} & \textbf{Search range} & \textbf{Global optimum}\\
\hline
Sphere & $f_1(\vec{x}) = \sum_{i=1}^{D} x_i^2$ & $[-5.12, 5.12]^D$ & $f_1(\vec{0}) = 0$\\
\hline
Rosenbrock & $f_2(\vec{x}) = \sum_{i=1}^{D-1} (100 (x_{i+1} - x_i^2)^2 + (x_i - 1)^2) $ & $[-2.048, 2.048]^D$ & $f_2(\vec{1}) = 0$\\
\hline
Rastrigin & $f_3(\vec{x}) = 10D + \sum_{i=1}^D \left(x_i^2 -10\cos(2\pi x_i)\right) $ & $[-5.12, 5.12]^D$ & $f_3(\vec{0}) = 0$\\
\hline
Griewank & $f_4(\vec{x}) = \sum_{i=1}^D \frac{x_i^2}{4000} - \prod_{i=1}^D \cos(\frac{x_i}{\sqrt{i}}) + 1 $ & $[-600, 600]^D$ & $f_4(\vec{0}) = 0$\\
\hline
Ackley & $f_5(\vec{x}) = -a\;\exp\left(-b \sqrt{\frac{1}{D} \sum_{i=1}^D x_i^2}\right) - \exp\left(\frac{1}{D} \sum_{i=1}^D \cos(c\;x_i)\right) + a + \exp(1) $& $[-32.768, 32.768]^D$ & $f_5(\vec{0}) = 0$\\
\hline
Schwefel & $f_6(\vec{x}) = 418.9829d - \sum_{i=1}^{D} x_i \sin(\sqrt{\lvert x_i \rvert}) $ & $[-500, 500]^D$ & $f_6(\vec{420.9687}) = 0$\\
\hline
Alpine & $f_7(\vec{x}) = \sum_{i=1}^{D} \lvert x_i \sin(x_i)+0.1x_i \rvert $ & $[-10, 10]^D$ & $f_7(\vec{0}) = 0$\\
\hline
Whitley & $f_8(\vec{x}) = \sum_{i=1}^D \sum_{j=1}^D \left(\frac{(100(x_i^2-x_j)^2 + (1-x_j)^2)^2}{4000} - \cos(100(x_i^2-x_j)^2 + (1-x_j)^2)+1\right) $ & $[-10, 10]^D$ & $f_8(\vec{1}) = 0$\\
\hline
Csendes & $f_9(\vec{x}) = \sum_{i=1}^D x_i^6\left( 2 + \sin \frac{1}{x_i}\right) $ & $[-1, 1]^D$ & $f_9(\vec{0}) = 0$\\
\hline
Dixon Price & $f_{10}(\vec{x}) = (x_1 - 1)^2 + \sum_{i = 2}^D i (2x_i^2 - x_{i - 1})^2 $ & $[-10, 10]^D$ & $f_{10}(x^*) = 0 \; x_i = 2^{-\frac{2^i - 2}{2^i}} $\\
\hline
\end{tabularx}
\end{table}
\end{document}
有没有办法让所有的数学运算都适合单元格,并使这个表格看起来更美观?过去几个小时我一直在为此烦恼。我还尝试使用 lscape 包将其置于横向,并将宽度设置为 24 厘米,但仍然不适合。任何帮助都将不胜感激。
答案1
您可以考虑非表格布局
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{description}
\item [sphere] Search range $[-5.12, 5.12]^D$, Global optimum $f_1(\vec{0}) = 0$
\[f_1(\vec{x}) = \sum_{i=1}^{D} x_i^2\]
\item[Rosenbrock] Search Range $[-2.048, 2.048]^D$, Global optimum $f_2(\vec{1}) = 0$
\[f_2(\vec{x}) = \sum_{i=1}^{D-1} (100 (x_{i+1} - x_i^2)^2 + (x_i - 1)^2)\]
\item[Rastrigin] Search Range $[-5.12, 5.12]^D$, Global optimum $f_3(\vec{0}) = 0$
\[f_3(\vec{x}) = 10D + \sum_{i=1}^D \left(x_i^2 -10\cos(2\pi x_i)\right) \]
\item[Griewank] Search Range $[-600, 600]^D$, Global optimum $f_4(\vec{0}) = 0$
\[ f_4(\vec{x}) = \sum_{i=1}^D \frac{x_i^2}{4000} - \prod_{i=1}^D \cos(\frac{x_i}{\sqrt{i}}) + 1 \]
\item[Ackley] Search Range $[-32.768, 32.768]^D$, Global optimum $f_5(\vec{0}) = 0$
\[ f_5(\vec{x}) = -a\;\exp\left(-b \sqrt{\frac{1}{D} \sum_{i=1}^D x_i^2}\right) - \exp\left(\frac{1}{D} \sum_{i=1}^D \cos(c\;x_i)\right) + a + \exp(1) \]
\item[Schwefel] Search Range $[-500, 500]^D$, Global optimum $f_6(\vec{420.9687}) = 0$
\[ f_6(\vec{x}) = 418.9829d - \sum_{i=1}^{D} x_i \sin(\sqrt{\lvert x_i \rvert}) \]
\item[Alpine] Search Range $[-10, 10]^D$, Global optimum $f_7(\vec{0}) = 0$
\[ f_7(\vec{x}) = \sum_{i=1}^{D} \lvert x_i \sin(x_i)+0.1x_i \rvert \]
\item[Whitley] Search Range $[-10, 10]^D$, Global optimum $f_8(\vec{1}) = 0$
\[ f_8(\vec{x}) = \sum_{i=1}^D \sum_{j=1}^D \left(\frac{(100(x_i^2-x_j)^2 + (1-x_j)^2)^2}{4000} - \cos(100(x_i^2-x_j)^2 + (1-x_j)^2)+1\right) \]
\item[Csendes] Search Range $[-1, 1]^D$, Global optimum $f_9(\vec{0}) = 0$
\[ f_9(\vec{x}) = \sum_{i=1}^D x_i^6\left( 2 + \sin \frac{1}{x_i}\right) \]
\item[Dixon Price] Search Range $[-10, 10]^D$, Global optimum $f_{10}(x^*) = 0 \; x_i = 2^{-\frac{2^i - 2}{2^i}} $
\[ f_{10}(\vec{x}) = (x_1 - 1)^2 + \sum_{i = 2}^D i (2x_i^2 - x_{i - 1})^2 \]
\end{description}
\end{document}
答案2
以下是其他一些替代方案:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{tabularx}
\usepackage{geometry}
\geometry{
a4paper,
left=30mm,
right=25mm,
top=30mm,
bottom=30mm,
asymmetric
}
\usepackage{pdflscape}
\usepackage{enumitem}
\usepackage{booktabs}
\begin{document}
\begin{landscape}
\begin{table}
\begin{tabular}{|l|l|l|l|}
\hline
\textbf{Name} & \textbf{Definition} & \textbf{Search range} & \textbf{Global optimum}\\
\hline
Sphere & $f_1(\vec{x}) = \sum_{i=1}^{D} x_i^2$ & $[-5.12, 5.12]^D$ & $f_1(\vec{0}) = 0$\\
\hline
Rosenbrock & $f_2(\vec{x}) = \sum_{i=1}^{D-1} (100 (x_{i+1} - x_i^2)^2 + (x_i - 1)^2) $ & $[-2.048, 2.048]^D$ & $f_2(\vec{1}) = 0$\\
\hline
Rastrigin & $f_3(\vec{x}) = 10D + \sum_{i=1}^D \left(x_i^2 -10\cos(2\pi x_i)\right) $ & $[-5.12, 5.12]^D$ & $f_3(\vec{0}) = 0$\\
\hline
Griewank & $f_4(\vec{x}) = \sum_{i=1}^D \frac{x_i^2}{4000} - \prod_{i=1}^D \cos(\frac{x_i}{\sqrt{i}}) + 1 $ & $[-600, 600]^D$ & $f_4(\vec{0}) = 0$\\
\hline
Ackley & $f_5(\vec{x}) = -a\;\exp\left(-b \sqrt{\frac{1}{D} \sum_{i=1}^D x_i^2}\right) - \exp\left(\frac{1}{D} \sum_{i=1}^D \cos(c\;x_i)\right) + a + \exp(1) $& $[-32.768, 32.768]^D$ & $f_5(\vec{0}) = 0$\\
\hline
Schwefel & $f_6(\vec{x}) = 418.9829d - \sum_{i=1}^{D} x_i \sin(\sqrt{\lvert x_i \rvert}) $ & $[-500, 500]^D$ & $f_6(\vec{420.9687}) = 0$\\
\hline
Alpine & $f_7(\vec{x}) = \sum_{i=1}^{D} \lvert x_i \sin(x_i)+0.1x_i \rvert $ & $[-10, 10]^D$ & $f_7(\vec{0}) = 0$\\
\hline
Whitley & $f_8(\vec{x}) = \sum_{i=1}^D \sum_{j=1}^D \left(\frac{(100(x_i^2-x_j)^2 + (1-x_j)^2)^2}{4000} - \cos(100(x_i^2-x_j)^2 + (1-x_j)^2)+1\right) $ & $[-10, 10]^D$ & $f_8(\vec{1}) = 0$\\
\hline
Csendes & $f_9(\vec{x}) = \sum_{i=1}^D x_i^6\left( 2 + \sin \frac{1}{x_i}\right) $ & $[-1, 1]^D$ & $f_9(\vec{0}) = 0$\\
\hline
Dixon Price & $f_{10}(\vec{x}) = (x_1 - 1)^2 + \sum_{i = 2}^D i (2x_i^2 - x_{i - 1})^2 $ & $[-10, 10]^D$ & $f_{10}(x^*) = 0 \; x_i = 2^{-\frac{2^i - 2}{2^i}} $\\
\hline
\end{tabular}
\end{table}
\end{landscape}
\begin{table}
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{ll}
\toprule
Name & Definition, Search Range, Global optimum \\
\midrule
Sphere & $f_1(\vec{x}) = \sum_{i=1}^{D} x_i^2$ \\
& $[-5.12, 5.12]^D$ \\
& $f_1(\vec{0}) = 0$\\
\addlinespace
Rosenbrock & $f_2(\vec{x}) = \sum_{i=1}^{D-1} (100 (x_{i+1} - x_i^2)^2 + (x_i - 1)^2) $ \\
& $[-2.048, 2.048]^D$ \\
& $f_2(\vec{1}) = 0$\\
\addlinespace
Rastrigin & $f_3(\vec{x}) = 10D + \sum_{i=1}^D \left(x_i^2 -10\cos(2\pi x_i)\right) $ \\
& $[-5.12, 5.12]^D$ \\
& $f_3(\vec{0}) = 0$\\
\addlinespace
Griewank & $f_4(\vec{x}) = \sum_{i=1}^D \frac{x_i^2}{4000} - \prod_{i=1}^D \cos(\frac{x_i}{\sqrt{i}}) + 1 $ \\
& $[-600, 600]^D$ \\
& $f_4(\vec{0}) = 0$\\
\addlinespace
Ackley & $f_5(\vec{x}) = -a\;\exp\left(-b \sqrt{\frac{1}{D} \sum_{i=1}^D x_i^2}\right) - \exp\left(\frac{1}{D} \sum_{i=1}^D \cos(c\;x_i)\right) + a + \exp(1) $ \\
& $[-32.768, 32.768]^D$ \\
& $f_5(\vec{0}) = 0$\\
\addlinespace
Schwefel & $f_6(\vec{x}) = 418.9829d - \sum_{i=1}^{D} x_i \sin(\sqrt{\lvert x_i \rvert}) $ \\
& $[-500, 500]^D$ \\
& $f_6(\vec{420.9687}) = 0$\\
\addlinespace
Alpine & $f_7(\vec{x}) = \sum_{i=1}^{D} \lvert x_i \sin(x_i)+0.1x_i \rvert $ \\
& $[-10, 10]^D$ \\
& $f_7(\vec{0}) = 0$\\
\addlinespace
Whitley & $f_8(\vec{x}) = \sum_{i=1}^D \sum_{j=1}^D \left(\frac{(100(x_i^2-x_j)^2 + (1-x_j)^2)^2}{4000} - \cos(100(x_i^2-x_j)^2 + (1-x_j)^2)+1\right) $ \\
& $[-10, 10]^D$ \\
& $f_8(\vec{1}) = 0$\\
\addlinespace
Csendes & $f_9(\vec{x}) = \sum_{i=1}^D x_i^6\left( 2 + \sin \frac{1}{x_i}\right) $ \\
& $[-1, 1]^D$ \\
& $f_9(\vec{0}) = 0$\\
\addlinespace
Dixon Price & $f_{10}(\vec{x}) = (x_1 - 1)^2 + \sum_{i = 2}^D i (2x_i^2 - x_{i - 1})^2 $ \\
& $[-10, 10]^D$ \\
& $f_{10}(x^*) = 0 \; x_i = 2^{-\frac{2^i - 2}{2^i}} $\\
\bottomrule
\end{tabular}
\end{table}
\begin{itemize}[leftmargin=*]
\item Sphere
\begin{itemize}
\item Definition: $f_1(\vec{x}) = \sum_{i=1}^{D} x_i^2$
\item Search range: $[-5.12, 5.12]^D$
\item Global optimum: $f_1(\vec{0}) = 0$
\end{itemize}
\item Rosenbrock
\begin{itemize}
\item Definition: $f_2(\vec{x}) = \sum_{i=1}^{D-1} (100 (x_{i+1} - x_i^2)^2 + (x_i - 1)^2) $
\item Search range: $[-2.048, 2.048]^D$
\item Global optimum: $f_2(\vec{1}) = 0$
\end{itemize}
\item Rastrigin
\begin{itemize}
\item Definition: $f_3(\vec{x}) = 10D + \sum_{i=1}^D \left(x_i^2 -10\cos(2\pi x_i)\right) $
\item Search range: $[-5.12, 5.12]^D$
\item Global optimum: $f_3(\vec{0}) = 0$
\end{itemize}
\item Griewank
\begin{itemize}
\item Definition: $f_4(\vec{x}) = \sum_{i=1}^D \frac{x_i^2}{4000} - \prod_{i=1}^D \cos(\frac{x_i}{\sqrt{i}}) + 1 $
\item Search range: $[-600, 600]^D$
\item Global optimum: $f_4(\vec{0}) = 0$
\end{itemize}
\item Ackley
\begin{itemize}
\item Definition: $f_5(\vec{x}) = -a\;\exp\left(-b \sqrt{\frac{1}{D} \sum_{i=1}^D x_i^2}\right) - \exp\left(\frac{1}{D} \sum_{i=1}^D \cos(c\;x_i)\right) + a + \exp(1) $
\item Search range: $[-32.768, 32.768]^D$
\item Global optimum: $f_5(\vec{0}) = 0$
\end{itemize}
\item Schwefel
\begin{itemize}
\item Definition: $f_6(\vec{x}) = 418.9829d - \sum_{i=1}^{D} x_i \sin(\sqrt{\lvert x_i \rvert}) $
\item Search range: $[-500, 500]^D$
\item Global optimum: $f_6(\vec{420.9687}) = 0$
\end{itemize}
\item Alpine
\begin{itemize}
\item Definition: $f_7(\vec{x}) = \sum_{i=1}^{D} \lvert x_i \sin(x_i)+0.1x_i \rvert $
\item Search range: $[-10, 10]^D$
\item Global optimum: $f_7(\vec{0}) = 0$
\end{itemize}
\item Whitley
\begin{itemize}
\item Definition: $f_8(\vec{x}) = \sum_{i=1}^D \sum_{j=1}^D \left(\frac{(100(x_i^2-x_j)^2 + (1-x_j)^2)^2}{4000} - \cos(100(x_i^2-x_j)^2 + (1-x_j)^2)+1\right) $
\item Search range: $[-10, 10]^D$
\item Global optimum: $f_8(\vec{1}) = 0$
\end{itemize}
\item Csendes
\begin{itemize}
\item Definition: $f_9(\vec{x}) = \sum_{i=1}^D x_i^6\left( 2 + \sin \frac{1}{x_i}\right) $
\item Search range: $[-1, 1]^D$
\item Global optimum: $f_9(\vec{0}) = 0$
\end{itemize}
\item Dixon Price
\begin{itemize}
\item Definition: $f_{10}(\vec{x}) = (x_1 - 1)^2 + \sum_{i = 2}^D i (2x_i^2 - x_{i - 1})^2 $
\item Search range: $[-10, 10]^D$
\item Global optimum: $f_{10}(x^*) = 0 \; x_i = 2^{-\frac{2^i - 2}{2^i}} $
\end{itemize}
\end{itemize}
\end{document}
答案3
以表格形式呈现(用于练习,不推荐):
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{makecell, tabularx}
\renewcommand\theadfont{\small\bfseries}
\usepackage{geometry}
\geometry{
a4paper,
left=30mm,
right=25mm,
top=30mm,
bottom=30mm,
asymmetric
}
\begin{document}
\begin{table}
\setlength\tabcolsep{4pt}
\setcellgapes{3pt}
\makegapedcells
\begin{tabularx}{\textwidth}{|l|X|c|l|}
\hline
\thead{Name} & \thead{Definition} & \thead{Search\\ range} & \thead{Global\\ optimum}\\
\hline
Sphere & $f_1(\vec{x}) = \sum\limits_{i=1}^{D} x_i^2$ & $[-5.12, 5.12]^D$ & $f_1(\vec{0}) = 0$\\
\hline
Rosenbrock & $f_2(\vec{x}) = \sum\limits_{i=1}^{D-1} (100 (x_{i+1} - x_i^2)^2 + (x_i - 1)^2) $ & $[-2.048, 2.048]^D$ & $f_2(\vec{1}) = 0$\\
\hline
Rastrigin & $f_3(\vec{x}) = 10D + \sum\limits_{i=1}^D \left(x_i^2 -10\cos(2\pi x_i)\right) $ & $[-5.12, 5.12]^D$ & $f_3(\vec{0}) = 0$\\
\hline
Griewank & $f_4(\vec{x}) = \sum\limits_{i=1}^D \frac{x_i^2}{4000} - \prod\limits_{i=1}^D \cos(\frac{x_i}{\sqrt{i}}) + 1 $ & $[-600, 600]^D$ & $f_4(\vec{0}) = 0$\\
\hline
Ackley & $ \begin{multlined}
f_5(\vec{x}) = -a\;\exp\left(-b \sqrt{\frac{1}{D} \sum_{i=1}^D x_i^2}\right)\\
- \exp\left(\frac{1}{D} \sum_{i=1}^D \cos(c\;x_i)\right) + a + \exp(1)
\end{multlined}$
& $[-32.768, 32.768]^D$
& $f_5(\vec{0}) = 0$\\
\hline
Schwefel & $f_6(\vec{x}) = 418.9829d - \sum\limits_{i=1}^{D} x_i \sin(\sqrt{\lvert x_i \rvert}) $ & $[-500, 500]^D$ & $f_6(\vec{420.9687}) = 0$\\
\hline
Alpine & $f_7(\vec{x}) = \sum\limits_{i=1}^{D} \lvert x_i \sin(x_i)+0.1x_i \rvert $ & $[-10, 10]^D$ & $f_7(\vec{0}) = 0$\\
\hline
Whitley & $\begin{multlined}[t]
f_8(\vec{x}) = \\
\sum_{i=1}^D \sum_{j=1}^D \Bigl(\frac{(100(x_i^2-x_j)^2 + (1-x_j)^2)^2}{4000}\\
- \cos(100(x_i^2-x_j)^2 + (1-x_j)^2)+1\Bigr)
\end{multlined}$
& $[-10, 10]^D$
& $f_8(\vec{1}) = 0$\\
\hline
Csendes & $f_9(\vec{x}) = \sum\limits_{i=1}^D x_i^6\left( 2 + \sin \frac{1}{x_i}\right) $ & $[-1, 1]^D$ & $f_9(\vec{0}) = 0$\\
\hline
Dixon Price & $f_{10}(\vec{x}) = (x_1 - 1)^2 + \sum\limits_{i = 2}^D i (2x_i^2 - x_{i - 1})^2 $
& $[-10, 10]^D$
& \makecell{$f_{10}(x^*) = 0$,\\
$x_i = 2^{-\frac{2^i - 2}{2^i}} $}\\
\hline
\end{tabularx}
\end{table}
\end{document}