I've got a NewEnviron
from the environ
package which I use to enclose a table. An example of this is in the MWE below. The purpose is to handle the table formatting in the preamble and let the user provide only the content. What I need now is some ability to interact with the \BODY
command of the environ so that I can properly specify the headers (via the ltablex
(really the longtable
) package) and have it properly display multi-page tables.
What the table content expands to now:
\caption{#1} \\ % Include the caption at the top of the table
\endfirsthead % Only show the caption for the first page
\hiderowcolors \caption{Continued} \\ % Include a caption on subsequent pages that just says continued
\showrowcolors % row coloring was turned off for the caption, now lets turn it back on
\endhead % End of header for all pages after first
\hline
\rowcolor{greyblue} \setrow{\bfseries} % Make the header row bold and colored grey-blue
Header 1 & Header 2 \\ % This is part of \BODY
Content 1 & Content 2 \\ % This is part of \BODY
Content 3 & Content 4 \\ % This is part of \BODY
\hline
What I would like it to be:
\caption{#1} \\ % Include the caption at the top of the table
\hline
\rowcolor{greyblue} \setrow{\bfseries} % Make the header row bold and colored grey-blue
Header 1 & Header 2 \\ % This is part of \BODY
\endfirsthead % Only show the caption for the first page
\hiderowcolors \caption{Continued} \\ % Include a caption on subsequent pages that just says continued
\showrowcolors % row coloring was turned off for the caption, now lets turn it back on
\hline
\rowcolor{greyblue} \setrow{\bfseries} % Make the header row bold and colored grey-blue
Header 1 & Header 2 \\ % This is part of \BODY
\endhead % End of header for all pages after first
Content 1 & Content 2 \\ % This is part of \BODY
Content 3 & Content 4 \\ % This is part of \BODY
\hline
Is there a way to achieve this?
Minimum Working Example
\documentclass{article}
\usepackage[table,dvipsnames]{xcolor} % Provides coloring for tables and text
\usepackage{ltablex} % Customized table formatting (uses tabularx and longtable)
\usepackage{environ} % Used to define custom table environment
% Fixes conflict between variable names in tabularx and xcolor
\newcounter{tblerows}
\expandafter\let\csname c@tblerows\endcsname\rownum
\definecolor{greyblue}{rgb}{0.6353,0.6863,0.7686} % Define a color used in the tables
\newcommand\setrow[1]{\gdef\rowmac{#1}#1\ignorespaces} % Used for making a row bold
\newcommand\clearrow{\global\let\rowmac\relax} \clearrow % Used for clearing a row formatting
\newcolumntype{L}[1]{>{\hsize=#1\hsize\rowmac\raggedright\arraybackslash}X} % Left-aligned column, input is relative width of page
\keepXColumns
\NewEnviron{doctable}[1]{%
\centering
\rowcolors{3}{black!5}{black!15}
\begin{tabularx}{\textwidth}{L{0.5}|L{0.5}<{\clearrow}}
\caption{#1} \\ % Include the caption at the top of the table
\endfirsthead % Only show the caption for the first page
\hiderowcolors \caption{Continued} \\ % Include a caption on subsequent pages that just says continued
\showrowcolors % row coloring was turned off for the caption, now lets turn it back on
\endhead % End of header for all pages after first
\hline
\rowcolor{greyblue} \setrow{\bfseries} % Make the header row bold and colored grey-blue
\BODY
\hline
\end{tabularx}
\label{tbl:somelabel}
}
\begin{document}
\begin{doctable}{Some Caption}
Header 1 & Header 2 \\
Content 1 & Content 2 \\
Content 3 & Content 4 \\
\end{doctable}
\end{document}
\expandafter\unexpanded
andxparse
.