Longtable 超出页面长度

Longtable 超出页面长度

情况:我使用 rmarkdown 和 xtable 迭代创建多个表格,并将它们输出到 Latex 中以创建 PDF。鉴于大多数表格都很长,我使用 Longtable 包。此外,我需要在每个页面的顶部插入两个对齐的图像。为此,我使用 Fancyhdr 和 Graphicx 将它们插入到页眉中。

并发症:创建的表格超出了页面长度。它们中断并继续在下一页,但有几行低于页面长度,因此未显示在 pdf 中。页脚也是一样。如果我不插入图像,就不会发生这种情况。如果没有页面顶部的图像,longtable 可以正常工作。此外,我注意到,与文档第一个表格的开始位置相比,拆分表格的后半部分(即 longtable 发送到下一页的表格块)在页面中的起始位置较低。

问题:我无法让 longtable 在页面长度的限制内分解表格。

来自 rmarkdown 的代码(我展示的是 xtable 代码):

---
title: "Reportes generales"
output: 
  pdf_document:
header-includes:
- \geometry{layout=a4paper}
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \usepackage{graphicx}
- \usepackage{longtable}
- \usepackage[spanish]{babel}
- \usepackage[]{hyperref}
- \hypersetup{
    bookmarksnumbered=true,     
    bookmarksopen=true,         
    bookmarksopenlevel=1,       
    colorlinks=true,
    linkcolor=blue,
    pdfstartview=Fit,           
    hyperindex=True
    hyperfigures=True
  }
- \fancyhead[R]{\includegraphics[height=5cm]{insight-top-right-2.png}}
- \fancyhead[L]{\raisebox{2.3\height}{\includegraphics[height=2.5cm]{logo.png}}}
- \renewcommand{\headrulewidth}{0pt}


---
\listoftables

\newpage

```{r, echo=FALSE, results='asis'}
datawrangling with r and calculations

### Here i am writing the code that will be inserted in the first line of the longtable, which states the use of endhead and endfoot, and footnotesize

addtorow<-list()
addtorow$pos<-list()
addtorow$pos[[1]]<-c(0)
addtorow$command<-c(paste("\\hline \n",
" \\endhead \n",
" \\hline \n",
" {\\footnotesize Continued on next page} \n",
" \\endfoot \n",
" \\endlastfoot \n",sep=""))

### Here is the tranformation of the dataframes to LaTex using xtable, note that tempmatrix is the matrix which i want to print in a pdf. This iterates for several dataframes, spawining several Longtables

xt <- capture.output(print.xtable(xtable(tempMatrix, align = "l|p{4cm}|r|r|r|r|r|"), include.rownames = FALSE, comment = FALSE, floating = FALSE, tabular.environment = "longtable",add.to.row=addtorow))
cat(xt, sep="\n")
```

最后,这是 latex 代码中的表格。这是几个表格中的一个,只有信息会发生变化,所有表格的格式都相同:

\begin{longtable}{|p{4cm}|r|r|r|r|r|}
  \hline
DEPARTAMENTO & Septiembre14 & Agosto15 & Septiembre15 & YTD14 & YTD15 \\ 
  \hline 
 \endhead 
 \hline 
 {\footnotesize Continued on next page} 
 \endfoot 
 \endlastfoot 
 \hline
BEBE & 3,136,143 & 3,908,120 & 3,970,474 & 167,346,367 & 253,682,083 \\ 
  BELLEZA DE LA PIEL & 4,056,518 & 4,383,270 & 5,657,551 & 268,024,922 & 376,562,389 \\ 
  CUIDADO CAPILAR & 3,598,571 & 4,485,420 & 4,860,410 & 231,520,280 & 360,023,595 \\ 
  CUIDADO ORAL & 1,466,654 & 2,077,587 & 2,149,403 & 106,409,239 & 159,647,444 \\ 
  CUIDADO PERSONAL & 5,993,436 & 7,920,352 & 8,268,905 & 431,726,918 & 615,126,409 \\ 
  LIMPIEZA &   283,785 &   254,940 &   306,183 &  26,618,969 &  28,738,917 \\ 
  NO COMESTIBLES &        NA &        NA &        NA &  14,600,825 &  23,053,981 \\ 
  OTC &         0 &         0 &    24,176 &           0 &     108,372 \\ 
  PRIMEROS AUXILIOS &   546,344 &   857,384 &   924,860 &  36,689,415 &  53,886,336 \\ 
   \hline
\hline
\end{longtable}

已经尝试过的可能的解决方案(单独或组合使用)均失败了:

