0

I have a table (longtable) that has a number of columns in alternating background colors. Once in a while, I want to have a row that spans all the columns. However, if I use \multicolumn, all the background colors are lost on that line.

For those rows, I was hoping there's a way to make the text from the leftmost column overflow on the other columns.

Here is a minimal example :

\documentclass[10pt,a4paper]{extarticle}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern,textcomp}
\usepackage{longtable}
\usepackage{array}
\usepackage{graphicx}
\usepackage[table]{xcolor}
\usepackage[a4paper,top=3cm,bottom=1cm,left=20mm,right=10mm,headheight=2cm]{geometry}
\renewcommand{\familydefault}{\sfdefault}
\colorlet{fondcol}{blue!4!white}

\newcolumntype{F}[2]{>{\columncolor{#1}\scriptsize\raggedright\arraybackslash}p{#2}}
\newcolumntype{L}[2]{>{\columncolor{#1}\ttfamily\fontseries{lc}\selectfont\footnotesize\raggedright\arraybackslash}p{#2}}
\newcolumntype{R}[2]{>{\columncolor{#1}\ttfamily\fontseries{lc}\selectfont\footnotesize\raggedleft\arraybackslash}p{#2}}
\newcolumntype{C}[2]{>{\columncolor{#1}\ttfamily\fontseries{lc}\selectfont\footnotesize\centering\arraybackslash}p{#2}}
\newcolumntype{M}[2]{>{\columncolor{#1}\tiny\raggedright\arraybackslash}p{#2}}
\begin{document}
{
    \setlength{\tabcolsep}{2pt}
    \setlength{\arrayrulewidth}{1pt}
    \begin{longtable}{|
        F{white}{55mm}
        L{fondcol}{9.5mm}
        L{white}{11mm}
        R{fondcol}{6mm}
        R{white}{5mm}
        R{fondcol}{10mm}
        C{white}{2mm}
        R{fondcol}{8mm}
        R{white}{10mm}
        R{fondcol}{8mm}
        R{white}{10mm}
        R{fondcol}{10mm}
        R{white}{12mm}
    |}
        \hline
        \centering col1 &
        \centering col2 &
        \centering col3 &
        \centering col4 &
        \centering\scriptsize col5 &
        \centering\scriptsize col6 &
        \centering\tiny col 7 &
        \centering\scriptsize col 8  &
        \centering\scriptsize col 9  &
        \centering\scriptsize col 10 &
        \centering\scriptsize col 11 &
        \centering\scriptsize col 12 &
        \centering\scriptsize col 13
        \tabularnewline
        \hline
        \endhead
        \textbf{ I would like this text to span all columns without changing the background colors}
        & & & & & & & & & & & &
        \tabularnewline
        \multicolumn{1}{|w{l}{55mm}}{This text may overflow but is overwritten by the other columns' color)}
        & & & & & & & & & & & &
        \tabularnewline
        \multicolumn{13}{|p{150mm}|}{This text does span all the columns but I lose the colors}
        \tabularnewline
        foo bar &
        0,00 &
        0,00 &
        0,00 &
        0,00 &
        0,00 &
        0,00 &
        0,00 &
        0,00 &
        0,00 &
        0,00 &
        0,00 &
        0,00
        \tabularnewline
        \hline
    \end{longtable}
}
\end{document}

Revised example with @Bernard's answer; the font changes and I didn't manage yet to recover the same font. Tried \sffamily before \textit ; I get the right font but no italics.

\documentclass[10pt,a4paper]{extarticle}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern,textcomp}
\usepackage{longtable}
\usepackage{array}
\usepackage{graphicx}
\usepackage[table]{xcolor}
\usepackage[a4paper,top=3cm,bottom=1cm,left=20mm,right=10mm,headheight=2cm]{geometry}
\renewcommand{\familydefault}{\sfdefault}
\colorlet{fondcol}{blue!4!white}

\newcolumntype{F}[2]{>{\columncolor{#1}\scriptsize\raggedright\arraybackslash}p{#2}}
\newcolumntype{L}[2]{>{\columncolor{#1}\ttfamily\fontseries{lc}\selectfont\footnotesize\raggedright\arraybackslash}p{#2}}
\newcolumntype{R}[2]{>{\columncolor{#1}\ttfamily\fontseries{lc}\selectfont\footnotesize\raggedleft\arraybackslash}p{#2}}
\newcolumntype{C}[2]{>{\columncolor{#1}\ttfamily\fontseries{lc}\selectfont\footnotesize\centering\arraybackslash}p{#2}}
\newcolumntype{M}[2]{>{\columncolor{#1}\tiny\raggedright\arraybackslash}p{#2}}
\begin{document}
{
    \setlength{\tabcolsep}{2pt}
    \setlength{\arrayrulewidth}{1pt}
    \begin{longtable}{|
        F{white}{55mm}
        L{fondcol}{9.5mm}
        L{white}{11mm}
        R{fondcol}{6mm}
        R{white}{5mm}
        R{fondcol}{10mm}
        C{white}{2mm}
        R{fondcol}{8mm}
        R{white}{10mm}
        R{fondcol}{8mm}
        R{white}{10mm}
        R{fondcol}{10mm}
        R{white}{12mm}
    |}
        \hline
        \centering col1 &
        \centering col2 &
        \centering col3 &
        \centering col4 &
        \centering\scriptsize col5 &
        \centering\scriptsize col6 &
        \centering\tiny col 7 &
        \centering\scriptsize col 8  &
        \centering\scriptsize col 9  &
        \centering\scriptsize col 10 &
        \centering\scriptsize col 11 &
        \centering\scriptsize col 12 &
        \centering\scriptsize col 13
        \tabularnewline
        \hline
        \endhead
        \textbf{I would like this text to span all columns without changing the background colors}
        & & & & & & & & & & & &
        \tabularnewline
        \textit{I would like this text to span all columns without changing the background colors}
        & & & & & & & & & & & &
%        \llap{\parbox{\dimexpr156.5mm + 24\tabcolsep}{\itshape\sffamily\scriptsize \var{_('gravure')} (\var{_(lig.gtype)})~: \var{lig.grav|esc|grav}}}
        \tabularnewline
%       \textit{\var{_('gravure')} (\var{_(lig.gtype)})~: \var{lig.grav|esc|grav}}
        & & & & & & & & & & & &
        \llap{\parbox{\dimexpr156.5mm + 24\tabcolsep}{\textit{I would like this text to span all columns without changing the background colors}}}
        \tabularnewline

        foo bar &
        0,00 &
        0,00 &
        0,00 &
        0,00 &
        0,00 &
        0,00 &
        0,00 &
        0,00 &
        0,00 &
        0,00 &
        0,00 &
        0,00
        \tabularnewline
        \hline
    \end{longtable}
}
\end{document}

with bernard's answer

2
  • 1
    Welcome to TeX.SX! Please make your code snippets -- as usual here -- compilable then we do not have to guess what you are doing!
    – Mensch
    Commented Mar 4, 2020 at 12:47
  • 1
    sorry about that -- edited the question with a compilable example
    – David V.
    Commented Mar 4, 2020 at 13:06

1 Answer 1

2

Here is a hack: insert your text in the last column, as a \parbox of the relevant width, combined with the \llap command:

\documentclass[10pt,a4paper]{extarticle}
   \usepackage[T1]{fontenc}
    \usepackage[utf8]{inputenc}
    \usepackage{lmodern,textcomp}
    \usepackage{longtable}
    \usepackage{graphicx}
    \usepackage[table]{xcolor}
    \usepackage[a4paper,top=3cm,bottom=1cm,left=20mm,right=10mm,headheight=2cm]{geometry}
    \renewcommand{\familydefault}{\sfdefault}
    \colorlet{fondcol}{blue!4!white}

\newcolumntype{F}[2]{>{\columncolor{#1}\scriptsize\raggedright\arraybackslash}p{#2}}
\newcolumntype{L}[2]{>{\columncolor{#1}\ttfamily\fontseries{lc}\selectfont\footnotesize\raggedright\arraybackslash}p{#2}}
\newcolumntype{R}[2]{>{\columncolor{#1}\ttfamily\fontseries{lc}\selectfont\footnotesize\raggedleft\arraybackslash}p{#2}}
\newcolumntype{C}[2]{>{\columncolor{#1}\ttfamily\fontseries{lc}\selectfont\footnotesize\centering\arraybackslash}p{#2}}
\newcolumntype{M}[2]{>{\columncolor{#1}\tiny\raggedright\arraybackslash}p{#2}}
\begin{document}
{
    \setlength{\tabcolsep}{2pt}
    \setlength{\arrayrulewidth}{1pt}
    \begin{longtable}{|
        F{white}{55mm}
        L{fondcol}{9.5mm}
        L{white}{11mm}
        R{fondcol}{6mm}
        R{white}{5mm}
        R{fondcol}{10mm}
        C{white}{2mm}
        R{fondcol}{8mm}
        R{white}{10mm}
        R{fondcol}{8mm}
        R{white}{10mm}
        R{fondcol}{10mm}
        R{white}{12mm}
    |}
        \hline
        \centering col1 &
        \centering col2 &
        \centering col3 &
        \centering col4 &
        \centering\scriptsize col5 &
        \centering\scriptsize col6 &
        \centering\tiny col 7 &
        \centering\scriptsize col 8 &
        \centering\scriptsize col 9 &
        \centering\scriptsize col 10 &
        \centering\scriptsize col 11 &
        \centering\scriptsize col 12 &
        \centering\scriptsize col 13
        \tabularnewline
        \hline
        \endhead
       & & & & & & & & & & & & \llap{\parbox{\dimexpr156.5mm + 24\tabcolsep}{I would like this text to span all columns without changing the background colors}}
     \tabularnewline
        foo bar &
        0,00 &
        0,00 &
        0,00 &
        0,00 &
        0,00 &
        0,00 &
        0,00 &
        0,00 &
        0,00 &
        0,00 &
        0,00 &
        0,00
        \tabularnewline
        \hline
    \end{longtable}
}

\end{document}

enter image description here

6
  • This hack is perfect with a minor problem: The font is not the same. Trying to find a workaround
    – David V.
    Commented Mar 4, 2020 at 14:39
  • it seems I have to find what cancels \fontseries{lc} but I don't even know exactly what it means.
    – David V.
    Commented Mar 4, 2020 at 14:54
  • 1
    lc means light condensed. The reason I added a \textbf command, as in your post. I removed it. Please see whether it's like you want now.
    – Bernard
    Commented Mar 4, 2020 at 15:09
  • It's still not what I'm looking for. regardless, your answer is really helpful so I'm accepting it. I also edited the question with a screenshot to show the font problem. I'm happy with what I have now, but I'd be curious to see a solution to the font problem.
    – David V.
    Commented Mar 4, 2020 at 15:36
  • You seem to want a bold sans font?
    – Bernard
    Commented Mar 4, 2020 at 16:05

You must log in to answer this question.

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