6

I have a table including scientific-notation numbers. When I run the code, I get the error "Missing inserted $".

Is there any way to get rid of the error without adding $...$ to all cells?

    \begin{table}[]
    \centering
    \begin{tabular}{|c|c|c|}  \hline
    x &t &f(x,t)\\ \hline
     0 & 0 & 0.\times 10^0 \\ \hline
 0 & 1 & 2.2371\times 10^{-17} \\ \hline
 0 & 2 & 5.71729\times 10^{-11} \\ \hline
 1 & 0 & 0.\times 10^0 \\ \hline
 1 & 1 & 8.82724\times 10^{-11} \\ \hline
 1 & 2 & 1.12808\times 10^{-14} \\ \hline
 2 & 0 & 0.\times 10^0 \\\hline
 2 & 1 & 2.19297\times 10^{-15} \\\hline
 2 & 2 & 2.63414\times 10^{-17} \\\hline
    \end{tabular}
    \caption{Caption}
    \label{tab:my_label}
\end{table}

2 Answers 2

12

You could use the siunitx package, for example as follows:

enter image description here

\documentclass{article}
\usepackage{siunitx}
\usepackage{makecell}
\setcellgapes{3pt}
\usepackage{booktabs}
\begin{document}

\begin{table}
  \centering
  \makegapedcells
    \begin{tabular}{|c|c|S[table-format=1.5e-2]|}  \hline
     $x$ & $t$ & ${f(x,t)}$\\ \hline
     0   & 0   & 0e0 \\ \hline
     0   & 1   & 2.2371e-17 \\ \hline
     0   & 2   & 5.71729e-11 \\ \hline
     1   & 0   & 0e0 \\ \hline
     1   & 1   & 8.82724e-11 \\ \hline
     1   & 2   & 1.12808e-14 \\ \hline
     2   & 0   & 0e0 \\\hline
     2   & 1   & 2.19297e-15 \\\hline
     2   & 2   & 2.63414e-17 \\\hline
    \end{tabular}
    \caption{Caption}
    \label{tab:my_label}
\end{table}


\begin{table}
  \centering
  \makegapedcells
    \begin{tabular}{ccS[table-format=1.5e-2]}
    \toprule
     $x$ & $t$ & ${f(x,t)}$\\ 
     \midrule
     0   & 0   & 0e0 \\ 
     0   & 1   & 2.2371e-17 \\ 
     0   & 2   & 5.71729e-11 \\
     \addlinespace
     1   & 0   & 0e0 \\ 
     1   & 1   & 8.82724e-11 \\
     1   & 2   & 1.12808e-14 \\
     \addlinespace  
     2   & 0   & 0e0 \\ 
     2   & 1   & 2.19297e-15 \\ 
     2   & 2   & 2.63414e-17 \\
     \bottomrule
    \end{tabular}
    \caption{Caption}
    \label{tab:my_label}
\end{table}

\end{document}
1
  • +1 Your headings should be in math mode. Jul 7, 2021 at 7:56
6

You asked,

Is there any way to get rid of the error without adding $...$ to all cells?

Yes: Switch from a tabular to an array environment, i.e., replace \begin{tabular} with $\begin{array} and \end{tabular} with \end{array}$.

4
  • Thank you. How to force the table into page or column width in array environment? Jul 5, 2021 at 19:10
  • 1
    @rbrt_cpr - Setting an explicit target width (say, \textwidth) for the array environment wasn't something you mentioned in the initial query, right? For the table at hand, I definitely wouldn't recommend setting its width to \textwidth. Can you be a bit more specific about a use case you have in mind?
    – Mico
    Jul 5, 2021 at 19:52
  • \begin{table}[ht!] $\begin{array}{ccccc} \toprule \\ x & t & {f(x,t)}\\ \midrule 0 & 0.1 & - 0.121435678966786234 + 2.2342352523523525235 i & - 0.121435678966786232 + 2.23423525235235252354 i & 0.\times 10^{-13} \\ 0 & 0.2 & - 0.212312412495825729 + 2.4234234257979595793 i & - 0.212312412495825729 + 2.42342342579795957932 i & 0.\times 10^{-15} \\ 0 & 0.3 & - 2.195293952935206234 + 1.23423495634678123249 i & - 2.195293952935206234 + 1.23423495634678123249 i & 0.\times 10^{-14} \\ \bottomrule \end{array}$ \end{table} Jul 6, 2021 at 1:53
  • @rbrt_cpr - You're posing an substantially new query in a comment, especially as making this particular table fit inside the width of the textblock should be the lease of your typographic worries. (BTW, why don't you just write 0 instead of 0.\times 10^{-14}?) If you have a new question, please post a new query.
    – Mico
    Jul 6, 2021 at 2:44

You must log in to answer this question.

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