5

i have currently this code in LaTeX

\begin{footnotesize}
\begin{center}
\begin{longtable}[c]{ll}
\caption[API da listagem de um docente]{API da listagem de um docente.}  \label{relStruct}\\
\begin{tabular}{|l|l|l|}
\hline
\multicolumn{1}{|c|}{\textcolor{WhiteC}{\textbf{URL}} \cellcolor{GreenC}} &
\multicolumn{2}{|c|}{http://di76.di.fct.unl.pt:3007/people} \\ \hline
\multicolumn{1}{|c|}{\textcolor{WhiteC}{\textbf{Method}} \cellcolor{GreenC}} &  
\multicolumn{2}{|c|}{GET} \\ \hline
\multirow{2}*{\textcolor{WhiteC}{\textbf{QueryString}} \cellcolor{GreenC}} & 
start= & The number of the first person to return \\  &  end= & The number of the last person to return \\ \hline
\multirow{2}{*}{\textcolor{WhiteC}{\textbf{Returns}} \cellcolor{GreenC}} &
\multicolumn{2}{|c|}{200 OK \& XML (people/people+xml)} \\ &
\multicolumn{2}{|c|}{404 Not Found} \\ \hline
\end{tabular}
%\end{center}
\end{longtable}
\end{center}
\end{footnotesize}

And the output of this code its a table where the 2 multirow parts are not painted fully, only the top of the row its painted. Anyone can tell me how to fix these problem in order to paint completely?

4 Answers 4

10

The best solution is to use \colorcolumn, for the first column, in the table format. Notice also that I changed \mulrirow{2}{*}{...} to \mulrirow{-2}{*}{...} to avoid problems with the text being overwritten by the color.

\documentclass{book}
\usepackage{longtable,multirow,array}
\usepackage[table]{xcolor}
\usepackage{lipsum}% just to generate some text

\colorlet{WhiteC}{white}% to make the example compilable
\colorlet{GreenC}{blue!60}% to make the example compilable

\begin{document}

\begingroup
\footnotesize
\begin{longtable}[c]{|>{\columncolor{GreenC}}l|l|l|}
  \caption[API da listagem de um docente]{API da listagem de um docente.}  \label{relStruct}\\
  \hline
  \multicolumn{1}{|c|}{\cellcolor{GreenC}\textcolor{WhiteC}{\textbf{URL}}}  & \multicolumn{2}{c|}{http://di76.di.fct.unl.pt:3007/people} \\ \hline
  \multicolumn{1}{|c|}{\cellcolor{GreenC}\textcolor{WhiteC}{\textbf{Method}}} 
    & \multicolumn{2}{c|}{GET} \\ \hline
  & start= & The number of the first person to return \\ 
  \multirow{-2}{*}{\textcolor{WhiteC}{\textbf{QueryString}}} & end= 
    & The number of the last person to return \\ \hline
  & \multicolumn{2}{c|}{200 OK \& XML (people/people+xml)} \\ 
  \multirow{-2}{*}{\textcolor{WhiteC}{\textbf{Returns}}} 
    & \multicolumn{2}{c|}{404 Not Found} \\ \hline
\end{longtable}
\endgroup

\end{document}

There's no footnotesize environment; \footnotesize is a switch. I don't understand why you are using a tabular environment inside a longtable; use longtable if your table will admit page breaks and tabular otherwise. I redefined the colors GreenC and WhiteC to make my code compilable for everyone.

1
  • In the first column of the first two rows, you only need to enter \textcolor{WhiteC}{\textbf{URL}} and \textcolor{WhiteC}{\textbf{Method}}, respectively, as you've already used the \columncolor command. I.e., no need for the \cellcolor instructions, right?
    – Mico
    Nov 21, 2011 at 3:44
7

With multirow there are known problems when it's required to color a cell. I would define, in the preamble,

\newcommand{\mycell}[2][c]{\begin{tabular}{@{}#1@{}}#2\end{tabular}}
\newcommand{\greencell}[1]{\textcolor{WhiteC}{\bfseries #1}\cellcolor{GreenC}}

and write the table as

\begin{table}
\centering
\caption[API da listagem de um docente]{API da listagem de um docente.}  \label{relStruct}
\medskip
\footnotesize

\begin{tabular}{|c|c|}
\hline
\greencell{URL} & http://di76.di.fct.unl.pt:3007/people \\
\hline
\greencell{Method}&  GET \\
\hline
\greencell{QueryString} &
\mycell[l|l]{%
  start= & The number of the first person to return \\
  end= & The number of the last person to return} \\
\hline
\greencell{Returns} &
\mycell{200 OK \& XML (people/people+xml) \\
  404 Not Found} \\
\hline
\end{tabular}
\end{table}

The double row cells are input as argument to \mycell, which can receive an optional argument to express the kind of "subtabular" you need.

Whether you prefer this method or the \multirow method as in Gonzalo's solution is a matter of taste.

2
  • Thanks so much for the answers. It worked for both of the answers you gave me. :) Really appreciate the fast answer. Cheers!
    – Peddro
    Jun 19, 2011 at 19:43
  • 2
    @Peddro: It would be fair to mark your preferred solution as the right one. Jun 19, 2011 at 20:59
1

Use \multirow{-n}{*}{...} on the nth row and \rowcolor{color} on each i'th row (i=1..n). This solves the problem of \rowcolor not coloring the following rows when using \multirow.

1
  • 1
    Welcome to TeX.SE. Could you provide a working example of you answer? Longer answers are more appreciated :-) Sep 20, 2015 at 16:00
0

I had a similar problem and \multirow{-n}{*}{...} was not working for me. The -n was the primary part. However I used a similar format to the answer:

\begin{tabular}{  m{9cm} m{9cm} >{\columncolor{mygreen}}m{7.3cm}  }

Then for the multirow I put it in the final row and was able to successfully shift the text up using the option below. 3 represents how many rows. 2.8 in the width of the internal text and 35em is how much you want to shift it up. You probably won't need a number as high as 35.

\multirow{3}{2.8in}[35em]{lots of text...}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .