I'd like to define a macro that expands to \hline
and \cline
inside the tabular environment depending on the next character:
\documentclass{standalone}
\makeatletter
\def\mycline[#1]{\cline{#1}}
\def\myline{\@ifnextchar[{\mycline}{\hline}} % Does not work. Either misplaced \noalign or \omit
\makeatother
\begin{document}
\begin{tabular}{cc}
a1 & a2 \\
\myline
b1 & b2 \\
\myline[1-2]
\end{tabular}
\end{document}
Unfortunately, this results in a misplaced \noalign
or \omit
(or both). It seems that \@ifnextchar
doesn't get fully expanded in time. Any idea?
\noalign
works, an unexpandable command (here\futurelet
used by\@ifnextchar
) starts a new alignment cell and it's too late for a line to be inserted.