0

How can I display this table with an equation? I tried many times but i can't find any solution to display the table

    \documentclass{article}
    \usepackage[margin=25mm]{geometry}
    \usepackage{mathtools}
\usepackage[table]{xcolor}
\usepackage{booktabs, collcell, makecell, tabularx, threeparttable, multirow}
    \newcommand{\tclr}[1]{\textcolor{blue!70!black}{#1}}
    \newcolumntype{L}{>{\collectcell\tclr\raggedright}X<{\endcollectcell}}
   %{\textwidth}{@{} >{\raggedright\arraybackslash}X >{$\displaystyle}l<{$} @{}}

\usepackage{xparse}
\NewExpandableDocumentCommand\mcc{O{1}m}
    {\multicolumn{#1}{c}{#2}}

\DeclarePairedDelimiter{\abs}{\mid}{\mid}

\begin{document}


\begin{table}
\centering
\begin{tabularx}{\textwidth}{@{}
                            L l
                       *{3}{>{$\displaystyle}l<{$}S}
                            @{}}
\toprule
MOP & Definition & Constraints\\
\midrule
\multirow{3}{*}{Schaffer Problem}
& $F=(f_1(x),f_2(x))$ & $-10^5\leq x\leq 10^5$ \\
& $f_1(x)=x^2,$       & \\
& $f_2(x)=(x-2)^2$    & \\
\midrule
\multirow{4}{*}{Viennet (3)}
& $ F=(f_1(x,y),f_2(x,y),f_3(x,y))$                          & $-4\leq x,y\leq4 $ \\
& $ f_1(x,y)=0.5(x^2+y^2)+sin(x^2+y^2),$                     & \\
& $ f_2(x,y)=\frac{(3x-2y+4)^2}{8}+\frac{(x-y+1)^2}{27}+15,$ & \\
& $ f_3(x,y)=\frac{1}{x^2+y^2+1}-1.1 e^{-x^2-y^2}$           & \\
\midrule
\multirow{3}{*}{Kursawe problem}
& $ F=(f_1(\mathbf{x}),f_2(\mathbf{x}))$                                                           & $-5\leq x_i\leq5$ \\
& $ f_1(\mathbf{x})=\sum_{i=1}^{n-1}\left(-10 \exp\left(-0.2\sqrt{x_i^2+y_{i+1}^2}\right)\right),$ & $i=1,2,3$ \\
& $ f_2(\mathbf{x})=\sum_{i=1}^n\left(\abs{x_i}^{0.8}+5 sin(x_i^3)\right)$                         & \\
\midrule
\multirow{4}{*}{Dep problem}
& $ F=(f_1(x,y),f_2(x,y))$                                   & $0\leq x,y\leq1$ \\
& $ f_1(x,y)=x$,                                             & \\
& $ f_2(x,y)=(1+10y)\Bigl(1-\Bigl(\frac{x}{1+10y}\Bigr)^2- $ & \\
& $ \qquad \qquad \frac{x}{1+10y}sin(2p\pi x)\Bigr)$         & \\
\bottomrule
\end{tabularx}
\caption{Unconstrained Functions}
\label{unconstrained}
\end{table}


\end{document}

Chamanga
  • 166

3 Answers3

2

With tabularray with columns in display math and in-line math mode the table code is simple:

\documentclass{article}
\usepackage[margin=25mm]{geometry}
\usepackage{tabularray}
\UseTblrLibrary{amsmath, booktabs}

\begin{document} \begin{table} \begin{tblr}{colspec ={@{} l X[l, mode=dmath] Q[c,mode=math] @{}}, row{1} = {mode=text}, rowsep = 3pt } \toprule MOP & Definition & Constraints \ \midrule \SetCell[r=3]{l} Schaffer Problem & F=(f_1(x),f_2(x)) & -10^5\leq x\leq 10^5 \ & f_1(x)=x^2 & \ & f_2(x)=(x-2)^2 & \ \midrule \SetCell[r=4]{l} Viennet (3) & F=(f_1(x,y),f_2(x,y),f_3(x,y))
& -4\leq x,y\leq4 \ & f_1(x,y)=0.5(x^2+y^2)+\sin(x^2+y^2)
& \ & f_2(x,y)=\frac{(3x-2y+4)^2}{8}+\frac{(x-y+1)^2}{27}+15
& \ & f_3(x,y)=\frac{1}{x^2+y^2+1}-1.1 e^{-x^2-y^2}
& \ \midrule \SetCell[r=3]{l} Kursawe problem & F=(f_1(\mathbf{x}),f_2(\mathbf{x})) & -5\leq x_i\leq5 \ & f_1(\mathbf{x})=\sum_{i=1}^{n-1}\left(-10 \exp\left(-0.2\sqrt{x_i^2+y_{i+1}^2}\right)\right) & i=1,2,3 \ & f_2(\mathbf{x})=\sum_{i=1}^n\left(|{x_i}|^{0.8}+5 \sin(x_i^3)\right) & \ \midrule \SetCell[r=3]{c} Dep problem & F=(f_1(x,y),f_2(x,y)) & 0\leq x,y\leq1 \ & f_1(x,y)=x & \ & f_2(x,y)=(1+10y)\Bigl(1-\Bigl(\frac{x}{1+10y}\Bigr)^2- \frac{x}{1+10y}\sin(2p\pi x)\Bigr) & \ \bottomrule \end{tblr} \end{table} \end{document}

enter image description here

Zarko
  • 296,517
2

You might use \multirow for this, but I prefer not to.

I solve the problem by stating the equations and the constraints in a single top aligned array; the rows are separated by \addlinespace to add some air (changing \arraystretch would not work as well).

\documentclass{article}
\usepackage[margin=25mm]{geometry}
\usepackage{mathtools}

\usepackage[table]{xcolor} \usepackage{booktabs,array}

\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}

\ExplSyntaxOn \NewDocumentCommand{\addvertspaces}{m} { \seq_set_split:Nnn \l_tmpa_seq { \ } { #1 } \seq_use:Nn \l_tmpa_seq { \ \addlinespace } } \ExplSyntaxOff

\begin{document}

\begin{table}[htp] \centering

% a local command to ease input \newcommand{\prob}[1]{$\begin{array}[t]{@{}>{\displaystyle}l@{}}\addvertspaces{#1}\end{array}$} \newcommand{\constr}[1]{$\begin{array}[t]{@{}c@{}}\addvertspaces{#1}\end{array}$}

\begin{tabular}{\textwidth}{ @{} >{\color{blue!70!black}}l @{\extracolsep{\fill}} l c @{} } \toprule MOP & Definition & Constraints\ \midrule Schaffer Problem & \prob{ F=(f_1(x),f_2(x)) \ f_1(x)=x^2, \ f_2(x)=(x-2)^2 } & \constr{-10^5\leq x\leq 10^5} \ \midrule Viennet (3) & \prob{ F=(f_1(x,y),f_2(x,y),f_3(x,y)) \ f_1(x,y)=0.5(x^2+y^2)+\sin(x^2+y^2), \ f_2(x,y)=\frac{(3x-2y+4)^2}{8}+\frac{(x-y+1)^2}{27}+15, \ f_3(x,y)=\frac{1}{x^2+y^2+1}-1.1 e^{-x^2-y^2} } & \constr{-4\leq x,y\leq4} \ \midrule Kursawe problem & \prob{ F=(f_1(\mathbf{x}),f_2(\mathbf{x})) \ f_1(\mathbf{x})=\sum_{i=1}^{n-1}\bigl(-10 \exp(-0.2\sqrt{\smash[b]{x_i^2+y_{i+1}^2}},)\bigr), \ f_2(\mathbf{x})=\sum_{i=1}^n \bigl(\abs{x_i}^{0.8}+5 \sin(x_i^3)\bigr) } & \constr{i=1,2,3 \ -5\leq x_i\leq5} \ \midrule Dep problem & \prob{ F=(f_1(x,y),f_2(x,y)) \ f_1(x,y)=x, \ f_2(x,y)=(1+10y)\Bigl(1-\Bigl(\frac{x}{1+10y}\Bigr)^2 -\frac{x}{1+10y}\sin(2p\pi x)\Bigr) } & \constr{0\leq x,y\leq1} \ \bottomrule \end{tabular}

\caption{Unconstrained Functions} \label{unconstrained} \end{table}

\end{document}

enter image description here

Note that \mid is not a delimiter. Also the sine function should always be \sin. I used a trick in order to reduce the size of the square root.

egreg
  • 1,121,712
1

Important things first. When dealing with new things, acquiring new skills, etc. keep things simple, do examples only with strictly necessary information. Everything else is a disturb and makes things susceptible to errors. This is the philosophy behind MWEs. You gonna read along the answer all methodology I used to find the issue, identify your objetive with this table and only then applying a solution.

That said, the first problem I found was: Package array Error: Illegal pream-token (S): 'c' used. \end{tabularx}. You used a column type named S which was not defined. You also defined (or let definitions someone else gave you) which were not used. Therefore, next step, change usage of S to anything basic, like l or c. Next, remove also non necessary packages and commands.

At this point we have the first working table with: \begin{tabularx}{\textwidth}{@{} l l c @{}}. Now the rain's gone.

It became clear you use sin instead of \sin. Checked and corrected. You created a special \abs delimiter, as it could be prone to errors, I removed it and let |x_i| where it was being used. Reinsert it, if it is necessary on anything else.

Finally I understood your real intention with your \newcolumntype. You wanted a column with \displaystyle. Following this answer

I created: \newcolumntype{L}{>{$\displaystyle} l <{$}}. Applying L in the tabularx we got an error: Missing $ inserted. \end{tabularx}. Basically, we are using $ twice, so let's remove it (a job for: Search and Replace). I chose to create a new table in order to be clear and didactic.

I used at this second table \textrm{Definition} and \text{Constraints} because they are text, not math. you may choose between both command options. To finish, let's use \renewcommand{\arraystretch}{1.8} from:

to make the table a lit bit more readable.


The MWE follows:

\documentclass{article}
\usepackage[margin=25mm]{geometry}
\usepackage{mathtools}
\usepackage{booktabs, tabularx, multirow}
\newcolumntype{L}{>{$\displaystyle} l <{$}}

\begin{document} \begin{table} \centering \begin{tabularx}{\textwidth}{@{} l l c @{}} \toprule MOP & Definition & Constraints \ \midrule \multirow{3}{}{Schaffer Problem} & $F=(f_1(x),f_2(x))$ & $-10^5\leq x\leq 10^5$ \ & $f_1(x)=x^2$ & \ & $f_2(x)=(x-2)^2$ & \ \midrule \multirow{4}{}{Viennet (3)} & $F=(f_1(x,y),f_2(x,y),f_3(x,y))$ & $-4\leq x,y\leq4 $ \ & $f_1(x,y)=0.5(x^2+y^2)+\sin(x^2+y^2)$ & \ & $f_2(x,y)=\frac{(3x-2y+4)^2}{8}+\frac{(x-y+1)^2}{27}+15$ & \ & $f_3(x,y)=\frac{1}{x^2+y^2+1}-1.1 e^{-x^2-y^2}$ & \ \midrule \multirow{3}{}{Kursawe problem} & $F=(f_1(\mathbf{x}),f_2(\mathbf{x}))$ & $-5\leq x_i\leq5$ \ & $f_1(\mathbf{x})=\sum_{i=1}^{n-1}\left(-10 \exp\left(-0.2\sqrt{x_i^2+y_{i+1}^2}\right)\right)$ & $i=1,2,3$ \ & $f_2(\mathbf{x})=\sum_{i=1}^n\left(|{x_i}|^{0.8}+5 \sin(x_i^3)\right)$ & \ \midrule \multirow{3}{}{Dep problem} & $F=(f_1(x,y),f_2(x,y))$ & $0\leq x,y\leq1$ \ & $f_1(x,y)=x$ & \ & $f_2(x,y)=(1+10y)\Bigl(1-\Bigl(\frac{x}{1+10y}\Bigr)^2- \frac{x}{1+10y}\sin(2p\pi x)\Bigr)$ & \ \bottomrule \end{tabularx} \end{table}

\begin{table} \renewcommand{\arraystretch}{1.8} \centering \begin{tabularx}{\textwidth}{@{} l L L @{}} \toprule MOP & \textrm{Definition} & \text{Constraints} \ \midrule \multirow{3}{}{Schaffer Problem} & F=(f_1(x),f_2(x)) & -10^5\leq x\leq 10^5 \ & f_1(x)=x^2 & \ & f_2(x)=(x-2)^2 & \ \midrule \multirow{4}{}{Viennet (3)} & F=(f_1(x,y),f_2(x,y),f_3(x,y)) & -4\leq x,y\leq4 \ & f_1(x,y)=0.5(x^2+y^2)+\sin(x^2+y^2) & \ & f_2(x,y)=\dfrac{(3x-2y+4)^2}{8}+\frac{(x-y+1)^2}{27}+15 & \ & f_3(x,y)=\dfrac{1}{x^2+y^2+1}-1.1 e^{-x^2-y^2} & \ \midrule \multirow{3}{}{Kursawe problem} & F=(f_1(\mathbf{x}),f_2(\mathbf{x})) & -5\leq x_i\leq5 \ & f_1(\mathbf{x})=\sum_{i=1}^{n-1}\left(-10 \exp\left(-0.2\sqrt{x_i^2+y_{i+1}^2}\right)\right) & i=1,2,3 \ & f_2(\mathbf{x})=\sum_{i=1}^n\left(|{x_i}|^{0.8}+5 \sin(x_i^3)\right) & \ \midrule \multirow{3}{}{Dep problem} & F=(f_1(x,y),f_2(x,y)) & 0\leq x,y\leq1 \ & f_1(x,y)=x & \ & f_2(x,y)=(1+10y)\Bigl(1-\Bigl(\frac{x}{1+10y}\Bigr)^2- \frac{x}{1+10y}\sin(2p\pi x)\Bigr) & \ \bottomrule \end{tabularx} \end{table} \end{document}

First table with $ and default \arraystretch.

enter image description here

Second table using \newcolumntype with displaystyle and \renewcommand{\arraystretch}{1.8}.

enter image description here

FHZ
  • 3,939