1

I was trying to create a table, and I'm having these two following errors:

"! Missing { inserted.
<to be read again>
^
l.149 ... $n_J\cdot x_i$ & $v_j=x_j-\overline{x^'}
$ & $v^2_j$ & $n_jv^2_j$ \..."

Here's the corresponding code:

\documentclass{article} %%% use \documentstyle for old LaTeX compilers

\usepackage[english]{babel} %%% 'french', 'german', 'spanish', 'danish', etc.
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{txfonts}
\usepackage{mathdots}
\usepackage[classicReIm]{kpfonts}
\usepackage[dvips]{graphicx} %%% use 'pdftex' instead of 'dvips' for PDF output

% You can include more LaTeX packages here 


\begin{document}

%\selectlanguage{english} %%% remove comment delimiter ('%') and select language if required


\begin{tabular}{|p{0.6in}|p{0.6in}|p{0.6in}|p{0.6in}|p{0.6in}|p{0.6in}|p{0.6in}|} \hline 
\multicolumn{3}{|p{1in}|}{Messungen} & \multicolumn{4}{|p{2.4in}|}{Berechnungen} \\ \hline 
$x_j$ & $h_j\ (mm$)\newline  & $n_j$ & $n_jx_j$ & $v_j=x_j-\overline{x^'}$ & $v^2_j$ & $n_jv^2_j$ \\ \hline 
-6 & 7  & 39 & -234 & -5,9 & 34,81 & 1357,59 \\ \hline 
-5 & 12 & 66 & -330 & -4,9 & 24,01 & 1584,66 \\ \hline 
-4 & 14 & 77 & -308 & -3,9 & 15,21 & 1171,17 \\ \hline 
-3 & 24 & 133 & -399 & -2,9 & 8,41 & 1118,53 \\ \hline 
-2 & 34 & 188 & -376 & -1,9 & 3,61 & 678,68 \\ \hline 
-1 & 43 & 238 & -238 & -0,9 & 0,81 & 192,78 \\ \hline 
0 & 42 & 233 & 0 & 0,1 & 0,01 & 2,33 \\ \hline 
1 & 36 & 200 & 200 & 1,1 & 1,21 & 242 \\ \hline 
2 & 32 & 177 & 354 & 2,1 & 4,41 & 780,57 \\ \hline 
3 & 23 & 127 & 381 & 3,1 & 9,61 & 1120,47 \\ \hline 
4 & 13 & 72 & 288 & 4,1 & 16,81 & 1210,32 \\ \hline 
5 & 8 & 44 & 220 & 5,1 & 26,01 & 1144,44 \\ \hline 
6 & 10 & 35 & 210 & 6,1 & 37,21 & 302,35 \\ \hline 
\end{tabular}

\end{document}
4
  • 1
    Replace \overline{x^'} by \overline{x'}. The prime is automatically a superscript, so if you add another ^ this essentially leads to ^^, which throws an error.
    – user194703
    Oct 27, 2019 at 12:58
  • 1
    Also it looks somewhat better if you replace the row containing ^' by $\vphantom{\dfrac{!}{!}}x_j$ & $h_j$ (mm)\newline & $n_j$ & $n_jx_j$ & $v_j=x_j-\overline{x'}$ & $v^2_j$ & $n_jv^2_j$ \\[-0.6em] \hline .
    – user194703
    Oct 27, 2019 at 13:02
  • 2
    a note on your comments \documentclass{article} %%% use \documentstyle for old LaTeX compilers "old" here means from before 1993, latex209 hasn't been included in standard distributions for decades... none of the \usepackage would work for latex2.09 either. \usepackage[dvips]{graphicx} %%% use 'pdftex' instead of 'dvips' for PDF output it would be much better to not use [dvips] or [pdftex] and let the system pick the correct option automatically. Oct 27, 2019 at 13:09
  • Another general comment: It makes no sense to load both the txfonts and the kpfonts package. Load one or the other, but not both.
    – Mico
    Oct 27, 2019 at 13:48

1 Answer 1

1

In addition to fixing the immediate problem at hand (by omitting the ^ symbol in x^', you may also wish to make your table more interesting and compelling. I suggest you do so by (a) omitting all vertical lines and most horizontal lines, (b) use the line-drawing macros of the booktabs package for the few remaining horizontal lines, and (c) aligning all numbers vertically along their respective decimal markers, using the S column type of the siunitx package.

enter image description here

\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage{amssymb,amsmath}
%\usepackage{txfonts}  % do NOT load both 'txfonts and 'kpfonts' 
\usepackage{mathdots}
\usepackage[classicReIm]{kpfonts}
\usepackage{graphicx} 
\usepackage{booktabs}

\usepackage[locale=DE]{siunitx} % for "S" column type
\newcolumntype{T}[1]{S[table-format=#1]}

\begin{document}

\begin{center}
\begin{tabular}{@{}T{-1.0}T{2.0}T{3.0}T{-3.0}T{-1.1}T{2.2}T{4.2}@{}} \toprule
\multicolumn{3}{c}{Messungen} & 
\multicolumn{4}{c}{Berechnungen} \\
\cmidrule(r){1-3} \cmidrule(l){4-7}
{$x_j$} & {$h_j$ (\si{\milli\meter})} & {$n_j$} & {$n_jx_j$} &
{$v_j=x_j-\bar{x}$} & {$v^2_j$} & {$n_jv^2_j$} \\
\midrule
-6 &  7 &  39 & -234 & -5,9 & 34,81 & 1357,59 \\
-5 & 12 &  66 & -330 & -4,9 & 24,01 & 1584,66 \\
-4 & 14 &  77 & -308 & -3,9 & 15,21 & 1171,17 \\
-3 & 24 & 133 & -399 & -2,9 &  8,41 & 1118,53 \\ \addlinespace
-2 & 34 & 188 & -376 & -1,9 &  3,61 &  678,68 \\
-1 & 43 & 238 & -238 & -0,9 &  0,81 &  192,78 \\
 0 & 42 & 233 &    0 &  0,1 &  0,01 &    2,33 \\
 1 & 36 & 200 &  200 &  1,1 &  1,21 &  242,00 \\
 2 & 32 & 177 &  354 &  2,1 &  4,41 &  780,57 \\ \addlinespace
 3 & 23 & 127 &  381 &  3,1 &  9,61 & 1120,47 \\
 4 & 13 &  72 &  288 &  4,1 & 16,81 & 1210,32 \\
 5 &  8 &  44 &  220 &  5,1 & 26,01 & 1144,44 \\ 
 6 & 10 &  35 &  210 &  6,1 & 37,21 &  302,35 \\ 
\bottomrule
\addlinespace
\multicolumn{7}{@{}l}{$N=\sum_j x_j=1{,}629$. $\bar{x}=(1/N) \sum_j n_jx_j=-0.142\approx-0.1$.}
\end{tabular}
\end{center}

\end{document} 

You must log in to answer this question.

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