1

I'm trying to create a longtable for 15 columns- however, it doesn't fit properly with the page border when it compiles.

Can anyone help me out?

\documentclass{article}

\RequirePackage[l2tabu,orthodox]{nag}
\usepackage{multirow}
\usepackage{longtable}
\usepackage{chngpage}
\usepackage{colortbl}
\usepackage{xcolor}
\usepackage{longtable}
\usepackage{paracol}
\usepackage{booktabs, makecell, tabularx}
\usepackage{booktabs, multirow}

\begin{document}
\begin{table}
\centering
\caption{Comparison of customers.}
\begin{tabular}{c c ccc ccc ccc ccc ccc}
\multirow{2}{*}{}
&
\multirow{2}{*}{} 
        & \multicolumn{15}{c}{customers}\\
    \cmidrule(lr){3-17}
        &  & \cellcolor{lightgray} 1  & \cellcolor{lightgray} 2  & \cellcolor{lightgray} 3  & \cellcolor{lightgray} 4  & \cellcolor{lightgray} 5  & \cellcolor{lightgray} 6 &
        \cellcolor{lightgray} 7  & \cellcolor{lightgray} 8  & \cellcolor{lightgray} 9  & \cellcolor{lightgray} 10  & \cellcolor{lightgray} 11  & \cellcolor{lightgray} 12 & \cellcolor{lightgray} 13  & \cellcolor{lightgray} 14  &  \cellcolor{lightgray} 15   \\
\multirow{4}{*}{1}  
        & values &
        \cellcolor{orange} 0.64&
        \cellcolor{orange} 0.92 &
        \cellcolor{orange} 0.46 &
        \cellcolor{orange} 0.33 &
        \cellcolor{orange} 0.33& 
        \cellcolor{orange} 0.53 &
        \cellcolor{orange} 0.22 & 
        \cellcolor{orange} 0.82 &
         \cellcolor{orange} 0.521&
         \cellcolor{orange} 0.15& 
         \cellcolor{orange} 0.46  & 
        \cellcolor{orange} 0.46  &
        \cellcolor{orange} 0.54  & 
        \cellcolor{orange} 0.25  & 
        \cellcolor{orange} 0.54\\
\end{tabular}
\label{tab}
\end{table}
\end{document}

Thanks in advance!

5
  • Welcome. // Why don’t you just split it into two?
    – MS-SPO
    Apr 2 at 17:52
  • 1
    or stick \small or` \footnotesize` or whatever works. I would also remove the useless first column with values Apr 2 at 17:55
  • 2
    you have tagged this as longtable and loaded the package of that name but your example does not use longtable , in fact the table is not long at all it only has 1 row plus a heading row. Apr 2 at 18:00
  • 1
    @David Carlisle thank you, sorry i beginner in lytx, i want to fix this problem without split the table
    – alxander80
    Apr 2 at 18:03
  • 1
    @alxander80 I didn't suggest you split the table I suggested you use a smaller font so it fits, but longtable is about multi-page tables with many rows so unrelated to your problem Apr 2 at 18:13

1 Answer 1

2

The table has 17 columns, not 15.

Assuming you work with A4-size paper, 2.5cm margins, the Computer Modern Roman font face, and a main font size of 10pt, the following code will make the table (just) fit inside the text block.

I would further suggest you use \rowcolor directives instead of 15 adjacent \cellcolor directives in a single row.

enter image description here

\documentclass[10pt]{article}
\usepackage[a4paper,margin=2.5cm]{geometry}
\RequirePackage[l2tabu,orthodox]{nag}
\usepackage[table]{xcolor}
\usepackage{booktabs, multirow}

\begin{document}

\begin{table}
\setlength\tabcolsep{4.5pt} % default: 6pt

\centering
\caption{Comparison of customers.} \label{tab}

\smallskip
\begin{tabular}{@{} *{17}{c} }
\toprule
& & \multicolumn{15}{c}{customers}\\
\rowcolor{lightgray}
\cellcolor{white} 
& \cellcolor{white} & 
 1 &  2 &  3 &  4 &  5 & 6 &  7 &  8 &  9 & 10 & 11 & 12 & 13 & 14 & 15 \\
\rowcolor{orange}
\cellcolor{white}\multirow{4}{*}{1} % what's this about??
& \cellcolor{white} values &
 0.64 & 0.92 & 0.46 & 0.33 & 0.33 & 0.53 & 0.22 & 0.82 & 0.521& 0.15 & 0.46 & 0.46 & 0.54 & 0.25 & 0.54 \\
& & b\\
& & c\\
& & d\\
\bottomrule
\end{tabular}
\end{table}
\end{document}
1
  • 1
    thank you for your help
    – alxander80
    Apr 2 at 18:29

You must log in to answer this question.

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