[Tex/LaTex] adjustbox missing endgroup inserted. How to fit longtable to page width

adjustboxlandscapelongtablepgfplotstables

I am working on my thesis. The appendix contains 2 large tables that span multiple pages. These tables are wider than the page height in landscape mode. When using the \begin{adjustbox}{width = 1\textheight} it produces multiple errors:

  1. Missing \endgroup inserted
  2. Missing } inserted
  3. Package graphixs Error: Division by 0
  4. Argument of \LT@max has an extra }
  5. Paragraph ended before \LT@max

Among others. The document compiles normally if the \begin{adjustbox} / \end{adjustbox} is commented out. The .csv files are found in my github repo for my thesis. The code used:

\documentclass[12pt]{book}

\begin{document}

[…]

\begin{landscape}
\begin{center}
\begin{adjustbox}{width=1\textheight}
\pgfplotstabletypeset[
    string type, 
    col sep=comma,
    outfile=prueba.tex,
    begin table=\begin{longtable},
    end table=\end{longtable},
    every head row/.append style={after row={
        \hline
        \endfirsthead
        \multicolumn{13}{c}{{\bfseries  -- continua de la pagina anterior}}\\\hline
        Accesion& Fecha& Pais& Departamento& Provincia& Distrito& Localidad& Altitud (m)& Latitud& Longitud& Fuente& Status& Mat. Viv. Col.\\\hline
        \endhead},
    before row={\hline}}        
    ]{apendice/pasaporte.csv}
\end{adjustbox}
\end{center}
\end{landscape}

[…]

\end{document}

The packages loaded are:

\usepackage{subcaption}
\usepackage[dvipsnames]{xcolor}
\definecolor{norte}{HTML}{1B9E77}
\definecolor{centro}{HTML}{E7298A}
\definecolor{sur}{HTML}{666666}
\usepackage[round, comma, numbers]{natbib}
\usepackage{url}
\usepackage[english, spanish, es-tabla]{babel}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{titlesec}
\usepackage{graphicx}
\graphicspath{{imagenes/}}
\DeclareGraphicsExtensions{.jpg, .jpeg}
\usepackage{titling}
\pagestyle{plain}
\usepackage{pgf}    
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.13}
\usepackage{booktabs}
\usepackage{array}
\usepackage{rotating}
\usepackage{siunitx}
\sisetup{
input-symbols = {()},
group-digits  = false,
explicit-sign
}
\usepackage{xfrac}
\usepackage[version=4]{mhchem}
\usepackage{adjustbox}
\usepackage{afterpage,lscape}
\usepackage{geometry}
\usepackage{pifont}
\usepackage{caption}
\usepackage{float}
\usepackage{longtable}
\usepackage[section]{placeins}

Data:

\begin {longtable}{ccccccccccccccc}%
\hline Accesion&KAAT007&QCA14&QGAA001&QGA17&KGA16&QAAT071&QAAT084&QAAT081&KGA20&KCAA011&QAAT050&QGA028&QAAT012&Provincia\\\hline \endfirsthead \multicolumn {15}{c}{{\bfseries -- continua de la pagina anterior}}\\\hline Accesión& KAAT007& QCA14& QGAA001& QGA17& KGA16& QAAT071& QAAT084& QAAT081& KGA20& KCAA011& QAAT050& QGA028& QAAT012& Provincia\\\hline \endhead %
 1&NA&NA&NA&NA&NA&NA&NA&NA&NA&NA&NA&NA&NA&SUCRE\\%
      2&225/225&205/205&NA&198/202&198/198&NA&176/176&206/206&214/224&NA&250/250&194/194&204/204&SUCRE\\%
3&225/291&NA&NA&198/198&198/198&164/164&170/170&206/206&212/220&235/235&247/247&222/222&204/204&SUCRE\\%
 5&315/315&203/207&NA&NA&NA&NA&170/170&206/206&NA&NA&NA&220/220&198/198&SUCRE\\%
6&255/255&203/207&143/206&NA&200/200&179/179&170/170&206/206&190/196&NA&223/223&220/220&198/198&SUCRE\\%
7&261/276&205/207&200/206&194/200&194/194&179/179&176/176&206/209&206/214&247/247&217/220&196/196&222/222&SUCRE\\%
8&NA&NA&206/236&194/202&200/200&NA&164/164&206/206&NA&NA&NA&202/214&189/231&SUCRE\\%
9&294/294&NA&NA&NA&196/198&179/179&167/167&206/206&206/214&NA&217/241&198/198&201/201&SUCRE\\%
10&342/342&207/207&245/266&196/196&NA&NA&173/173&206/206&190/196&NA&223/223&224/224&198/198&HUAMANGA\\%
13&225/225&205/209&NA&NA&196/200&164/164&179/194&206/209&214/222&235/235&247/247&224/224&207/207&HUAMANGA\\%
14&222/222&NA&NA&196/200&196/196&164/164&179/179&209/209&216/224&235/235&247/247&224/224&207/207&HUAMANGA\\%
15&NA&205/207&NA&180/196&200/200&173/173&173/173&206/206&190/194&241/241&220/220&224/224&225/225&HUAMANGA\\%
 16&228/228&207/211&209/209&182/200&200/200&164/164&164/164&206/206&214/222&235/235&247/247&224/224&207/207&HUANCASANCOS\\%
 \end {longtable}%

Best Answer

It is easier for people to help if you post a complete document, as below, that shows the problem rather than disconnected fragments, but anyway, it fits on the page if you reduce the font size, and steal a bit of the bottom margin.

enter image description here \documentclass[12pt]{book} \usepackage{lscape,longtable} \begin{document}

\begin{landscape}
\scriptsize
\setlength\tabcolsep{2pt}
\setlength\LTleft{-70pt}
\begin {longtable}{ccccccccccccccc}%
\hline Accesion&KAAT007&QCA14&QGAA001&QGA17&KGA16&QAAT071&QAAT084&QAAT081&KGA20&KCAA011&QAAT050&QGA028&QAAT012&Provincia\\\hline \endfirsthead \multicolumn {15}{c}{{\bfseries -- continua de la pagina anterior}}\\\hline Accesión& KAAT007& QCA14& QGAA001& QGA17& KGA16& QAAT071& QAAT084& QAAT081& KGA20& KCAA011& QAAT050& QGA028& QAAT012& Provincia\\\hline \endhead %
 1&NA&NA&NA&NA&NA&NA&NA&NA&NA&NA&NA&NA&NA&SUCRE\\%
      2&225/225&205/205&NA&198/202&198/198&NA&176/176&206/206&214/224&NA&250/250&194/194&204/204&SUCRE\\%
3&225/291&NA&NA&198/198&198/198&164/164&170/170&206/206&212/220&235/235&247/247&222/222&204/204&SUCRE\\%
 5&315/315&203/207&NA&NA&NA&NA&170/170&206/206&NA&NA&NA&220/220&198/198&SUCRE\\%
6&255/255&203/207&143/206&NA&200/200&179/179&170/170&206/206&190/196&NA&223/223&220/220&198/198&SUCRE\\%
7&261/276&205/207&200/206&194/200&194/194&179/179&176/176&206/209&206/214&247/247&217/220&196/196&222/222&SUCRE\\%
8&NA&NA&206/236&194/202&200/200&NA&164/164&206/206&NA&NA&NA&202/214&189/231&SUCRE\\%
9&294/294&NA&NA&NA&196/198&179/179&167/167&206/206&206/214&NA&217/241&198/198&201/201&SUCRE\\%
10&342/342&207/207&245/266&196/196&NA&NA&173/173&206/206&190/196&NA&223/223&224/224&198/198&HUAMANGA\\%
13&225/225&205/209&NA&NA&196/200&164/164&179/194&206/209&214/222&235/235&247/247&224/224&207/207&HUAMANGA\\%
14&222/222&NA&NA&196/200&196/196&164/164&179/179&209/209&216/224&235/235&247/247&224/224&207/207&HUAMANGA\\%
15&NA&205/207&NA&180/196&200/200&173/173&173/173&206/206&190/194&241/241&220/220&224/224&225/225&HUAMANGA\\%
 16&228/228&207/211&209/209&182/200&200/200&164/164&164/164&206/206&214/222&235/235&247/247&224/224&207/207&HUANCASANCOS\\%
 \end {longtable}
 \end{landscape}
 \end{document}