3

In the table below, if I move the units in the square brackets to the next line in the header (e.g. [mg/g] on a new line), I get an error. However, if I use curved () brackets instead, there is no error. How can I use square [] brackets without an error? Thanks

enter image description here

\documentclass{article}
\usepackage[abbreviations=true,per-mode=symbol]{siunitx}
\usepackage{booktabs}
\usepackage{makecell}
\usepackage{caption}
\begin{document}

\begin{table}
\caption{Specific Acid Added to Samples}
\label{Acid_Added}
\centering
\begin{tabular}{c  S[table-format=2.2]  S[table-format=2.2]  S[table-format=1.2] }
\toprule
\thead{ID} & {\thead{Specific Acid\\ Weight [\si{\mg}]}} & {\thead{Spread\\ Weight [\si{\g}]}} & {\thead{Specific Acid\\Conc [\si{\mg\per\g}]}} \\
\midrule
1   &0.20   &19.96  &0.01\\
2   &0.40   &20.00  &0.02\\
3   &1.00   &19.98  &0.05\\
4   &2.00   &20.00  &0.10\\
5   &4.00   &20.00  &0.20\\
6   &10.00  &20.00  &0.50\\
\bottomrule
\end{tabular}
\end{table}
\end{document}
leandriis
  • 62,593
Vuro H
  • 79
  • 3
    The error occurs with Specific Acid Weight \\ [\si{\mg}] because \\ can take an optional argument in square brackets. So LaTeX reads the [\si{\mg}] as optional argument of \\ and not as text for the next line. Unfortunately, \si{\mg} is not something that would make sense as this optional argument. You can add \relax after the \\. See also https://tex.stackexchange.com/q/34466/35864 – moewe Oct 21 '19 at 05:35

2 Answers2

4

To move the units into the new line, you can use \\{} instead of the usual \\:

enter image description here

\documentclass{article}
\usepackage[abbreviations=true,per-mode=symbol]{siunitx}
\usepackage{booktabs}
\usepackage{makecell}
\usepackage{caption}
\begin{document}

\begin{table}
\caption{Specific Acid Added to Samples}
\label{Acid_Added}
\centering
\begin{tabular}{c  S[table-format=2.2]  S[table-format=2.2]  S[table-format=1.2] }
\toprule
\thead{ID} & {\thead{Specific Acid\\ Weight\\{} [\si{\mg}]}} & {\thead{Spread\\ Weight\\{} [\si{\g}]}} & {\thead{Specific Acid\\Conc\\{} [\si{\mg\per\g}]}} \\
\midrule
1   &0.20   &19.96  &0.01\\
2   &0.40   &20.00  &0.02\\
3   &1.00   &19.98  &0.05\\
4   &2.00   &20.00  &0.10\\
5   &4.00   &20.00  &0.20\\
6   &10.00  &20.00  &0.50\\
\bottomrule
\end{tabular}
\end{table}
\end{document}
leandriis
  • 62,593
0

I had an simple array

\begin{equation*} \begin{array}{cccccccc} [,\mathbf{i},] & 001 & 001 & 001 & 010 & 010 & 011 & 011 \{} [,\mathbf{j},] & 010 & 100 & 110 & 100 & 101 & 100 & 101 \{} [,\mathbf{k},] & 011 & 101 & 111 & 110 & 111 & 111 & 110 \{} [,\mathbf{i},] & 1 & 1 & 1 & 2 & 2 & 3 & 3 \{} [,\mathbf{j},] & 2 & 4 & 6 & 4 & 5 & 4 & 5 \{} [,\mathbf{k},] & 3 & 5 & 7 & 6 & 7 & 7 & 6 \{} \end{array} \end{equation*}

Adding the square brackets at the beginning of each line would generate errors(?) I followed your recommendation and added braces at the end of each line \{} , and there was no more error. Hmmm, Looks like stackexchange pruned down the double backslashes to one from my example.

  • This seems to be a long way to say "I followed the answer and it worked." Why not just upvote the answer? – Teepeemm Oct 03 '22 at 00:55