3

I experience this issue where the rows in a longtable after \multicolumn{1}{r}{Some text} are contracted:

Problem:

Here is an example holding all packages I currently use:

\documentclass[12pt]{article} 
\usepackage{geometry,graphicx,csquotes}
\usepackage{pdfpages,enumitem,xcolor,sidenotes,fancyhdr}
\usepackage{longtable,booktabs,multicol,colortbl,url,pbox,pifont}

\begin{document}
        \begin{longtable}{@{}rl@{}}
            \rowcolor{tablehead}
                \multicolumn{2}{c}{{\color{tabletxt}
                     \textbf{A header which is multicolumn}}}
            \\ \addlinespace[2mm]
            \rowcolor{tableodd}
                \multicolumn{1}{c}{Text}
            &
            \multicolumn{1}{c}{Website}
            \\ \addlinespace[-1mm]
                \midrule \addlinespace[2mm]
                % HEADER END
                Some text & \url{http://www.example.com/example} \\
            \rowcolor{tableodd} Some text & \url{http://www.example.com/example} \\
                Some text & \url{http://www.example.com/example} \\
            \rowcolor{tableodd} Some text & \url{http://www.example.com/example} \\
                Some text & \url{http://www.example.com/example} \\
            \rowcolor{tableodd} Some text & \url{http://www.example.com/example} \\
                Some text & \url{http://www.example.com/example} \\
            \rowcolor{tableodd} Some text & \url{http://www.example.com/example} \\
                Some text & \url{http://www.example.com/example} \\
            \rowcolor{tableodd} Some text & \url{http://www.example.com/example} \\
                Some text & \url{http://www.example.com/example} \\
        \end{longtable}
\end{document}

Resulting in the following table (Note the difference in width):

table with issue

One Solution:

While using \multicolumn{}{}{} in all cells, this solves the problem:

\documentclass[12pt]{article} 
\usepackage{geometry,graphicx,csquotes}
\usepackage{pdfpages,enumitem,xcolor,sidenotes,fancyhdr}
\usepackage{longtable,booktabs,multicol,colortbl,url,pbox,pifont}

\begin{document}
        \begin{longtable}{@{}rl@{}}
            \rowcolor{tablehead}
                \multicolumn{2}{c}{{\color{tabletxt}
                    \textbf{A header which is multicolumn}}}
            \\ \addlinespace[2mm]
            \rowcolor{tableodd}
                \multicolumn{1}{c}{Multicolumn text}
            &
            \multicolumn{1}{c}{Multicolumn website}
            \\ \addlinespace[-1mm]
                \midrule \addlinespace[2mm]
                % HEADER END
            \multicolumn{1}{r}{Some Text}
                & \multicolumn{1}{l}{\url{http://www.example.com/example}} \\
            \rowcolor{tableodd}
                \multicolumn{1}{r}{Some Text}
                & \multicolumn{1}{l}{\url{http://www.example.com/example}} \\
            \multicolumn{1}{r}{Some Text}
                & \multicolumn{1}{l}{\url{http://www.example.com/example}} \\
            \rowcolor{tableodd}
                \multicolumn{1}{r}{Some Text}
                & \multicolumn{1}{l}{\url{http://www.example.com/example}} \\
            \multicolumn{1}{r}{Some Text}
                & \multicolumn{1}{l}{\url{http://www.example.com/example}} \\
            \rowcolor{tableodd}
                \multicolumn{1}{r}{Some Text}
                & \multicolumn{1}{l}{\url{http://www.example.com/example}} \\
            \multicolumn{1}{r}{Some Text}
                & \multicolumn{1}{l}{\url{http://www.example.com/example}} \\
            \rowcolor{tableodd}
                \multicolumn{1}{r}{Some Text}
                & \multicolumn{1}{l}{\url{http://www.example.com/example}} \\
            \multicolumn{1}{r}{Some Text}
                & \multicolumn{1}{l}{\url{http://www.example.com/example}} \\
            \rowcolor{tableodd}
                \multicolumn{1}{r}{Some Text}
                & \multicolumn{1}{l}{\url{http://www.example.com/example}} \\
        \end{longtable}
\end{document}

Which resolves to the following table:

enter image description here

Further reading

In section 4 "Multicolumn entries" of the longtable documentation, David Carlisle describes the \kill and \setlongtables commands. But it is not clear to me how these solve the issues. I've tried to use kill on an empty row on top, even on a multicolumn spanning both columns.

Even after several passes, I cannot seem to get the rows in line, so to speak. I firmly believe there is a better option than using multicolumn in every cell.

Any ideas?

9
  • 2
    in column definition remove @{} ...
    – Zarko
    Apr 19, 2017 at 4:37
  • 1
    Off-topic: It's poor practice to load the xcolor and colortbl packages independently. If both packages are needed, one should issue the instruction \usepackage[table]{xcolor} to optimize the interoperability between the two packages.
    – Mico
    Apr 19, 2017 at 5:53
  • @zarko, I cannot believe I missed that!
    – Ole Aldric
    Apr 19, 2017 at 6:57
  • @mico, by doing so, I get a option clash warning.
    – Ole Aldric
    Apr 19, 2017 at 6:57
  • 1
    I've taken the liberty of editing your posting to remove all references to the multicol package, as it is neither involved in the issue you've raised nor even used in your code.
    – Mico
    Apr 19, 2017 at 7:56

1 Answer 1

5

The cause of your problem is feature of colortbl package, see explanation in section 1 and 2 in the package documentation.

The simplest solution is not to use @{} in definition of longtable columns: instead of \begin{longtable}{@{}rl@{}} you should use only \begin{longtable}{rl}:

enter image description here

\documentclass[12pt]{article}
\usepackage{geometry}
\usepackage[table]{xcolor}
\usepackage{booktabs, longtable}
\usepackage{url}

\begin{document}
        \begin{longtable}{rl}
            \rowcolor{gray}
                \multicolumn{2}{c}{{\color{white}
                    \scshape \textbf{A header which is multicolumn}}}
            \\ \addlinespace[2mm]
            \rowcolor{gray!30}
                \multicolumn{1}{c}{Text}
            &
            \multicolumn{1}{c}{Website}
            \\ \addlinespace[-1mm]
                \midrule \addlinespace[2mm]
                % HEADER END
                Some text & \url{http://www.example.com/example} \\
            \rowcolor{gray!30} Some text & \url{http://www.example.com/example} \\
                Some text & \url{http://www.example.com/example} \\
            \rowcolor{gray!30} Some text & \url{http://www.example.com/example} \\
                Some text & \url{http://www.example.com/example} \\
            \rowcolor{gray!30} Some text & \url{http://www.example.com/example} \\
                Some text & \url{http://www.example.com/example} \\
            \rowcolor{gray!30} Some text & \url{http://www.example.com/example} \\
                Some text & \url{http://www.example.com/example} \\
            \rowcolor{gray!30} Some text & \url{http://www.example.com/example} \\
                Some text & \url{http://www.example.com/example} \\
        \end{longtable}
\end{document}

Note: as noted Mico in his comment, Computer Modern fonts doesn't feature a bold small caps font shape/face.

2
  • Don't enclose a longtable environment in a center environment. Also, it may be worth pointing out that Computer Modern doesn't feature a bold smallcaps font shape/face.
    – Mico
    Apr 19, 2017 at 5:47
  • @Mico, I know that the longtable is centered in itself. I simple forgot to remove \begin{center} ...\end{center}˙ ... corrected now. Regarding used font, I didn't give any attention to this issue. My bed :)
    – Zarko
    Apr 19, 2017 at 6:13

You must log in to answer this question.

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