1

I'm creating a table with alternating coloured rows. However, the colour seems to extend the top- bottom rule of the table, which doesn't look quite right.

Also, my header row probably should be a multiline, but I am not quite sure how to do that. I tried the tabularx environment using the first column defined as 'X' but it seems not to be working in an threeparttable environment?

Please excuse my really messy header, but I am not sure which packages I need and which I don't so I don't wanna erase anything important...

Heres the MWE:

% Layout preamble

\documentclass[12pt, a4paper] {article}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage[margin=2.5cm,left=2.5cm,top=3cm,bottom=3cm,includefoot,headsep=.8in]{geometry}
\usepackage[dvipsnames,table]{xcolor}
%%%% For Fancy Style Format with Headers %%%%%%%%%%%%
\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhf{}

\lhead{\textcolor{Cyan}{\raisebox{-.5\baselineskip}[0pt][0pt]{Group No. 1}}}
\lfoot{\thepage}
\renewcommand{\footrulewidth}{0.8pt}
\renewcommand{\headrulewidth}{0.8pt}
\renewcommand{\headrule}{\hbox to\headwidth{%
\color{Cyan}\leaders\hrule height \headrulewidth\hfill}}

%%%%%%%%%%%% BOXES AROUND SECTIONS %%%%%%%%%%%%%%

%\usepackage{color}
\usepackage{titlesec}
\usepackage{tocloft}
\renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}

\makeatletter
\newif\if@secnum
%\definecolor{lgray}{gray}{0.75}
\titleformat{\section}[hang]{\Large\bfseries}{%
    \global\@secnumtrue
}{0em}{%
    {%
        \setlength{\fboxsep}{0pt}%
        \colorbox{Cyan!30}{\makebox[\textwidth]{\Large\strut}}%
    }%
    \hspace*{-\textwidth}%
    \if@secnum%
        \arabic{section}%
        \hspace*{1em}%
    \fi%
    \global\@secnumfalse%
}[]
\makeatother

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Math preamble
\usepackage{mathtools}
\DeclareMathOperator{\var}{var}
\usepackage{mathdesign}
\renewcommand{\vec}[1]{\mathbf{#1}}
\providecommand\given{}
\DeclarePairedDelimiterXPP\EV[1]{E}[]{}{
\renewcommand\given{\nonscript\;\delimsize\vert\nonscript\;\mathopen{}}
#1}
%Tables preamble
\usepackage{longtable}
\usepackage{tabularx}
\usepackage{marvosym}
\usepackage{setspace}
\usepackage{booktabs, rotating, dcolumn, siunitx, array}
\usepackage{multirow}
\usepackage{threeparttable}
\usepackage{enumitem}

% Graphics preamble
\usepackage{graphicx}
\usepackage{float}
\usepackage[skip=10pt, labelfont=bf, labelsep=space]{caption}

\makeatletter
\setlength{\@fptop}{0pt}
\makeatother
% Drawing figures in document
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{backgrounds, shapes, snakes}
% avoids hyphenation of words in tables
% cllickable hyperlinks preamble
\usepackage[hidelinks]{hyperref}
\usepackage{url}
\usepackage{hyphenat} 

% Bibliography preamble
\usepackage[comma]{natbib}
\usepackage{har2nat}
\hypersetup{hidelinks=true}
\usepackage{etoolbox}
\apptocmd{\thebibliography}{\raggedright}{}{}
\makeatletter
\newcommand{\addcolonandeatperiod}{\@ifnextchar.{:\@gobble}\relax}
\makeatother
% for having raggedright footnotes
\usepackage[hang,flushmargin]{footmisc}
% Timeline tabular
% Sources under figures
\newcommand{\source}[1]{{\footnotesize Source: #1}}
% For eurosymbol
\usepackage{eurosym}
% Appendix
\usepackage{appendix}
\usepackage{capt-of}
\usepackage{pdfpages}

% Table headers:
\DeclareCaptionFormat{centerlabel}{{\centering #1\par}\medskip#3\par}
\captionsetup[table]{format=centerlabel}

\newcommand\firstpart[1]{{\centering\bfseries#1\par}\medskip}
\newcommand\secondpart[1]{\small#1}

% Small tabulars:
\newcommand{\mytab}[1]{%
\begin{tabular}{@{}c@{}}
#1
\end{tabular}
}

\nocite{*}

\usepackage{transparent}

\usepackage{transparent}
\usepackage{eso-pic}
\newcommand\BackgroundIm{
\put(0,-200){
\parbox[b][\paperheight]{\paperwidth}{%
\vfill
\centering
{\transparent{0.1}\includegraphics[height=0.4\paperheight,width=\paperwidth,
keepaspectratio]{./pie}%
\vfill}}}}


%%%% Document %%%%%%%%

\begin{document}
\pagestyle{fancy}
\rowcolors{2}{Cyan!25}{white}


\begin{table}[!h]
\centering
\begin{threeparttable}
\caption[Top 20 Holdings
]{%
\firstpart{Top 20 Holdings }
\secondpart{This table displays the 20 companies with biggest weights as of 20.09.2015.}
}\label{tab: assets}
\begin{tabular}{@{}lcccc@{}}
\rowcolor{Cyan!50}
\toprule
Name of Company & Ticker & Sector & Annualised & Annualised \\
\rowcolor{Cyan!50}
& & & Return & St. Dev. \\
\midrule
Humana Inc & HUM & Health Care & 38.54\% & 29.05\% \\
Thermo Fisher Scientific Inc & TMO & Health Care & 23.95\% & 20.64\% \\
Monsanto Co & MON & Materials & 22.04\% & 26.50\% \\
Tenet Healthcare Corp & THC & Health Care & 43.77\% & 45.46\% \\
Flextronics International Ltd & FLEX & Technology & 19.85\% & 29.07\% \\
Community Health Systems Inc & CYH & Health Care & 22.87\% & 41.32\% \\
Anthem Inc & ANTM & Health Care & 30.47\% & 22.19\% \\
Aetna Inc & AET & Health Care & 39.87\% & 20.90\% \\
Endo International PLC & ENDP & Health Care & 37.64\% & 37.74\% \\
VCA Inc & WOOF & Health Care & 20.82\% & 25.67\% \\
PVH Corp & PVH & Consumer & 25.76\% & 31.87\% \\
Allergan plc & AGN & Health Care & 52.27\% & 19.95\% \\
ManpowerGroup Inc & MAN & Industrials & 21.97\% & 33.42\% \\
CBS Corp & CBS & Consumer & 38.81\% & 27.97\% \\
Laboratory Corp of America Hol & LH & Health Care & 11.39\% & 16.13\% \\
Cigna Corp & CI & Health Care & 42.20\% & 21.65\% \\
Cadence Design Systems Inc & CDNS & Technology & 30.66\% & 22.24\% \\
Applied Materials Inc & AMAT & Technology & 14.36\% & 28.95\% \\
Brookdale Senior Living Inc & BKD & Health Care & 26.26\% & 37.42\% \\
Pentair PLC & PNR & Industrials & 19.89\% & 25.07\% \\
\bottomrule
\end{tabular}
\end{threeparttable}
\end{table}

\end{document}
  • 2
    MWE ? Is that really the smallest example you can make? It is easy fror you to test if the packages you load are important, just delete them and see if the error still occurs, also why not make a three line talel with data A&B&C ? anyone trying to help may need to run your example with tracing enabled it's not reasonable to trace an example like this. – David Carlisle Nov 27 '15 at 20:26
3

If you use

\begin{tabular}{lcccc}

then the rules are the same length as the coloured panels:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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