- \geometry{top=0cm}
- \geometry{bottom=5cm}
- \geometry{headsep=0pt}
- \geometry{includehead}

我真的不知道如何解决这个问题,我越来越绝望了。

谢谢

更新:我发现当浮点数位于同一页时,longtable 在计算页面大小时可能会出现一些问题,这里 这可能是问题所在吗?也许标题中的图像会扰乱 longtable 计算页面长度的方式。他们建议对 longtable.sty 进行修改,但我找不到它。

更新2: 我可以获得 rmarkdown 用于生成 pdf 的 tex 文件,如下所建议:

\documentclass[]{article}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
\else % if luatex or xelatex
  \ifxetex
    \usepackage{mathspec}
    \usepackage{xltxtra,xunicode}
  \else
    \usepackage{fontspec}
  \fi
  \defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
  \newcommand{\euro}{€}
\fi
% use upquote if available, for straight quotes in verbatim     environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
% use microtype if available
\IfFileExists{microtype.sty}{%
\usepackage{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\usepackage[margin=1in]{geometry}
\ifxetex
  \usepackage[setpagesize=false, % page size defined by xetex
              unicode=false, % unicode breaks when used with xetex
              xetex]{hyperref}
\else
  \usepackage[unicode=true]{hyperref}
\fi
\hypersetup{breaklinks=true,
            bookmarks=true,
            pdfauthor={},
            pdftitle={Reportes generales},
            colorlinks=true,
            citecolor=blue,
            urlcolor=blue,
            linkcolor=magenta,
            pdfborder={0 0 0}}
\urlstyle{same}  % don't use monospace font for urls
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
\setlength{\emergencystretch}{3em}  % prevent overfull lines
\setcounter{secnumdepth}{0}

%%% Use protect on footnotes to avoid problems with footnotes in titles
\let\rmarkdownfootnote\footnote%
\def\footnote{\protect\rmarkdownfootnote}

%%% Change title format to be more compact
\usepackage{titling}

% Create subtitle command for use in maketitle
\newcommand{\subtitle}[1]{
  \posttitle{
    \begin{center}\large#1\end{center}
    }
}

\setlength{\droptitle}{-2em}
  \title{Reportes generales}
  \pretitle{\vspace{\droptitle}\centering\huge}
  \posttitle{\par}
  \author{}
  \preauthor{}\postauthor{}
  \date{}
  \predate{}\postdate{}

\geometry{layout=a4paper}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage[spanish]{babel}
\usepackage[]{hyperref}
\hypersetup{ bookmarksnumbered=true, bookmarksopen=true, bookmarksopenlevel=1, colorlinks=true, linkcolor=blue, pdfstartview=Fit, hyperindex=True hyperfigures=True }
\geometry{top=0.1cm}
\geometry{headsep=0pt}
\fancyhfoffset[L]{72pt}
\fancyhfoffset[R]{72pt}
\fancyhead[L]{\raisebox{0.7\height}{\includegraphics[height=1.0cm]{logo.png}}}
\fancyhead[R]{\includegraphics[height=2cm]{insight-top-right-3.png}}
\setlength{\LTpre}{1pt}
\setlength{\LTpost}{1pt}
\renewcommand{\headrulewidth}{0pt}


\begin{document}

\maketitle


\listoftables

\newpage

\begin{longtable}{|p{4cm}|r|r|r|r|r|}
  \hline
DEPARTAMENTO & Septiembre14 & Agosto15 & Septiembre15 & YTD14 & YTD15 \\ 
  \hline 
 \endhead 
 \hline 
 {\footnotesize Continued on next page} 
 \endfoot 
 \endlastfoot 
 \hline
BEBE & 3,136,143 & 3,908,120 & 3,970,474 & 167,346,367 & 253,682,083 \\ 
  BELLEZA DE LA PIEL & 4,056,518 & 4,383,270 & 5,657,551 & 268,024,922 & 376,562,389 \\ 
  CUIDADO CAPILAR & 3,598,571 & 4,485,420 & 4,860,410 & 231,520,280 & 360,023,595 \\ 
  CUIDADO ORAL & 1,466,654 & 2,077,587 & 2,149,403 & 106,409,239 & 159,647,444 \\ 
  CUIDADO PERSONAL & 5,993,436 & 7,920,352 & 8,268,905 & 431,726,918 & 615,126,409 \\ 
  LIMPIEZA &   283,785 &   254,940 &   306,183 &  26,618,969 &  28,738,917 \\ 
  NO COMESTIBLES &        NA &        NA &        NA &  14,600,825 &  23,053,981 \\ 
  OTC &         0 &         0 &    24,176 &           0 &     108,372 \\ 
  PRIMEROS AUXILIOS &   546,344 &   857,384 &   924,860 &  36,689,415     &  53,886,336 \\ 
   \hline
\hline
\end{longtable}\begin{longtable}{|p{4cm}|r|r|r|}
  \hline
DEPARTAMENTO & varMA & varMMAA & varYTD \\ 
  \hline
BEBE &  1.60 & 26.60 & 51.59 \\ 
  BELLEZA DE LA PIEL & 29.07 & 39.47 & 40.50 \\ 
  CUIDADO CAPILAR &  8.36 & 35.06 & 55.50 \\ 
  CUIDADO ORAL &  3.46 & 46.55 & 50.03 \\ 
  CUIDADO PERSONAL &  4.40 & 37.97 & 42.48 \\ 
  LIMPIEZA & 20.10 &  7.89 &  7.96 \\ 
  NO COMESTIBLES &    NA &    NA & 57.90 \\ 
  OTC &   Inf &   Inf &   Inf \\ 
  PRIMEROS AUXILIOS &  7.87 & 69.28 & 46.87 \\ 
   \hline
\hline
\end{longtable}

\begin{longtable}{|p{4cm}|r|r|r|r|r|}
\caption{Valores Absolutos-Categorias de  BELLEZA DE LA PIEL} \\ 
  \hline
CATEGORY & Septiembre14 & Agosto15 & Septiembre15 & YTD14 & YTD15 \\ 
  \hline 
 \endhead 
 \hline 
 {\footnotesize Continued on next page} 
 \endfoot 
 \endlastfoot 
 \hline
CREMAS FACIALES & 2,803,254 & 3,121,176 & 3,595,056 & 173,742,026 & 230,131,906 \\ 
  CREMAS P/CUERPO &   792,387 &   832,099 & 1,117,033 &  56,567,912 &  79,910,260 \\ 
  BRONCEADORES &   393,863 &   394,842 &   800,450 &  34,884,696 &  62,260,683 \\ 
  CREMAS REDUCTORAS &    67,014 &    35,153 &   145,012 &   2,830,287 &   4,259,539 \\ 
   \hline
\hline
\end{longtable}\begin{longtable}{|p{4cm}|r|r|r|}
\caption{Variaciones-Categorias de  BELLEZA DE LA PIEL} \\ 
  \hline
CATEGORY & varMA & varMMAA & varYTD \\ 
  \hline 
 \endhead 
 \hline 
 {\footnotesize Continued on next page} 
 \endfoot 
 \endlastfoot 
 \hline
CREMAS FACIALES &  15.18 &  28.25 & 32.46 \\ 
  CREMAS P/CUERPO &  34.24 &  40.97 & 41.26 \\ 
  BRONCEADORES & 102.73 & 103.23 & 78.48 \\ 
  CREMAS REDUCTORAS & 312.52 & 116.39 & 50.50 \\ 
   \hline
\hline
\end{longtable}\begin{longtable}{|p{4cm}|r|r|r|r|r|}
\caption{Valores Absolutos-Categorias de  CUIDADO PERSONAL} \\ 
  \hline
CATEGORY & Septiembre14 & Agosto15 & Septiembre15 & YTD14 & YTD15 \\ 
  \hline 
 \endhead 
 \hline 
 {\footnotesize Continued on next page} 
 \endfoot 
 \endlastfoot 
 \hline
DESODORANTES CORPORALES & 2,063,564 & 2,735,511 & 2,720,461 & 154,726,728 & 213,362,316 \\ 
  TINTURAS & 1,011,545 & 1,309,711 & 1,441,668 &  61,215,451 & 103,688,813 \\ 
  JABONES DE TOCADOR &   857,958 & 1,132,913 & 1,145,764 &  67,971,560 &  96,365,051 \\ 
  PROTECCION SANITARIA FEMENINA &   996,205 & 1,428,784 & 1,465,860 &  68,427,382 &  92,990,493 \\ 
  HOJAS Y SISTEMAS DE AFEITAR &   463,789 &   577,544 &   684,020 &  36,823,238 &  49,877,736 \\ 
  DESODORANTES PEDICOS &   275,378 &   302,852 &   349,053 &  18,068,231 &  26,220,716 \\ 
  PRODUCTOS DEPILATORIOS &   169,226 &   200,146 &   225,431 &  12,888,939 &  17,012,924 \\ 
  CREMAS Y ESPUMAS DE AFEITAR &    65,707 &    81,179 &   101,928 &   5,363,923 &   7,065,802 \\ 
  JABONES DE TOCADOR INFANTIL &    41,112 &    76,530 &    60,340 &   2,996,544 &   4,375,777 \\ 
  PROTECTORES MAMARIOS &    25,921 &    36,486 &    37,044 &   1,582,267 &   2,538,494 \\ 
  JABONES Y DETERGENTES LIQUIDOS &    23,031 &    38,695 &    37,336 &   1,662,655 &   1,628,287 \\ 
   \hline
\hline
\end{longtable}\begin{longtable}{|p{4cm}|r|r|r|}
\caption{Variaciones-Categorias de  CUIDADO PERSONAL} \\ 
  \hline
CATEGORY & varMA & varMMAA & varYTD \\ 
  \hline 
 \endhead 
 \hline 
 {\footnotesize Continued on next page} 
 \endfoot 
 \endlastfoot 
 \hline
DESODORANTES CORPORALES &  \textcolor{red}{-0.55} & 31.83 & 37.90 \\ 
  TINTURAS &  10.08 & 42.52 & 69.38 \\ 
  JABONES DE TOCADOR &   1.13 & 33.55 & 41.77 \\ 
  PROTECCION SANITARIA FEMENINA &   2.59 & 47.14 & 35.90 \\ 
  HOJAS Y SISTEMAS DE AFEITAR &  18.44 & 47.49 & 35.45 \\ 
  DESODORANTES PEDICOS &  15.26 & 26.75 & 45.12 \\ 
  PRODUCTOS DEPILATORIOS &  12.63 & 33.21 & 32.00 \\ 
  CREMAS Y ESPUMAS DE AFEITAR &  25.56 & 55.13 & 31.73 \\ 
  JABONES DE TOCADOR INFANTIL & \textcolor{red}{-21.16} & 46.77 & 46.03 \\ 
  PROTECTORES MAMARIOS &   1.53 & 42.91 & 60.43 \\ 
  JABONES Y DETERGENTES LIQUIDOS &  \textcolor{red}{-3.51} & 62.11 & \textcolor{red}{-2.07} \\ 
   \hline
\hline
\end{longtable}\begin{longtable}{|p{4cm}|r|r|r|r|r|}
\caption{Valores Absolutos-Categorias de  BEBE} \\ 
  \hline
CATEGORY & Septiembre14 & Agosto15 & Septiembre15 & YTD14 & YTD15 \\ 
  \hline 
 \endhead 
 \hline 
 {\footnotesize Continued on next page} 
 \endfoot 
 \endlastfoot 
 \hline
PA-ALES DESCARTABLES P/BEBES & 2,122,630 & 2,780,865 & 3,079,733 & 113,368,516 & 188,264,578 \\ 
  TOALLAS HUMEDAS &   769,750 &   624,151 &   588,020 &  35,922,853 &  42,581,782 \\ 
  COLONIAS &   136,517 &   394,210 &   190,754 &  11,578,566 &  15,923,990 \\ 
  HISOPOS &    86,054 &    89,065 &    87,441 &   5,032,377 &   5,123,320 \\ 
  ACEITES INFANTILES &    21,191 &    19,603 &    22,353 &   1,439,380 &   1,749,265 \\ 
  ALIMENTOS PARA BEBE &         0 &       226 &     2,172 &       4,674 &      39,148 \\ 
   \hline
\hline
\end{longtable}\begin{longtable}{|p{4cm}|r|r|r|}
\caption{Variaciones-Categorias de  BEBE} \\ 
  \hline
CATEGORY & varMA & varMMAA & varYTD \\ 
  \hline 
 \endhead 
 \hline 
 {\footnotesize Continued on next page} 
 \endfoot 
 \endlastfoot 
 \hline
PA-ALES DESCARTABLES P/BEBES &  10.75 &  45.09 &  66.06 \\ 
  TOALLAS HUMEDAS &  \textcolor{red}{-5.79} & \textcolor{red}{-23.61} &  18.54 \\ 
  COLONIAS & \textcolor{red}{-51.61} &  39.73 &  37.53 \\ 
  HISOPOS &  \textcolor{red}{-1.82} &   1.61 &   1.81 \\ 
  ACEITES INFANTILES &  14.03 &   5.48 &  21.53 \\ 
  ALIMENTOS PARA BEBE & 861.38 &    Inf & 737.56 \\ 
   \hline
\hline
\end{longtable}\begin{longtable}{|p{4cm}|r|r|r|r|r|}
\caption{Valores Absolutos-Categorias de  CUIDADO CAPILAR} \\ 
  \hline
CATEGORY & Septiembre14 & Agosto15 & Septiembre15 & YTD14 & YTD15 \\ 
  \hline 
 \endhead 
 \hline 
 {\footnotesize Continued on next page} 
 \endfoot 
 \endlastfoot 
 \hline
SHAMPOO & 1,773,948 & 2,247,855 & 2,356,224 & 121,419,925 & 175,429,757 \\ 
  TRATAMIENTOS POST LAVADO CAPIL & 1,657,579 & 2,035,991 & 2,289,201 &  97,430,656 & 168,517,341 \\ 
  FIJADORES Y BRILLANTINAS &   167,044 &   201,573 &   214,985 &  12,669,698 &  16,076,497 \\ 
   \hline
\hline
\end{longtable}\begin{longtable}{|p{4cm}|r|r|r|}
\caption{Variaciones-Categorias de  CUIDADO CAPILAR} \\ 
  \hline
CATEGORY & varMA & varMMAA & varYTD \\ 
  \hline 
 \endhead 
 \hline 
 {\footnotesize Continued on next page} 
 \endfoot 
 \endlastfoot 
 \hline
SHAMPOO &  4.82 & 32.82 & 44.48 \\ 
  TRATAMIENTOS POST LAVADO CAPIL & 12.44 & 38.11 & 72.96 \\ 
  FIJADORES Y BRILLANTINAS &  6.65 & 28.70 & 26.89 \\ 
   \hline
\hline
\end{longtable}\begin{longtable}{|p{4cm}|r|r|r|r|r|}
\caption{Valores Absolutos-Categorias de  CUIDADO ORAL} \\ 
  \hline
CATEGORY & Septiembre14 & Agosto15 & Septiembre15 & YTD14 & YTD15 \\ 
  \hline 
 \endhead 
 \hline 
 {\footnotesize Continued on next page} 
 \endfoot 
 \endlastfoot 
 \hline
CREMAS DENTALES & 806,334 & 1,119,215 & 1,153,052 & 55,999,726 & 86,000,224 \\ 
  CEPILLOS DENTALES & 437,088 &   633,310 &   652,061 & 32,699,481 & 48,952,653 \\ 
  ENJUAGUE BUCAL & 196,601 &   286,640 &   307,849 & 15,756,802 & 21,779,345 \\ 
  HILOS DENTALES &  26,631 &    38,422 &    36,441 &  1,953,230 &  2,915,221 \\ 
   \hline
\hline
\end{longtable}\begin{longtable}{|p{4cm}|r|r|r|}
\caption{Variaciones-Categorias de  CUIDADO ORAL} \\ 
  \hline
CATEGORY & varMA & varMMAA & varYTD \\ 
  \hline 
 \endhead 
 \hline 
 {\footnotesize Continued on next page} 
 \endfoot 
 \endlastfoot 
 \hline
CREMAS DENTALES &  3.02 & 43.00 & 53.57 \\ 
  CEPILLOS DENTALES &  2.96 & 49.18 & 49.70 \\ 
  ENJUAGUE BUCAL &  7.40 & 56.59 & 38.22 \\ 
  HILOS DENTALES & \textcolor{red}{-5.16} & 36.83 & 49.25 \\ 
   \hline
\hline
\end{longtable}\begin{longtable}{|p{4cm}|r|r|r|r|r|}
\caption{Valores Absolutos-Categorias de  ALMACEN} \\ 
  \hline
CATEGORY & Septiembre14 & Agosto15 & Septiembre15 & YTD14 & YTD15 \\ 
  \hline 
 \endhead 
 \hline 
 {\footnotesize Continued on next page} 
 \endfoot 
 \endlastfoot 
 \hline
LECHES MATERNIZADAS & 690,342 & 1,081,196 & 1,117,606 & 50,599,593 & 78,413,709 \\ 
  LECHES FLUIDAS INFANTILES & 305,284 &   406,650 &   356,478 & 17,418,316 & 32,561,526 \\ 
  EDULCORANTES &  81,847 &   108,511 &   108,040 &  5,062,420 &  8,405,514 \\ 
  LECHES EN POLVO ENTERAS Y DESC &  50,583 &    65,481 &    71,004 &  4,146,129 &  5,330,949 \\ 
  PASTILLAS &       0 &       200 &       150 &          0 &      9,000 \\ 
  POSTRES PREPARADOS &       0 &     5,398 &         0 &          0 &      5,398 \\ 
  AZUCAR &      NA &        NA &        NA &          0 &      1,546 \\ 
   \hline
    \hline
\end{longtable}\begin{longtable}{|p{4cm}|r|r|r|}
\caption{Variaciones-Categorias de  ALMACEN} \\ 
  \hline
CATEGORY & varMA & varMMAA & varYTD \\ 
  \hline 
 \endhead 
 \hline 
 {\footnotesize Continued on next page} 
 \endfoot 
 \endlastfoot 
 \hline
LECHES MATERNIZADAS &    3.37 & 61.89 & 54.97 \\ 
  LECHES FLUIDAS INFANTILES &  \textcolor{red}{-12.34} & 16.77 & 86.94 \\ 
  EDULCORANTES &   \textcolor{red}{-0.43} & 32.00 & 66.04 \\ 
  LECHES EN POLVO ENTERAS Y DESC &    8.44 & 40.37 & 28.58 \\ 
  PASTILLAS &  \textcolor{red}{-25.00} &   Inf &   Inf \\ 
  POSTRES PREPARADOS & \textcolor{red}{-100}.00 &   NaN &   Inf \\ 
  AZUCAR &      NA &    NA &   Inf \\ 
   \hline
\hline
\end{longtable}\begin{longtable}{|p{4cm}|r|r|r|r|r|}
\caption{Valores Absolutos-Categorias de  PRIMEROS AUXILIOS} \\ 
  \hline
CATEGORY & Septiembre14 & Agosto15 & Septiembre15 & YTD14 & YTD15 \\ 
  \hline 
 \endhead 
 \hline 
 {\footnotesize Continued on next page} 
 \endfoot 
 \endlastfoot 
 \hline
PA-ALES DESCARTABLES P/ADULTO & 291,871 & 513,709 & 509,992 & 19,938,505 & 34,598,008 \\ 
  ALGODON & 109,650 & 128,338 & 129,161 &  7,944,323 &  9,423,255 \\ 
  PA-UELOS DESCARTABLES & 144,823 & 200,002 & 201,561 &  8,806,587 &  9,171,453 \\ 
  APOSITOS ADHESIVOS &       0 &  15,335 &  84,147 &          0 &    693,620 \\ 
   \hline
\hline
\end{longtable}\begin{longtable}{|p{4cm}|r|r|r|}
\caption{Variaciones-Categorias de  PRIMEROS AUXILIOS} \\ 
  \hline
CATEGORY & varMA & varMMAA & varYTD \\ 
  \hline 
 \endhead 
 \hline 
 {\footnotesize Continued on next page} 
 \endfoot 
 \endlastfoot 
 \hline
PA-ALES DESCARTABLES P/ADULTO &  \textcolor{red}{-0.72} & 74.73 & 73.52 \\ 
  ALGODON &   0.64 & 17.79 & 18.62 \\ 
  PA-UELOS DESCARTABLES &   0.78 & 39.18 &  4.14 \\ 
  APOSITOS ADHESIVOS & 448.73 &   Inf &   Inf \\ 
   \hline
\hline
\end{longtable}\begin{longtable}{|p{4cm}|r|r|r|r|r|}
\caption{Valores Absolutos-Categorias de  NO COMESTIBLES} \\ 
  \hline
CATEGORY & Septiembre14 & Agosto15 & Septiembre15 & YTD14 & YTD15 \\ 
  \hline 
 \endhead 
 \hline 
 {\footnotesize Continued on next page} 
 \endfoot 
 \endlastfoot 
 \hline
PERSONAL CARE & 202,776 & 342,134 & 283,591 & 12,525,189 & 19,873,598 \\ 
  PILAS Y BATERIAS &  26,811 &  51,955 &  34,284 &  2,073,855 &  3,170,379 \\ 
  LAMPARAS ELECTRICAS &      63 &      77 &     341 &      1,781 &     10,004 \\ 
   \hline
\hline
\end{longtable}\begin{longtable}{|p{4cm}|r|r|r|}
\caption{Variaciones-Categorias de  NO COMESTIBLES} \\ 
  \hline
CATEGORY & varMA & varMMAA & varYTD \\ 
  \hline 
 \endhead 
 \hline 
 {\footnotesize Continued on next page} 
 \endfoot 
 \endlastfoot 
 \hline
PERSONAL CARE & \textcolor{red}{-17.11} &  39.85 &  58.67 \\ 
  PILAS Y BATERIAS & \textcolor{red}{-34.01} &  27.87 &  52.87 \\ 
  LAMPARAS ELECTRICAS & 342.86 & 443.43 & 461.72 \\ 
   \hline
\hline
\end{longtable}\begin{longtable}{|p{4cm}|r|r|r|r|r|}
\caption{Valores Absolutos-Categorias de  LIMPIEZA} \\ 
  \hline
CATEGORY & Septiembre14 & Agosto15 & Septiembre15 & YTD14 & YTD15 \\ 
  \hline 
 \endhead 
 \hline 
 {\footnotesize Continued on next page} 
 \endfoot 
 \endlastfoot 
 \hline
INSECTICIDAS TOTAL & 46,733 & 25,317 & 70,275 & 8,405,776 & 10,842,602 \\ 
  DESODORIZ. AMBIENTALES & 47,641 & 41,725 & 36,204 & 4,066,838 &  3,143,191 \\ 
  PAPEL HIGIENICO & 41,524 & 34,182 & 43,812 & 3,376,920 &  2,879,686 \\ 
  DETERGENTES LIQUIDOS & 16,513 & 19,675 & 19,315 & 1,252,239 &  1,586,210 \\ 
  ROLLOS DE PAPEL P/COCINA & 23,198 & 17,788 & 19,031 & 1,604,990 &  1,395,317 \\ 
  JABONES Y DETERGENTES EN POLVO & 14,511 & 16,699 & 16,702 &   961,115 &  1,284,704 \\ 
  DESOD.PARA INODOROS & 15,230 & 12,561 & 12,982 & 1,142,564 &  1,092,752 \\ 
  DILUIBLES & 11,072 & 12,906 & 13,469 &   797,580 &  1,052,769 \\ 
  GUANTES DE LATEX & 13,745 & 12,303 & 11,359 & 1,017,632 &    834,462 \\ 
  LIMPIADORES Y DESENGRASANTES N &  6,893 & 10,171 &  7,555 &   532,131 &    645,236 \\ 
  SUAVIZANTES &  5,725 &  9,575 &  7,670 &   572,759 &    640,669 \\ 
  LAVANDINAS &  5,694 &  7,353 &  7,360 &   464,882 &    602,875 \\ 
  CERAS PARA PISOS &  4,613 &  4,501 &  4,444 &   364,140 &    382,369 \\ 
  LUSTRAMUEBLES &  7,141 &  3,614 &  5,788 &   492,708 &    365,615 \\ 
  VIDRIOS Y MULTIUSO &  3,271 &  3,911 &  3,768 &   271,616 &    302,953 \\ 
  PRODUCTOS P/EL LAVADO FINO &  2,904 &  2,926 &  3,572 &   117,832 &    289,474 \\ 
  JABONES Y DETERGENTES EN PANES &  2,891 &  3,380 &  3,656 &   193,319 &    283,411 \\ 
  FIBRAS LIMPIADORAS &  3,406 &  3,342 &  3,295 &   231,409 &    233,841 \\ 
  LANAS/ESPONJAS Y TRAPOS METALI &  2,230 &  2,715 &  2,814 &   145,893 &    210,034 \\ 
  COCINA Y ANTIGRASA &  1,973 &  3,175 &  4,267 &   121,913 &    205,040 \\ 
  QUITAMANCHAS &  2,121 &  2,416 &  2,449 &   140,739 &    135,342 \\ 
  PA-OS SINTETICOS &  1,826 &  2,861 &  2,762 &   145,271 &    128,108 \\ 
  APRESTOS &    947 &    873 &  1,114 &    67,115 &     95,356 \\ 
  INODOROS &    874 &    798 &  1,216 &     9,834 &     51,266 \\ 
  SERVILLETAS DE PAPEL &    856 &     33 &    884 &   105,955 &     45,377 \\ 
  DESTAPACA-ERIAS &    252 &    140 &    420 &    15,798 &     10,260 \\ 
   \hline
\hline
\end{longtable}\begin{longtable}{|p{4cm}|r|r|r|}
\caption{Variaciones-Categorias de  LIMPIEZA} \\ 
  \hline
CATEGORY & varMA & varMMAA & varYTD \\ 
  \hline 
 \endhead 
 \hline 
 {\footnotesize Continued on next page} 
 \endfoot 
 \endlastfoot 
 \hline
INSECTICIDAS TOTAL &   177.58 &  50.38 &  28.99 \\ 
  DESODORIZ. AMBIENTALES &   \textcolor{red}{-13.23} & \textcolor{red}{-24.01} & \textcolor{red}{-22.71} \\ 
  PAPEL HIGIENICO &    28.18 &   5.51 & \textcolor{red}{-14.72} \\ 
  DETERGENTES LIQUIDOS &    \textcolor{red}{-1.83} &  16.97 &  26.67 \\ 
  ROLLOS DE PAPEL P/COCINA &     6.99 & \textcolor{red}{-17.96} & \textcolor{red}{-13.06} \\ 
  JABONES Y DETERGENTES EN POLVO &     0.02 &  15.10 &  33.67 \\ 
  DESOD.PARA INODOROS &     3.35 & \textcolor{red}{-14.76} &  \textcolor{red}{-4.36} \\ 
  DILUIBLES &     4.36 &  21.65 &  32.00 \\ 
  GUANTES DE LATEX &    \textcolor{red}{-7.67} & \textcolor{red}{-17.36} & \textcolor{red}{-18.00} \\ 
  LIMPIADORES Y DESENGRASANTES N &   \textcolor{red}{-25.72} &   9.61 &  21.26 \\ 
  SUAVIZANTES &   \textcolor{red}{-19.90} &  33.97 &  11.86 \\ 
  LAVANDINAS &     0.09 &  29.27 &  29.68 \\ 
  CERAS PARA PISOS &    \textcolor{red}{-1.27} &  \textcolor{red}{-3.67} &   5.01 \\ 
  LUSTRAMUEBLES &    60.15 & \textcolor{red}{-18.95} & \textcolor{red}{-25.79} \\ 
  VIDRIOS Y MULTIUSO &    \textcolor{red}{-3.66} &  15.19 &  11.54 \\ 
  PRODUCTOS P/EL LAVADO FINO &    22.07 &  23.01 & 145.67 \\ 
  JABONES Y DETERGENTES EN PANES &     8.17 &  26.44 &  46.60 \\ 
  FIBRAS LIMPIADORAS &    \textcolor{red}{-1.40} &  \textcolor{red}{-3.26} &   1.05 \\ 
  LANAS/ESPONJAS Y TRAPOS METALI &     3.66 &  26.18 &  43.96 \\ 
  COCINA Y ANTIGRASA &    34.39 & 116.24 &  68.19 \\ 
  QUITAMANCHAS &     1.37 &  15.50 &  \textcolor{red}{-3.84} \\ 
  PA-OS SINTETICOS &    \textcolor{red}{-3.46} &  51.30 & \textcolor{red}{-11.82} \\ 
  APRESTOS &    27.48 &  17.56 &  42.08 \\ 
  INODOROS &    52.38 &  39.05 & 421.32 \\ 
  SERVILLETAS DE PAPEL & 2,578.79 &   3.22 & \textcolor{red}{-57.17} \\ 
  DESTAPACA-ERIAS &   200.00 &  66.69 & \textcolor{red}{-35.06} \\ 
   \hline
\hline
\end{longtable}\begin{longtable}{|p{4cm}|r|r|r|r|r|}
\caption{Valores Absolutos-Categorias de  OTC} \\ 
  \hline
CATEGORY & Septiembre14 & Agosto15 & Septiembre15 & YTD14 & YTD15 \\ 
  \hline 
 \endhead 
 \hline 
 {\footnotesize Continued on next page} 
\endfoot 
 \endlastfoot 
 \hline
ANTISEPTICOS & 0 & 0 & 24,176 & 0 & 108,372 \\ 
   \hline
\hline
\end{longtable}\begin{longtable}{|p{4cm}|r|r|r|}
\caption{Variaciones-Categorias de  OTC} \\ 
  \hline
CATEGORY & varMA & varMMAA & varYTD \\ 
  \hline 
 \endhead 
 \hline 
 {\footnotesize Continued on next page} 
 \endfoot 
 \endlastfoot 
 \hline
ANTISEPTICOS & Inf & Inf & Inf \\ 
   \hline
\hline
\end{longtable}

\end{document}

答案1

就像我说的,读取控制台输出。它会准确地告诉你问题是什么以及如何解决。

Package Fancyhdr Warning: \headheight is too small (12.0pt): 
 Make it at least 60.50554pt.
 We now make it that large for the rest of the document.
 This may cause the page layout to be inconsistent, however.

设置headheight=61ptingeometry的选项可以解决问题。但请注意,整个序言中散布着不一致且奇怪的布局选项,这很容易造成麻烦和混乱。

如果结合起来,你最终会得到类似这样的结果

\usepackage[margin=1in,headheight=61pt,layout=a4paper,top=0.1cm,headsep=0pt]{geometry}

因此,您要将所有边距设置为 1 英寸,然后将顶部边距重置为 1 毫米。您还将布局设置为 A4,将纸张尺寸设置为美国信纸。虽然您确实可能需要这种配置,但似乎不太可能。

例如,添加showframe,我们得到这个

丑陋的输出

请注意长桌是它会帮你拆分表格。如果你要自己拆分表格,那么你最好使用tabulars。不断启动和停止longtable环境会导致格式和间距不一致。

相关内容