渲染多聯骨牌的程式碼對於一行不正確

渲染多聯骨牌的程式碼對於一行不正確

我正在使用改編自的代碼(非常輕微)這個答案渲染多聯骨牌。除了兩個問題之外,它工作得很好。

  1. 僅一排的多骨牌的長度似乎沒有被考慮在內。

  2. 第二個問題是我總是需要用墊片填充第一行以使間距正常工作。 (這只是一個不便,所以不像第一個問題那麼重要)。

有誰知道我該如何解決這個問題?

這是一個最小的例子:

\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}

在此輸入影像描述

相關內容