Re: errore longtable in landscape

#61279
GKT
Partecipante
    Up
    0
    Down
    ::

    Ciao,
    stavo provando l’esempio di Pantieri sulle longtable, variandolo un po’ per avvicinarmi a quello che mi serve… e ottengo un errore.
    Il codice è:
    `
    \begin{landscape}
    \begin{longtable}{ccccccc}
    % didascalia ed etichetta
    \caption{Tabella comparativa.}
    \label{tab:tabella_comparativa_app} \\
    % intestazione iniziale
    \toprule
    \multicolumn{1}{c}\textbf{} & \multicolumn{1}{c}\textbf{A} & \multicolumn{1}{c}\textbf{B} & \multicolumn{1}{c}\textbf{C} & \multicolumn{1}{c}\textbf{D} & \multicolumn{1}{c}\textbf{E} & \multicolumn{1}{c}\textbf{F}\\
    \midrule
    \endfirsthead
    % intestazione normale
    \multicolumn{7}{l}{\footnotesize\itshape\tablename~\thetable: continua dalla pagina precedente} \\
    \toprule
    \multicolumn{1}{c}\textbf{} & \multicolumn{1}{c}\textbf{A} & \multicolumn{1}{c}\textbf{B} & \multicolumn{1}{c}\textbf{C} & \multicolumn{1}{c}\textbf{D} & \multicolumn{1}{c}\textbf{E} & \multicolumn{1}{c}\textbf{F}\\
    \midrule
    \endhead
    % piede normale
    \midrule
    \multicolumn{7}{r}{\footnotesize\itshape\tablename~\thetable: continua nella prossima pagina} \\
    \endfoot
    % piede finale
    \bottomrule
    \multicolumn{7}{r}{\footnotesize\itshape\tablename~\thetable: si conclude dalla pagina precedente} \\
    \endlastfoot
    % corpo tabella
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7\\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7\\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7 \\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7 \\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7 \\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7 \\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7 \\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7 \\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7 \\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7 \\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7 \\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7 \\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7 \\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7 \\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7 \\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7 \\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7 \\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7 \\
    \bottomrule
    \end{longtable}
    \end{landscape}
    `

    L’errore è:
    `
    Package longtable Error: Column widths have changed in table 2.1
    See the longtable package documentation for explanation.
    Type H for immediate help.

    l.901 \end{longtable}

    `

    Vorrei che il testo fosse centrato nelle celle.

    L’errore è dovuto al fatto che usi longtable insieme a multicol. I due pacchetti si possono usare, ma sono necessarie diverse compilazioni per convergere al risultato finale. Per allineare le celle della prima riga con il contenuto della tabella basta eliminare i \multicolumn: le celle sono già centrate, scrivere \multicolumn{1}{c}{} tante volte quante sono le colonne della tabella non ha molto senso.
    `\documentclass[a4paper]{article}

    \usepackage[T1]{fontenc}
    \usepackage[utf8]{inputenc}
    \usepackage[italian]{babel}
    \usepackage{booktabs}
    \usepackage{longtable}
    \usepackage{lscape}
    \usepackage{multicol}

    \begin{document}

    \begin{landscape}
    \begin{longtable}{ccccccc}
    % didascalia ed etichetta
    \caption{Tabella comparativa.}
    \label{tab:tabella_comparativa_app} \\
    % intestazione iniziale
    \toprule
    & \textbf{A} & \textbf{B} & \textbf{C} & \textbf{D} & \textbf{E} & \textbf{F}\\
    \midrule
    \endfirsthead
    % intestazione normale
    \multicolumn{7}{l}{\footnotesize\itshape\tablename~\thetable: continua dalla pagina precedente} \\
    \toprule
    & \textbf{A} & \textbf{B} & \textbf{C} & \textbf{D} & \textbf{E} & \textbf{F}\\
    \midrule
    \endhead
    % piede normale
    \midrule
    \multicolumn{7}{r}{\footnotesize\itshape\tablename~\thetable: continua nella prossima pagina} \\
    \endfoot
    % piede finale
    \bottomrule
    \multicolumn{7}{r}{\footnotesize\itshape\tablename~\thetable: si conclude dalla pagina precedente} \\
    \endlastfoot
    % corpo tabella
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7\\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7\\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7 \\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7 \\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7 \\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7 \\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7 \\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7 \\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7 \\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7 \\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7 \\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7 \\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7 \\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7 \\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7 \\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7 \\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7 \\
    \midrule
    \textbf{1} & 2 & 3 & 4 & 5 & 6 & 7 \\
    \bottomrule
    \end{longtable}
    \end{landscape}

    \end{document}`

    Lorenzo

    Go to top