TransWikia.com

Misplace omit in multicolumn alias definition

TeX - LaTeX Asked on March 18, 2021

I’m attempting to make my syntax cleaner and more readable (to me) by making aliases for some commands. One is the mC command, which produces a multicolumn with removed left and right padding. When invoking the command, I get a misplaced omit error. Any ideas?

PS: is there a non-risky way to redefine tabular to default to @{} at the ends of the tabular column specification (but not in between…)?

MWE:

documentclass{article}

usepackage{xparse}
usepackage{multirow}
usepackage{makecell}
usepackage{booktabs}

NewDocumentCommand{mC}{m O{c} m}{% multicolumn cell
    multicolumn{#1}{@{}#2@{}}{#3}%
}%

NewDocumentCommand{lbC}{O{t} O{l} m}{% line-break cell
    makecell[{#1}{#2}]{#3}%
}%


begin{document}
    begin{tabular}{@{}lll@{}}
        lbC[b][l]{L1L2} & a & b
        mC{2}[l]{Multi col}  & 3  % causes misplaces omit
        multicolumn{2}{@{}l@{}}{Multi col}  & 3   % works fine
    end{tabular}

end{document}

One Answer

It seems the mC command has to expand to multicolumn rather directly, without parsing for optional arguments. A plain newcommand with three mandatory arguments works.

You can define your mytabular such that it always adds @{} at the beginning and at the end, but you will still have to remember it when adding multicolumn commands.

documentclass{article}
newcommandmC[3]{multicolumn{#1}{@{}#2@{}}{#3}}%
newenvironment{mytabular}[1]{%
  begin{tabular}{@{}#1@{}}%
}{%
  end{tabular}%
}
begin{document}
    begin{mytabular}{lll}
      mC{2}{l}{Multirow}  & 3 
      multicolumn{2}{@{}l@{}}{Multirow}  & 3 
    end{mytabular}
end{document}

Correct answer by gernot on March 18, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP