
tabu
環境の新しい定義内にを含めようとしていますが、enddef
新しい環境のポストアンブル ( ) にタブーの内容が含まれていると失敗します。つまり、セルです。tabular
またはを使用するとtabular*
機能します。エラーは次のとおりです。
! Missing number, treated as zero. \[email protected]
MWE:
\documentclass{article}
\usepackage{tabu}
\newenvironment{testt}
{\begin{tabu} to \textwidth{cccc}
11 & 12 & 13 & 14 \\
21 & 22 & 23 & 24 \\}
{
41 & 42 & 43 & 44
\end{tabu}
}
\begin{document}
\begin{testt}
31 & 32 & 33 & 34 \\
\end{testt}
\end{document}
これをどうやって解決すればいいでしょうか?
答え1
パッケージを試してくださいenviron
。このパッケージは、\BODY
パラメータの位置をマークアップするために使用し、中括弧の不一致やこの質問で発生した問題などの問題を回避します。
参照書類。
\documentclass{article}
\usepackage{tabu}
\usepackage{environ}
\NewEnviron{testt}
{\begin{tabu} to \textwidth{cccc}
11 & 12 & 13 & 14 \\
21 & 22 & 23 & 24 \\
\BODY
41 & 42 & 43 & 44
\end{tabu}
}
\begin{document}
\begin{testt}
31 & 32 & 33 & 34 \\
\end{testt}
\end{document}
答え2
パッケージtabu
内部では
\tabu@collectbody#1#2\end
\end{tabu}
組版前に表の内容を全て収集します。表の一部を「非表示」にすると正しく動作しません。例えば、表の一部だけを非表示にすると正常に動作します。
\documentclass{article}
\usepackage{tabu}
\newenvironment{testt}
{\begin{tabu} to \textwidth{cccc}
11 & 12 & 13 & 14 \\
21 & 22 & 23 & 24 \\}
{
\end{tabu}
}
\begin{document}
\begin{testt}
31 & 32 & 33 & 34 \\
41 & 42 & 43 & 44
\end{testt}
\end{document}
それでもテーブル全体を正しく取得します。
\showthe\currentgrouplevel
セル内を使用すると、何かが間違っていることがわかります。すべての「機能する」ケースのグループ レベルは 14 ですが、「間違った」ケースのグループ レベルは 8 です。
egreg が言うように、これはおそらく のバグtabu
、または少なくとも文書化されるべき「機能」です。回避策をアドバイスするには、どのような効果を求めているかを知る必要があり、それによって代替アプローチを提案できると思います。新しい質問として投稿するのが最善だと思います。
答え3
パッケージで試すことができますcollect
。注意: どちらも使用したことがないのでcollect
、tabu
これが実行可能で堅牢な方法であるかどうかを専門的に評価することはできません。
\documentclass{article}
\usepackage{tabu}
\usepackage{collect}
\definecollection{rescuetabu}
\makeatletter
\newenvironment{testt}
{\@nameuse{collect*}{rescuetabu}
{\begin{tabu} to \textwidth{cccc}
11 & 12 & 13 & 14 \\
21 & 22 & 23 & 24 \\ }
{41 & 42 & 43 & 44 \\ \end{tabu}}{}{}}
{\@nameuse{endcollect*}}
\makeatother
\begin{document}
\texttt{normal tabu}
\begin{tabu} to \textwidth{cccc}
11 & 12 & 13 & 14 \\
21 & 22 & 23 & 24 \\
31 & 32 & 33 & 34 \\
\end{tabu}
\hrule\medskip
\texttt{rescued tabus}
\begin{testt}
31 & 32 & 33 & 34 \\
\end{testt}
\bigskip
\begin{testt}
51 & 52 & 53 & 54 \\
61 & 62 & 63 & 64 \\
\end{testt}
\hrule
\end{document}