代码

代码

在这里我附加了代码,\\该代码会提前查看\endin是否\end{tabular}是下一个击球点。此代码隐藏在 中\noalign\\有代码会先查找星号,然后[查找 ,最后再调用\cr。我怀疑问题就在这里。

我不确定这是否适用:

代码

查看日志输出\typeout{\noexpand\reserved@a value: \meaning\reserved@a}

\documentclass{article}
\usepackage{fontspec}
\usepackage{booktabs}

\catcode`@=11 % or \catcode"0040=11 or \makeatletter to change category code of @ to 11 and temporarily to access kernel macro \@tabularcr
\let\clone@tabularcr\@tabularcr%
\def\@tabularcr{\clone@tabularcr \mymidline}%

% Using \hline and \midrule as a model, I made my own hybrid with some extra end of tabular logic
\def\mymidline{%
  \noalign{\ifnum0=`}\fi\@aboverulesep=\aboverulesep\global\@belowrulesep=\belowrulesep \futurelet
    \reserved@a\@mymidline}%
\def\@mymidline{\typeout{\noexpand\reserved@a value: \meaning\reserved@a}\ifx\reserved@a\end\else% <-- Here is the value test. I need \reserved@a to eventually equal \end
               \vskip\@aboverulesep%
               \hrule \@height \lightrulewidth%
               \vskip\@belowrulesep%
             \fi
      \ifnum0=`{\fi}}
\catcode`@=12 % or \catcode"0040=12 or \makeatother to restore category code of @ to 12

\begin{document}
\makeatletter
\begin{tabular}{ccc}
col1 & col2 & col3 \\
\meaning\@tabularcr & col2 & col3 \\
\meaning\\ & col2 & col3 \\
col1 & col2 & col3 \\
\meaning\clone@tabularcr & col2 & col3 \\
\end{tabular}
\makeatother
\end{document}

电流输出

在此处输入图片描述

期望输出

在此处输入图片描述

答案1

无论如何\\跳过寻找空格*你可以让它做工作并询问它是否找到了\end

这仅适用于乳胶内核,尽管也tabular可以对包进行一些名称更改。array

\documentclass{article}

\usepackage{booktabs}

\catcode`@=11 % or \catcode"0040=11 or \makeatletter to change category code of @ to 11 and temporarily to access kernel macro \@tabularcr
\def\addmyrule{\noalign{%
           \vskip\@aboverulesep%
           \hrule \@height \lightrulewidth%
           \vskip\@belowrulesep}}

\let\old@xtabularcr\@xtabularcr

\def\@xtabularcr{%
\ifx\@let@token\end\else
\aftergroup\aftergroup\aftergroup
\aftergroup\aftergroup\aftergroup
\aftergroup
\addmyrule
\fi
\old@xtabularcr}

\catcode`@=12 % or \catcode"0040=12 or \makeatother to restore category code of @ to 12

\begin{document}
\makeatletter
\begin{tabular}{ccc}
col1 & col2 & col3 \\
\meaning\@tabularcr & col2 & col3 \\
\meaning\\ & col2 & col3 \\
col1 & col2 & col3 \\
\meaning\clone@tabularcr & col2 & col3 \\
\end{tabular}
\makeatother
\end{document}

相关内容