1

I'm trying to insert an equation into a table, and there are 2 lines to the equation. I got the idea to use parbox from other questions on this site. SO, I tried doing this like so:

\begin{document}
\begin{table}[]
\begin{tabular}{@{}llllll@{}}
\toprule
col & $r$  & $a-b$  & $k-j$ & other & value $f(x)$ \\ \midrule
0 & \{01,0\}   & \parbox{\begin{equation} x=100 \\ y=\max \{500,673\} + 10 + 200 \end{equation}} & $8$ &  No &  N/A \\
\end{tabular}
\end{table}
\end{document}

which gives the following output: table

However, there are 2 problems with this:

  • the newline command "\" in the equation did not work at all
  • I would prefer no number of this equation, since it is inside the table.

Does anyone know of a nice way to display these equations in a table, with the modifications described above?

Thanks.

9
  • 1
    Welcome to TeX.SE!
    – Mensch
    Commented Dec 8, 2023 at 20:47
  • 2
    \parbox has a width argument, \parbox{3cm} or whatever width you want, equation does not allow \\ you could use gather* from amsmath Commented Dec 8, 2023 at 20:51
  • 1
    \begin{table}[] would not allow the table anywhere, it generates a warning and latex ignores the specified option. Commented Dec 8, 2023 at 20:52
  • Instead of equation, try using $x=100$ \\ $y=\max ...$ inside the \parbox. Commented Dec 8, 2023 at 21:14
  • Does equation should be numbered? Without this request solution can be easier to find.
    – Zarko
    Commented Dec 8, 2023 at 22:10

2 Answers 2

2

Something like this?

enter image description here

\documentclass{article}
\usepackage{amsmath,array,booktabs}
\begin{document}

\begin{center}
\begin{tabular}{@{} ll >{$}l<{$} lll @{}}
\toprule
col & $r$  & a-b  & $k-j$ & other & value $f(x)$ \\ \midrule
0 & \{01,0\}   
  & \begin{aligned}[t]
      x&=100 \\
      y&=\max \{500,673\} + 10 + 200
    \end{aligned}
  & $8$ &  No &  N/A \\ 
\bottomrule   
\end{tabular}
\end{center}

\end{document} 
0

See if the following soggestion where equations inserted in table are numbered, are numbered:

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{amsmath, booktabs, counter}

\begin{document}
\begin{equation}
c^2 = a^2 + b^2
\end{equation}
\begin{table}[ht]
\begin{tblr}{colspec = {@{} ll X[l, mode=dmath] 
                            r
                            c c  Q[c, wd=3em] 
                        @{}},
             cell{2-Z}{4} = {cmd=\refstepcounter{equation}(\theequation)},
             row{1}   = {m},
             row{2-Z} = {rowsep=5pt}
             }
    \toprule
col & $r$       & a-b   && $k-j$    & other    & value $f(x)$  \\ 
    \midrule
0   & \{01,0\}  &   \begin{aligned}
                    x & = 100 \\
                    y & =\max \{500,673\} + 10 + 200
                    \end{aligned}
                        && 8        &  No      &  N/A          \\
1   & \{01,1\}  &   a^2 + b^2 = c^2
                        && 8        &  No      &  N/A          \\
    \bottomrule
\end{tblr}
\end{table}
\begin{equation}
c^2 = a^2 + b^2
\end{equation}

\end{document}

enter image description here

Addendum:
In the case that equation in table are not be numbered, above code can be much simpler (without added column for numbering):

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{amsmath, booktabs}

\begin{document}
    \begin{table}[ht]
\begin{tblr}{colspec = {@{} ll X[l, mode=dmath] 
                            c c c 
                        @{}},
             row{2-Z} = {rowsep=5pt}
             }
    \toprule
col & $r$       & a-b   & $k-j$    & other    & value $f(x)$  \\ 
    \midrule
0   & \{01,0\}  &   \begin{aligned}%[t] add in case that you like to have it top aligned
                    x & = 100 \\
                    y & =\max \{500,673\} + 10 + 200
                    \end{aligned}
                        & 8        &  No      &  N/A          \\
    \bottomrule
\end{tblr}
    \end{table}
\end{document}

enter image description here

3
  • Trying to copy your solution (I like it except for the equation numbers), but I'm getting File 'tabularray.sty' not found. How do I get around this?
    – somewhere
    Commented Dec 8, 2023 at 23:28
  • @somewhere - Which TeX distribution do you employ, and when was it last updated? The reason I ask is that the tabularray package is of recent vintage.
    – Mico
    Commented Dec 9, 2023 at 4:57
  • @somewhere, of course is easier. Than can be dropped additional column and simplified table preamble. By this the result become the same as is shown in Mico answer. See addendum to answer. Regarding package tabularray. Apparently you not have installed. Do maybe use Overleaf?
    – Zarko
    Commented Dec 9, 2023 at 5:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .