Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How can I define a style (font, size, color etc) for a whole row, without repiting the command before each cell?

Note that I do not want to use tabu package. I want to know to what extent this can be done without tabu. (nothing against tabu, I want to demonstrate the usage of standard tabular env. and in contrast tabu).

Also I do not want to add new columntypes. The principle shall be applicable to any table in a complex document, without inventing columntypes for each column in each table.

This example shows that only the first cell after the setting of styles is changed.

\documentclass[]{scrbook} 

\usepackage[
  dvipsnames, % Load a set of predefined colors 
  table,      % Load the colortbl package
]{xcolor}

\usepackage{float}

\begin{document}

\begin{table}[H]
%  --- table -->
  \renewcommand{\arraystretch}{1.4}
  \centering
  \sffamily
  \rowcolors{1}{gray!15}{white!100}%
  % <------------
\begin{tabular}{lll}
\hline
%  --- thead -->
\rowcolor{gray!25}
\small
\rmfamily
% <------------
   header &
   header &
   header \tabularnewline
\hline
%  --- tbody -->
\tiny\slshape
% <------------
content & content  & content \tabularnewline
content & content  & content \tabularnewline
content & content  & content \tabularnewline
\hline
\end{tabular}
\end{table}
\end{document}
share|improve this question
4  
If you're going to show good examples of LaTeX code, please refrain from using the [H] option for floating objects. In some occasions it can come handy, but in general it's not recommendable. –  egreg Oct 6 '11 at 12:58
    
I need a group, because otherwise the commands after \begin{table} would be applied to the whole document. I would prefer to write \begin{table}[float=none] but that is not implemented. Since there is no other solution which combines this functionality with self explaining code I always use [H] if I do not want floats. –  Matthias Pospiech Oct 6 '11 at 13:54
    
if you don't want floats, it's always possible to wrap the object to be isolated in \begingroup ... \endgroup which has nearly the same effect; the major difference of which i'm aware is that it doesn't include the extra vertical space associated with floats, but you can always add that yourself. –  barbara beeton Oct 6 '11 at 14:55
    
I know many ways to achieve the same. \begingroup .. is one of them. But I prefer readable self-explanatory code. –  Matthias Pospiech Oct 6 '11 at 16:38
add comment

1 Answer

up vote 1 down vote accepted

I put together I package which almost does what I want - configurable tables styles. Here is an example of the user API. Please provide feedback if you like it or what should be changed. The full code including a very detailed example is linked below.

Table Style

\begin{table}[H]
\tablestyle[sansboldbw]
\captionabove{table with darker alternating colors}
\begin{tabular}{*{2}{v{0.45\textwidth}}}
\theadstart
   \thead header &
   \thead header \tabularnewline
\tbody
\tsubheadrow{2}{subheader} 
 content  & content \tabularnewline
 content  & content \tabularnewline
 content  & content \tabularnewline
 content  & content \tabularnewline
 content  & content \tabularnewline
 content  & content \tabularnewline
 %
 \tsubheadstart
 \tsubhead subhead &
 \tsubhead subhead \tabularnewline
 %
 content  & content \tabularnewline
 content  & content \tabularnewline
\tend
\end{tabular}
\end{table}

The API for configuration of new styles can be improved. Documentation is not available currently. But I only want to start if the code itsself is considered useful. What I do not like currently is the definition of new columnstyles. But that is part of another thread.

share|improve this answer
    
Your links are dead ;) –  azetina Jul 4 '12 at 14:35
    
I no longer work there... But the whole code is online at code.google.com/p/latexthesistemplate/source/browse/… –  Matthias Pospiech Jul 5 '12 at 16:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.