
Mein Hauptziel ist es, eine Tabelle in einer Savebox zu erstellen, damit ich die Seite problemlos mit mehreren Kopien füllen kann. Jemand hat mir die Verwendung von tabularx empfohlen, was gut funktioniert hat, bis ich auch versucht habe, mit dem Paket colortbl einige Zeilen einzufärben.
Bitte beachten Sie im folgenden MWE, dass ...
- Tabelle 1: tabularx und colortbl funktionieren außerhalb der Savebox gut zusammen.
- Tabelle 2: Tabularx funktioniert einwandfrei, wenn es in einer Savebox gespeichert wird.
- Tabelle 3: Beim Versuch, Tabelle 1 in einer Savebox zu speichern, tritt der Fehler „Steuersequenz nicht definiert“ auf.
Besonders hervorzuheben ist, dass die Auswahl der Option „s“ (überspringen) auf der Konsole zu einem kompilierten Dokument führt, in dem alle drei Tabellen korrekt dargestellt zu sein scheinen. Obwohl ich das Dokument also setzen kann, frage ich mich, ob es eine „Lösung“ für dieses Problem gibt.
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}
Antwort1
Der Satz ist erst vollständig eingerichtet \begin{document}
. Manchmal funktioniert es, einfachen Text in einer Sbox in der Präambel zu speichern, aber hier nicht:
\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}