
私の全体的な目標は、セーブボックス内にテーブルを構築して、複数のコピーでページを簡単に埋められるようにすることです。誰かが tabularx の使用を勧めてくれましたが、colortbl パッケージを使用して行の一部に色を付けるまではうまく機能していました。
以下の MWE では、次の点に注意してください...
- 表 1: tabularx と colortbl は、保存ボックスの外部でうまく連携します。
- 表 2: tabularx は savebox に保存すると正常に動作します。
- 表 3: 表 1 を保存ボックスに保存しようとすると、「未定義の制御シーケンス」エラーが発生します。
特に注目すべきは、コンソールで「s」(スキップ) オプションを選択すると、コンパイルされたドキュメントが生成され、3 つのテーブルがすべて正しくレンダリングされるように見えることです。したがって、ドキュメントをタイプセットすることはできますが、この問題を「修正」する方法があるかどうか疑問に思います。
MWE:
\documentclass{article}
\usepackage{colortbl}
\usepackage{tabularx}
\usepackage{xcolor}
\newsavebox{\tabularxInBox}
\sbox{\tabularxInBox}{
\begin{tabularx}{\textwidth}{cX}
Col 1 & Col 2\\
\hline
Row 1& No Colored Background\\
Row 2& No Colored Background\\
\end{tabularx}
}
\newsavebox{\tabularxAndColortblInBox}
\sbox{\tabularxAndColortblInBox}{
\begin{tabularx}{\textwidth}{cX}
Col 1 & Col 2\\
\hline
Row 1& No Colored Background\\
\rowcolor{lightgray}
Row 2& Colored Background\\
\end{tabularx}
}
\begin{document}
No conflict with tabularx and colortbl normally:\\
\begin{tabularx}{\textwidth}{cX}
Col 1 & Col 2\\
\hline
Row 1& No Colored Background\\
\rowcolor{lightgray}
Row 2& Colored Background\\
\end{tabularx}
\vskip 1cm
No conflict with tabularx and sbox:\\
\usebox{\tabularxInBox}
\vskip 1cm
However, using both tabularx and colortble inside an \sbox throws an error:\\
\usebox{\tabularxAndColortblInBox}
\end{document}
答え1
タイプセッティングは まで完全には設定されません\begin{document}
。プリアンブルの sbox に単純なテキストを保存すると機能する場合がありますが、ここでは機能しません。
\documentclass{article}
\usepackage{colortbl}
\usepackage{tabularx}
\usepackage{xcolor}
\newsavebox{\tabularxInBox}
\newsavebox{\tabularxAndColortblInBox}
\begin{document}
\sbox{\tabularxInBox}{%%%dont forget eol
\begin{tabularx}{\textwidth}{cX}
Col 1 & Col 2\\
\hline
Row 1& No Colored Background\\
Row 2& No Colored Background\\
\end{tabularx}%%%dont forget eol
}
\sbox{\tabularxAndColortblInBox}{%%%dont forget eol
\begin{tabularx}{\textwidth}{cX}
Col 1 & Col 2\\
\hline
Row 1& No Colored Background\\
\rowcolor{lightgray}
Row 2& Colored Background\\
\end{tabularx}%%%dont forget eol
}
No conflict with tabularx and colortbl normally:\\
\begin{tabularx}{\textwidth}{cX}
Col 1 & Col 2\\
\hline
Row 1& No Colored Background\\
\rowcolor{lightgray}
Row 2& Colored Background\\
\end{tabularx}
\vskip 1cm
No conflict with tabularx and sbox:\\
\usebox{\tabularxInBox}
\vskip 1cm
However, using both tabularx and colortble inside an \verb|\sbox| throws an error:\\
\usebox{\tabularxAndColortblInBox}
\end{document}