0

In the MWE below, the output gets displayed correctly when I omit the following code from the tabular environment:

\multicolumn{6}{|c|}{The sentence below is an example of the polite past tense}\\\hline

Furthermore, the 'bottom' \multicolumn command also displays correctly.

What's strange (for me at least) is that when I do include the above code, the table output goes haywire. Please compare the 2 figures below to better understand what I mean.

so far so good

Misplaced \omit Error.

How can I adjust the code so that both \multicolumn statements get displayed correctly, without jumbling up the other contents in the table?

Here is a MWE. Note that I have commented the part out that causes the problem:

\documentclass[10pt, a4paper]{ltjbook}
\usepackage{luatexja}
\usepackage{amsmath}
\usepackage{environ}
\usepackage{tabularx}
\usepackage{hhline}
\usepackage[table]{xcolor}

\newcolumntype{A}{>{\centering\let\newline\\\arraybackslash}X}

\NewEnviron{decomp}[1]
{%
\begin{tabularx}{\columnwidth}{|*{#1}{@{}A}@{}|}%
\hhline{|*{#1}{-}|}\multicolumn{#1}{|c|}{\cellcolor{lightgray}\textbf{$\lbrace\cdot\cdot\cdot\rbrace$ Sample Sentence}}\\%
\hhline{|*{#1}{-}|}\rule{0pt}{\baselineskip}%
\BODY%
\end{tabularx}%
}

\begin{document}

\begin{decomp}{6}
%\multicolumn{6}{|c|}{The sentence below is an example of the polite past tense.}\\\hline
先生&は&一週間&前&に&来ました。\\\hline
センセイ&は&イッシュウカン&まえ&に&きました。\\\hline
teacher&は&1 week&before&に&came\\\hline
\multicolumn{6}{|r|}{\textit{The teacher came a week ago.}}\\\hline
\end{decomp}
\end{document}

2 Answers 2

1

This is unrelated to tabularx or environ

You have

\hhline{|*{#1}{-}|}\rule{0pt}{\baselineskip}%

so you have already started the cell with a rule, you get the same same error in

\documentclass{article}

\begin{document}

\begin{tabular}{cc}
  a&b\\\hline\rule{1pt}{1pt}%
  \multicolumn{2}{c}{bang}
\end{tabular}
\end{document}
2
  • Thank you for the quick response. Replacing with hhline with \\\hline seems to do the trick. Commented May 29, 2021 at 15:28
  • @HenriBranken no I just used hline to sabe loading the hhline package, the line is not relevant to the issue. The error is because you have a \rule after the \\ Commented May 29, 2021 at 15:30
0

Based on David Carlisle's answer above:

\documentclass[10pt, a4paper]{ltjbook}
\usepackage{luatexja}
\usepackage{amsmath}
\usepackage{environ}
\usepackage{tabularx}
\usepackage{hhline}
\usepackage[table]{xcolor}

\newcolumntype{A}{>{\centering\let\newline\\\arraybackslash}X}

\NewEnviron{decomp}[1]
{%
\begin{tabularx}{\columnwidth}{|*{#1}{@{}A}@{}|}%
\hhline{|*{#1}{-}|}\multicolumn{#1}{|c|}{\cellcolor{lightgray}\textbf{$\lbrace\cdot\cdot\cdot\rbrace$ Sample Sentence}}\\\hline
\BODY%
\end{tabularx}%
}

\begin{document}

\begin{decomp}{6}
\multicolumn{6}{|l|}{The sentence below is an example of the polite past tense.}\\\hline
先生&は&一週間&前&に&来ました。\\\hline
センセイ&は&イッシュウカン&まえ&に&きました。\\\hline
teacher&は&1 week&before&に&came\\\hline
\multicolumn{6}{|r|}{\textit{The teacher came a week ago.}}\\\hline
\end{decomp}
\end{document}

You must log in to answer this question.

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