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.

I have a multirow column in a longtable with alternating coloured rows. The alternating colour overflows into the multirow. Colouring the first column white wipes out the specialrule but doesn't seem to make a difference to the row colour. I am not sure how to deal with this. Would you have any pointers?

Here is my MWE:

\documentclass[10pt]{article}
\usepackage{longtable, booktabs, rotating, multirow}
\usepackage[table]{xcolor}
\definecolor{tblue}{HTML}{F1F5FA}
\definecolor{tgrey}{HTML}{dddddd}
\renewcommand{\arraystretch}{1.6}
\usepackage{arydshln}
\arrayrulecolor{tgrey}
\begin{document}
\rowcolors{1}{tblue}{white}\centering
\begin{longtable}{>{\columncolor{white}}l !{\color{white}\vrule width 4pt}>{\raggedright}p{3in} p{2.4in}}
\hiderowcolors
&\textbf{Selected representative vars}&\textbf{Correlated vars ($\rho \ge$ 0.8)}\\
\specialrule{0.01em}{0.02em}{0.02em}
\endhead
\specialrule{0.01em}{0.0em}{0em}
\endfoot
\specialrule{0.01em}{0.0em}{0em}
&\multicolumn{2}{l}{\textbf{Subheading}}\\
\specialrule{0.01em}{0.0em}{0em}
\showrowcolors
& Something & Something else
\\
& Something & Something else
\\
& Something & Something else
\\
\hiderowcolors
\specialrule{0.01em}{0.0em}{0em}
&\multicolumn{2}{l}{\textbf{Subheading}}\\
\specialrule{0.01em}{0.0em}{0em}
\showrowcolors
& Something & Something else
\\
& Something & Something else
\\
& Something & Something else
\\
\multirow{-9}{*}{\begin{sideways}\centering \textbf{A long line of sideways text}\end{sideways}}
\end {longtable}
\end{document}

Here is what the table looks like currently: enter image description here

share|improve this question

1 Answer 1

up vote 6 down vote accepted

A different way of thinking: Insert the vertical text using zero-width boxes, rather than giving its own column.

enter image description here

\documentclass[10pt]{article}
\usepackage{longtable, booktabs, graphicx, multirow}
\usepackage[table]{xcolor}
\definecolor{tblue}{HTML}{F1F5FA}
\definecolor{tgrey}{HTML}{dddddd}
\renewcommand{\arraystretch}{1.6}
\usepackage{arydshln}
\arrayrulecolor{tgrey}
\begin{document}
\rowcolors{1}{tblue}{white}\centering
\begin{longtable}{!{\color{white}\vrule width 4pt}>{\raggedright}p{3in} p{2.4in}}
  \hiderowcolors
  \textbf{Selected representative vars}&\textbf{Correlated vars ($\rho \ge$ 0.8)}\\
  \specialrule{0.01em}{0.02em}{0.02em}
  \endhead
  \specialrule{0.01em}{0.0em}{0em}
  \endfoot
  \specialrule{0.01em}{0.0em}{0em}
  \multicolumn{2}{l}{\textbf{Subheading}}\\
  \specialrule{0.01em}{0.0em}{0em}
  \showrowcolors
  Something & Something else \\
  Something & Something else \\
  Something & Something else \\
  \hiderowcolors
  \specialrule{0.01em}{0.0em}{0em}
  \multicolumn{2}{l}{%
    \llap{\smash{\rotatebox[origin=c]{90}{%
      \hspace*{2\normalbaselineskip}% Vertical adjustment
      \textbf{A long line of sideways text}}}%
      \hspace*{\dimexpr\tabcolsep+2em}}% Horizontal adjustment
    \textbf{Subheading}}\\
  \specialrule{0.01em}{0.0em}{0em}
  \showrowcolors
  Something & Something else \\
  Something & Something else \\
  Something & Something else \\
  %\multirow{-9}{*}{\begin{sideways}\centering \textbf{A long line of sideways text}\end{sideways}}
\end{longtable}
\end{document}

The sideways text is rotated using \rotatebox[origin=c]{90}{..} from graphicx (also included when using rotating). origin=c pivots the rotation around the centre of the object. \llap create a left overlap, pushed outward by \tabcolsep+2em. This effectively places the sideways text 2em from the left margin of the longtable. Also, since I chose an element not exactly in the middle (vertically) of the table, pushing it upward by 2\normalbaselineskip allows for proper vertical alignment with the rest of the table's body (8 rows).

\smash removes all vertical height + depth from an object, thereby not affecting the row height.

share|improve this answer
    
It works most beautifully! With your code, I added several sideways labels without the need for adding a whole column and altering my pre-existing tables! Thanks so very much for this solution!! :-) –  Ariel May 21 '12 at 16:21

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.