Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
TeX言語:表組み(alignment)中でチョット複雑なコードを動かすとアレ
% This code gives an error.
\documentclass[a4paper]{article}
\makeatletter %!!!!!!!!!!!!!!!!!!!!!!!!! TeX code BEGIN
\newcount\xx@k \newcount\xx@n
% \EvenOddTable{<max-number>}
\newcommand*\EvenOddTable[1]{%
\global\xx@k=\z@ \global\xx@n=#1\relax
\begin{tabular}{cc}%
Even&Odd\\\hline
\@whilenum{\xx@k<\xx@n}\do{%
\global\advance\xx@k\@ne
\ifodd\xx@k
---&\the\xx@k\\%
\else
\the\xx@k&---\\%
\fi}%
\end{tabular}}
\def\xx@evenoddtable@a#1#2{%
#1&#2\\}
\makeatother %!!!!!!!!!!!!!!!!!!!!!!!!! TeX code END
\begin{document}
\EvenOddTable{9}
\end{document}
% This code compiles successfully.
\documentclass[a4paper]{article}
\makeatletter %!!!!!!!!!!!!!!!!!!!!!!!!! TeX code BEGIN
\newcount\xx@k \newcount\xx@n
% \EvenOddTable{<max-number>}
\newcommand*\EvenOddTable[1]{%
\global\xx@k=\z@ \global\xx@n=#1\relax
\begin{tabular}{cc}%
Even&Odd\\\hline
\@whilenum{\xx@k<\xx@n}\do{%
\global\advance\xx@k\@ne
\ifodd\xx@k
\xx@evenoddtable@a{---}{\the\xx@k}%
\else
\xx@evenoddtable@a{\the\xx@k}{---}%
\fi}%
\end{tabular}}
\def\xx@evenoddtable@a#1#2{%
#1&#2\\}
\makeatother %!!!!!!!!!!!!!!!!!!!!!!!!! TeX code END
\begin{document}
\EvenOddTable{9}
\end{document}
@zr-tex8r

This comment has been minimized.

Copy link
Owner Author

commented Feb 2, 2019

何がしたいのかについては、goodの方の組版結果を参照。

alignment tab(&)を含む部分を別のマクロに逃がすとエラーを回避できる。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.