我使用的代码(非常轻微)改编自这个答案渲染多格骨牌。除了两个问题外,它运行良好。
仅有一行的多格骨牌的长度似乎未被考虑。
第二个问题是我总是需要用垫片填充第一行以使间距正常工作。(这只是一个不便之处,因此并不像第一个问题那么严重)。
有人知道我该如何解决这个问题吗?
这是一个简单的例子:
\documentclass{article}
\makeatletter
\def\omino#1{{%
\unitlength6\p@
\@tempcnta\z@
\@tempcntb\@ne
\count@\z@
\xomino#1\relax
\begin{picture}(\@tempcnta,\@tempcntb)(0,-\@tempcntb)%
\@tempcnta\z@
\@tempcntb\@ne
\count@\z@
\xxomino#1\relax
\end{picture}%
}%
}
\def\xomino#1{%
\ifx\relax#1%
\else
\ifx\\#1%
\ifnum\count@>\@tempcnta \@tempcnta\count@\fi
\advance\@tempcntb\@ne
\count@\z@
\else
\advance\count@\@ne
\fi
\expandafter\xomino
\fi}
\def\xxomino#1{%
\ifx\relax#1%
\else
\ifx\\#1%
\advance\@tempcntb\@ne
\count@\z@
\else
\advance\count@\@ne
\ifx*#1%
\put(\count@,-\@tempcntb){\kern-6pt\framebox(0.93,0.93)}
\fi
\fi
\expandafter\xxomino
\fi}
\makeatother
\begin{document}
Polyominoes with two or more rows like this \omino{*****\\*\\*}
work great, but polyominoes that have only one row like this
\omino{******} don't align properly.
Also, the first row needs to be complete, like this \omino{*...\\****}
to work. Without the empty characters, the polyomino is not spaced
correctly, like \omino{*\\****}this.
\end{document}
答案1
问题在于,最大水平步长的计算没有考虑最后一行。可以通过将案例中的最大计算添加到案例\\
中来解决这个\relax
问题。更改以 标记%<-
。
\documentclass{article}
\makeatletter
\def\omino#1{{%
\unitlength6\p@
\@tempcnta\z@
\@tempcntb\@ne
\count@\z@
\xomino#1\relax
\begin{picture}(\@tempcnta,\@tempcntb)(0,-\@tempcntb)%
\@tempcnta\z@
\@tempcntb\@ne
\count@\z@
\xxomino#1\relax
\end{picture}%
}%
}
\def\xomino#1{%
\ifx\relax#1%
\ifnum\count@>\@tempcnta \@tempcnta\count@\fi%<-
\else
\ifx\\#1%
\ifnum\count@>\@tempcnta \@tempcnta\count@
\fi
\advance\@tempcntb\@ne
\count@\z@
\else
\advance\count@\@ne%
\fi
\expandafter\xomino
\fi}
\def\xxomino#1{%
\ifx\relax#1%
\else
\ifx\\#1%
\advance\@tempcntb\@ne
\count@\z@
\else
\advance\count@\@ne
\ifx*#1%
\put(\count@,-\@tempcntb){\kern-6pt\framebox(0.93,0.93)}
\fi
\fi
\expandafter\xxomino%
\fi}
\makeatother
\begin{document}
Polyominoes with two or more rows like this \omino{*****\\*\\*}
work great, but polyominoes that have only one row like this
\omino{******} don't align properly.
Also, the first row needs to be complete, like this \omino{*...\\****}
to work. Without the empty characters, the polyomino is not spaced
correctly, like \omino{*\\****} this.
\end{document}