colortbl
doesn't much like \extracolsep
. For individual cells you can fiddle with the optional overhang arguments, but for rows that's a bit difficult.
Also your table isn't full width as the \extracolsep
glue is balanced by \LTleft
and \LTright
glue that is either side of the table.
If you make it full width, making the colour bands is much easier, as you know in advance how big they need to be:
\documentclass[9pt]{article}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage[margin=0.5in]{geometry}
\usepackage{fancyhdr}
\LTchunksize=200
\setlength{\parindent}{0cm}
\title{test}
\author{R}
\setlength{\headheight}{0.4in}
\setlength{\headwidth}{\textwidth}
\usepackage[table]{xcolor}
% define lightgray
\definecolor{lightgray}{gray}{0.9}
% alternate rowcolors for all long-tables
\let\oldlongtable\longtable
\let\endoldlongtable\endlongtable
%\renewenvironment{longtable}{\rowcolors{2}{white}{lightgray}\oldlongtable} {
%\endoldlongtable}
\def\zza{\global\let\zz\zzb
\fullwidthcolor{lightgray}}%
\def\zzb{\global\let\zz\zza}
\def\fullwidthcolor#1{\color{#1}\leaders\vrule\hskip\textwidth\hskip-\textwidth\kern0pt}
\def\resetLTcolor{\global\let\zz\zza}
\LTleft0pt
\LTright0pt
\begin{document}
\section{Sector}
\resetLTcolor
\begin{longtable}{ @{\zz\extracolsep{\fill}} |l | r | r | r | r | r|}
\hline
\multicolumn{1}{@{\fullwidthcolor{yellow}\extracolsep{\fill}} |l |}{}
& Beta & Phys & Phys & Phys & comp \\
\multicolumn{1}{@{\fullwidthcolor{yellow}\extracolsep{\fill}} |l |}{Industry Code}
& {} & {} & {} & {} & {} \endhead
\hline
Materials & 16,365,792 & 13,419,455 & 13,419,455 & 0.00 & -201,593 \\
Goods & 471,925 & 1,110,412 & 1,110,412 & 0.00 & -11,947 \\
Services & 7,122,991 & 8,511,225 & 9,492,570 & -981,345 & -75,117 \\
Banks & 5,078,280 & 6,123,238 & 12,084,671 & -5,961,433 & -69,738 \\
Health & 2,141,346 & 5,059,382 & 5,059,382 & 0.00 & -26,319 \\
Industrials & -6,013,491 & -4,758,346 & 6,036,445 & -10,794,791 & 3,722 \\
row & -4,093,746 & -3,755,730 & 0.00 & -3,755,730 & 45,628 \\
row & -1,753,606 & -1,006,601 & 2,533,792 & -3,540,393 & -18,962 \\
Consumer & 2,227,195 & 2,317,581 & 2,317,581 & 0.00 & -30,632 \\
All & 20,808,544 & 25,160,345 & 54,728,908 & -29,568,563 & nan \\
\hline
\end{longtable}
\end{document}
orange
is predefined, you can simply use it as {\color{orange}Hello}
without any color definitions. Otherwise, use the form \definecolor{MaterialOrange}{named}{orange}
as noted also by @samcarter or using the color value and model given in the manual. Finally, you should embrace the colored portion between two {}
, otherwise, the whole document will take the defined color.
\documentclass{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[swedish]{babel}
\usepackage{xcolor}
\usepackage{kvoptions}
\usepackage{xcolor-material}
% Material Colors
%\definecolor{MaterialOrange}{named}{orange} % This or
%\definecolor{MaterialOrange}{HTML}{FF8000} % this or
\definecolor{MaterialOrange}{cmyk}{0,0.5,1,0} % this
\begin{document}
{\color{MaterialOrange}Hello} and normal text ..
\end{document}
Best Answer
I will give an alternative solution with
longtblr
environment of the new LaTeX3 packagetabularray
: