2

I am currently trying to fill a whole row from a longtable with color.

However, the collor filling does not make it to the end of the columns:

enter image description here

Any idea how can I fix this? Bellow I present the code.

Many thanks

\documentclass{article}

\usepackage{longtable}
\usepackage{lipsum}
\usepackage[table]{xcolor}

\title{A longtable example}

\begin{document}

\begin{center}
    \begin{longtable}{p{8cm} p{3cm} p{1cm}}
        \caption{Calculation of estimated revenues for the first year of sales.} \label{tab:long} \\

        \hline \multicolumn{1}{l}{\textbf{Column}} & \multicolumn{1}{l}{\textbf{Calculation}} & \multicolumn{1}{l}{\textbf{Source/ Notes:}} \\ \hline 
        \endfirsthead

        \multicolumn{3}{c}%
        {{\bfseries \tablename\ \thetable{} -- continued from previous page}} \\
        \hline \multicolumn{1}{l}{\textbf{Column)}} & \multicolumn{1}{l}{\textbf{Calculation}} & \multicolumn{1}{l}{\textbf{Source/ Notes:}} \\ \hline 
        \endhead

        \hline \multicolumn{3}{r}{{Continued on next page}} \\
        \endfoot

        \hline
        \endlastfoot

        \lipsum[3]                                                                                                                                                                          & text text text                & Link 1                  \\ \hline         \rowcolor[HTML]{efefef}
        \lipsum[3] & text text text text       & Link 2                  \\ \hline
        \lipsum[3]                                                           & text text &                         \\ \hline
        \lipsum[3]                                                                                                                                                                                                                                                                                                                                    & 220,675 devices                   &                         \\ \hline
        \lipsum[3]                 &                         \\ \hline
        \lipsum[3] &                         \\ \hline
        \lipsum[3]                                                                                                             & 15\%                              &                         \\ \hline
        \textbf{Potential Market Volume:} \newline (Market volume = Number of devices purchased x Penetration rate)                                                                                                                                                                                                                                                                                                                                                                      & 33 101 devices                    &                         \\ \hline
        \lipsum[2]   & \\
    \end{longtable}
\end{center}

\end{document}
2

The last column is wider than the specified size of 1cm. This is caused by the \multicolumn in the header, which is of type l and therefore does not break the line. However, rowcolor uses the specified size and therefore does not color the full column.

When you increase the column width the issue is resolved - however it is better not to use multicolumns of size 1 and allow the main column type (p{1cm} in this case) to determine the column width.

Code:

\begin{longtable}{p{8cm} p{3cm} p{3cm}}

Result:

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.