Tables are the final frontier of my documents. So far I have managed to standardized over 20 documents (hundreds of pages) using a single, shared preamble.
Issue
Abstracting format from content in tables still eludes me.
I have limited my tables to two major types and one minor type.
Table List
- tabular
- longtable
- tabularx (being weeded out for consistency. It is still a nice option)
I use LaTeX for its ability to separate formatting from content. Tables seems to have two much non-content code integrated inside of them
- \hline
- \toprule, \midrule, \bottomrule from
booktabs - manually setting alignment of cells, rows, and columns per table (annoying, should be global with option to override locally)
- having to set colors and other formatting of header cells, rows, and columns per table (should be global with option to override locally)
- having to set colors and other formatting of data cells locally, rows, and columns per table (should be global with option to override locally)
- although probably not avoidable,
multirowandmulticolumnmust be inside the data.
Complete This List
Things that offer global conditions for all of the tables in Table List:
- pgfplotstable
- ?
In an ideal world, I could do something like the following and they would function as specified in the preamble (without any local adjustments):
\begin{mycustomtabular}
col1 & col2 & col3 \\
dat1 & dat2 & dat3 \\
dat4 & dat5 & dat6 \\
\end{mycustomtabular}
\begin{mycustomtabular}
col1 & col2 & col3 & col4 \
dat1 & dat2 & dat3 & dat4 \
dat5 & dat6 & dat7 & dat8 \
\end{mycustomtabular}
\begin{mycustomtabular}[longtable] % set to use longtable
col1 & col2 & col3 & col4 \
dat1 & dat2 & dat3 & dat4 \
dat5 & dat6 & dat7 & dat8 \
\end{mycustomtabular}
Update 2015-04-13
I was able to format a column, but not yet globally with the following code.
**A step in the right direction, but still missing the ability to add two things globally:
\rowstyle{\bfseries\Large\color{green!25!gray}}(this works withNewEnviron+tabularx)\midrule- (ignoring issues with referencing cells for the time being)
Code
\documentclass{article}
\usepackage{fontspec}
\usepackage{booktabs} % Adds support for \toprule, \midrule, \bottomrule
\usepackage{xcolor} % Adds support for coloring blocks of text: \color{green!25!black} or \textcolor{green!25!black){text}
\usepackage{tabularx}
\usepackage{environ} % Use for tabular environment when using booktabs
\usepackage{array} % https://tex.stackexchange.com/a/4816/13552
\newcolumntype{$}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{^}{>{\currentrowstyle}}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}%
#1\ignorespaces
}
\newenvironment{mytab}[1][$l*{50}{^l}]{% <-- tabular WORKS!
\begin{tabular}{#1}\toprule}{%
\rowstyle{\bfseries\color{green}} %<-- Global \rowstyle
\\bottomrule\end{tabular}}
\newenvironment{mytabx}[1][$l*{50}{^l}]{% <-- tabularx WORKS!
\tabularx{\linewidth}{#1}\toprule}{%
\\bottomrule\endtabularx}
\NewEnviron{mysupertabx}[1][$l*{50}{^l}]{% <-- tabularx with NewEnviron
\tabularx{\linewidth}{#1}\toprule\rowstyle{\bfseries\color{green!25!gray}}\BODY\bottomrule}{% <-- Global formatting on first row WORKS!
\endtabularx}
\begin{document}
\begin{table}
\begin{mytab}
\rowstyle{\bfseries\Large\color{green!25!gray}} %<--- Commenting this line out should make global \rowstyle apply
col1 & col2 & col3 & col4 \ \midrule
dat1 & dat2 & dat3 & dat4 \
dat5 & dat6 & dat7 & dat8 \
\end{mytab}
\caption{Tabular without working global row style or global centering}
\end{table}
\begin{table}
\begin{mytabx}[$l^X^l^l] % <-- tabularx with local override WORKS but with an issue (see output)!
\rowstyle{\bfseries\color{green!25!gray}} %<--- Commenting this line out should make global \rowstyle apply
col1 & col2 & col3 & col4 \ \midrule
dat1 & dat2 & dat3 & dat4 \
dat5 & dat6 & dat7 & dat8 \
\end{mytabx}
\caption{Tabularx with messed up first row}
\end{table}
\def\tabularxcolumn#1{m{#1}} % Redefines tabularx X row to vertically center text
\begin{table}
\begin{mytabx}[$l^X^l^l] % <-- tabularx with local override WORKS but with an issue (see output)!
\rowstyle{\bfseries\color{green!25!gray}} %<--- Commenting this line out should make global \rowstyle apply
col1 & col2 & col3 & col4 \ \midrule
dat1 & dat2 & dat3 & dat4 \
dat5 & dat6 & dat7 & dat8 \
\end{mytabx}
\caption{Tabularx inside newenvironment with fixed first row (column redefinition) but broken bottomrule.}
\end{table}
\begin{table}
\begin{mysupertabx}[$l^X^l^l] % <-- tabularx with local override WORKS but with an issue (see output)!
%\rowstyle{\bfseries\color{green!25!gray}} %<--- Commenting this line out should make global \rowstyle apply and in this case it WORKS!
col1 & col2 & col3 & col4 \ \midrule
dat1 & dat2 & dat3 & dat4 \
dat5 & dat6 & dat7 & dat8 \
\end{mysupertabx}
\caption{Tabularx inside NewEnviron from environ package with working global formatting for first row. Midrule must still be explicitly inputted into the tabular data :(}
\end{table}
\end{document}
Tabular Output

Tabularx with Local Override Output
The fix for this is found here:
https://tex.stackexchange.com/a/105671/13552

Full Output

Disclaimer: I realize that this question does not target a specific problem (rather an issue with tables), but if it is alright, I think it is more useful than my favorite question: How can I explain the meaning of LaTeX to my grandma?
\newcolumntypecommand fromarrayand define some 'general' column types which can be customized... an idea, not checked – Apr 08 '15 at 07:47calsuseful. The only thing it lacks is per-column formatting. http://www.ctan.org/pkg/cals – olpa Apr 09 '15 at 13:36