将很长的表格拆分到一页,然后继续到下一页第 2 部分

将很长的表格拆分到一页,然后继续到下一页第 2 部分

这个问题是建立在解决方案在这里找到。该帖子中给出的解决方案,在下一页开始表格。如何在同一页上开始表格\section\chapter开始?

另外,从下面给出的代码来看,虽然数据完整,但在新页面上打印了一个没有数据的标题。如何解决这个问题?

以下是 MWE:

 \documentclass{book}
\usepackage[top=3cm,bottom=3cm,left=3.2cm,right=3.2cm,headsep=10pt,a4paper]{geometry}
\usepackage{pgfplotstable, booktabs}
\pgfplotsset{compat=newest}
                \usepackage{supertabular}
                \usepackage{amsmath}
                \usepackage{array}
                \usepackage{fancyhdr}
                \pagestyle{fancy}
                \fancyhf{}

                \usepackage{filecontents}
                \begin{filecontents}{verylong.txt}
                c   G(c)GTOT    GhatGTOT    MODELPERFORM
                0.10106383  1   0.971896956 0.971896956
                0.095744681 1   0.974238876 0.974238876
                0.090425532 1   0.974238876 0.974238876
                0.085106383 1   0.974238876 0.974238876
                0.079787234 1   0.974238876 0.974238876
                0.074468085 1   0.976580796 0.976580796
                0.069148936 1   0.978922717 0.978922717
                0.063829787 1   0.978922717 0.978922717
                0.058510638 1   0.981264637 0.981264637
                0.053191489 1   0.981264637 0.981264637
                0.04787234  1   0.981264637 0.981264637
                0.042553191 1   0.990632319 0.990632319
                0.037234043 1   0.990632319 0.990632319
                0.031914894 1   0.992974239 0.992974239
                0.026595745 1   0.992974239 0.992974239
                0.021276596 1   0.992974239 0.992974239
                0.015957447 1   1   1
                0.010638298 1   1   1
                0.005319149 1   1   1
                0   1   1   1
                0.893617021 0.629976581 0.585480094 0.92936803
                0.888297872 0.644028103 0.592505855 0.92
                0.882978723 0.658079625 0.613583138 0.932384342
                0.877659574 0.672131148 0.62295082  0.926829268
                0.872340426 0.683840749 0.634660422 0.928082192
                0.867021277 0.695550351 0.641686183 0.922558923
                0.861702128 0.707259953 0.641686183 0.907284768
                0.856382979 0.718969555 0.644028103 0.895765472
                0.85106383  0.730679157 0.655737705 0.897435897
                0.845744681 0.742388759 0.669789227 0.902208202
                0.840425532 0.754098361 0.669789227 0.888198758
                0.835106383 0.763466042 0.669789227 0.877300613
                0.829787234 0.772833724 0.683840749 0.884848485
                0.824468085 0.782201405 0.68852459  0.880239521
                0.819148936 0.791569087 0.700234192 0.884615385
                0.813829787 0.800936768 0.711943794 0.888888889
                0.808510638 0.81030445  0.716627635 0.884393064
                0.803191489 0.817330211 0.723653396 0.885386819
                0.10106383  1   0.971896956 0.971896956
                0.095744681 1   0.974238876 0.974238876
                0.090425532 1   0.974238876 0.974238876
                0.085106383 1   0.974238876 0.974238876
                0.079787234 1   0.974238876 0.974238876
                0.074468085 1   0.976580796 0.976580796
                0.069148936 1   0.978922717 0.978922717
                0.063829787 1   0.978922717 0.978922717
                0.058510638 1   0.981264637 0.981264637
                0.053191489 1   0.981264637 0.981264637
                0.04787234  1   0.981264637 0.981264637
                0.042553191 1   0.990632319 0.990632319
                0.037234043 1   0.990632319 0.990632319
                0.031914894 1   0.992974239 0.992974239
                0.026595745 1   0.992974239 0.992974239
                0.021276596 1   0.992974239 0.992974239
                0.015957447 1   1   1
                0.010638298 1   1   1
                0.005319149 1   1   1
                0   1   1   1
                0.638297872 0.948477752 0.880562061 0.928395062
                0.632978723 0.950819672 0.880562061 0.926108374
                0.627659574 0.953161593 0.880562061 0.923832924
                0.622340426 0.955503513 0.880562061 0.921568627
                0.617021277 0.957845433 0.880562061 0.919315403
                0.611702128 0.960187354 0.880562061 0.917073171
                0.606382979 0.962529274 0.880562061 0.914841849
                0.10106383  1   0.971896956 0.971896956
                0.095744681 1   0.974238876 0.974238876
                0.090425532 1   0.974238876 0.974238876
                0.085106383 1   0.974238876 0.974238876
                0.079787234 1   0.974238876 0.974238876
                0.074468085 1   0.976580796 0.976580796
                0.069148936 1   0.978922717 0.978922717
                0.063829787 1   0.978922717 0.978922717
                0.058510638 1   0.981264637 0.981264637
                0.053191489 1   0.981264637 0.981264637
                0.04787234  1   0.981264637 0.981264637
                0.042553191 1   0.990632319 0.990632319
                0.037234043 1   0.990632319 0.990632319
                0.031914894 1   0.992974239 0.992974239
                0.026595745 1   0.992974239 0.992974239
                0.021276596 1   0.992974239 0.992974239
                0.015957447 1   1   1
                0.010638298 1   1   1
                0.005319149 1   1   1
                0   1   1   1
                0.521276596 1   0.915690867 0.915690867
                0.515957447 1   0.915690867 0.915690867
                0.510638298 1   0.915690867 0.915690867
                0.505319149 1   0.915690867 0.915690867
                0.5 1   0.915690867 0.915690867
                0.494680851 1   0.918032787 0.918032787
                0.489361702 1   0.918032787 0.918032787
                0.484042553 1   0.920374707 0.920374707
                0.478723404 1   0.920374707 0.920374707
                0.473404255 1   0.920374707 0.920374707
                0.468085106 1   0.920374707 0.920374707
                0.462765957 1   0.922716628 0.922716628
                0.457446809 1   0.922716628 0.922716628
                0.45212766  1   0.925058548 0.925058548
                0.446808511 1   0.925058548 0.925058548
                0.441489362 1   0.925058548 0.925058548
                0.436170213 1   0.925058548 0.925058548
                0.10106383  1   0.971896956 0.971896956
                0.095744681 1   0.974238876 0.974238876
                0.090425532 1   0.974238876 0.974238876
                0.085106383 1   0.974238876 0.974238876
                0.079787234 1   0.974238876 0.974238876
                0.074468085 1   0.976580796 0.976580796
                0.069148936 1   0.978922717 0.978922717
                0.063829787 1   0.978922717 0.978922717
                0.058510638 1   0.981264637 0.981264637
                0.053191489 1   0.981264637 0.981264637
                0.04787234  1   0.981264637 0.981264637
                0.042553191 1   0.990632319 0.990632319
                0.037234043 1   0.990632319 0.990632319
                0.031914894 1   0.992974239 0.992974239
                0.026595745 1   0.992974239 0.992974239
                0.021276596 1   0.992974239 0.992974239
                0.015957447 1   1   1
                0.010638298 1   1   1
                0.005319149 1   1   1
                0   1   1   1
                0.367021277 1   0.948477752 0.948477752
                0.361702128 1   0.948477752 0.948477752
                0.356382979 1   0.950819672 0.950819672
                0.35106383  1   0.950819672 0.950819672
                0.345744681 1   0.950819672 0.950819672
                0.340425532 1   0.950819672 0.950819672
                0.335106383 1   0.950819672 0.950819672
                0.329787234 1   0.950819672 0.950819672
                0.324468085 1   0.950819672 0.950819672
                0.319148936 1   0.950819672 0.950819672
                0.313829787 1   0.950819672 0.950819672
                0.10106383  1   0.971896956 0.971896956
                0.095744681 1   0.974238876 0.974238876
                0.090425532 1   0.974238876 0.974238876
                0.085106383 1   0.974238876 0.974238876
                \end{filecontents}


                \begin{document}
                \section{This is a VERY LONG TABLE}
                \twocolumn

                %%% Code from Dr. Christian ------ for not using headers.----------------------
                \pgfkeysifdefined{/pgfplots/table/output empty row/.@cmd}{
                    % upcoming releases offer this more convenient option:
                    \pgfplotstableset{
                        empty header/.style={
                          every head row/.style={output empty row},
                          outfile=pgfplotstable.example1.out.tex,
                        }
                    }
                }{
                    % versions up to and including 1.5.1 need this:
                    \pgfplotstableset{
                        empty header/.style={
                            typeset cell/.append code={%
                                \ifnum\pgfplotstablerow=-1 %
                                    \pgfkeyssetvalue{/pgfplots/table/@cell content}{}%
                                \fi
                            }
                        }
                    }
                }

                \noindent
                {\scriptsize
                % define tab first header
                \tablefirsthead{\multicolumn{2}{c}{\emph{c}} & \multicolumn{2}{c}{$\dfrac{G(c)}{G_{TOT}}$} & \multicolumn{2}{c}{$\dfrac{\hat{G}(c)}{G_{TOT}}$} & \multicolumn{2}{c}{$\phi(c)$} \\[7pt] \toprule\\}
                %define subsequent headers
                \tablehead{\multicolumn{8}{c}%
                    {{\bfseries Table \thetable\ \textit{(Continued)}}}\\
                    \toprule
                    %
                    \multicolumn{2}{c}{\emph{c}} & \multicolumn{2}{c}{$\dfrac{G(c)}{G_{TOT}}$} & \multicolumn{2}{c}{$\dfrac{\hat{G}(c)}{G_{TOT}}$} & \multicolumn{2}{c}{$\phi(c)$} \\[7pt] \toprule\\}
                %define tails
                \tabletail{ \midrule \multicolumn{8}{r}{{Continued on next column}} \\ \bottomrule\\}
                %define last tail
                \tablelasttail{\midrule\multicolumn{8}{r}{{End of Table}} \\ \bottomrule\\}
                %define caption
                \tablecaption{This is a Table with Data}
                \pgfplotstabletypeset[col sep=space,empty header,
                columns={c,G(c)GTOT,GhatGTOT,MODELPERFORM},      % display specified columns
                begin table=\begin{supertabular},
                end table=\end{supertabular},
                columns/c/.style={column type={c},dec sep align,precision=4,fixed,fixed zerofill},
                columns/G(c)GTOT/.style={column type={c},dec sep align,precision=4,fixed,fixed zerofill},
                columns/GhatGTOT/.style={column type={c},dec sep align,precision=4,fixed,fixed zerofill},
                columns/MODELPERFORM/.style={column type={c},dec sep align,precision=4,fixed,fixed zerofill},
                every head row/.append style={before row={%
                    \label{tab:DataTable}
                    }},
                ]{verylong.txt}
                \onecolumn %restores one-column output
                \end{document} 

答案1

借用这个问题,我建议你引入以下命令:

\makeatletter
\let\mcnewpage=\newpage
\newcommand{\TrickSupertabularIntoMulticols}{%
\renewcommand\newpage{%
    \if@firstcolumn%
        \hrule width\linewidth height0pt%
            \columnbreak%
        \else%
          \mcnewpage%
        \fi%
}%
}
\makeatother

这基本上是在环境中诱使supertabular进入新列而不是新页面multicols(*)

因此,这是解决方案:

\documentclass{book}
\usepackage[top=3cm,bottom=3cm,left=3.2cm,right=3.2cm,headsep=10pt,a4paper]{geometry}
\usepackage{multicol}
\usepackage{pgfplotstable, booktabs}
\pgfplotsset{compat=newest}
                \usepackage{supertabular}
                \makeatletter
\let\mcnewpage=\newpage
\newcommand{\TrickSupertabularIntoMulticols}{%
\renewcommand\newpage{%
    \if@firstcolumn%
        \hrule width\linewidth height0pt%
            \columnbreak%
        \else%
          \mcnewpage%
        \fi%
}%
}
\makeatother



       \usepackage{amsmath}
            \usepackage{array}
            \usepackage{fancyhdr}
            \pagestyle{fancy}
            \fancyhf{}

            \usepackage{filecontents}
            \begin{filecontents}{verylong.txt}
            c   G(c)GTOT    GhatGTOT    MODELPERFORM
            0.10106383  1   0.971896956 0.971896956
            0.095744681 1   0.974238876 0.974238876
            0.090425532 1   0.974238876 0.974238876
            0.085106383 1   0.974238876 0.974238876
            0.079787234 1   0.974238876 0.974238876
            0.074468085 1   0.976580796 0.976580796
            0.069148936 1   0.978922717 0.978922717
            0.063829787 1   0.978922717 0.978922717
            0.058510638 1   0.981264637 0.981264637
            0.053191489 1   0.981264637 0.981264637
            0.04787234  1   0.981264637 0.981264637
            0.042553191 1   0.990632319 0.990632319
            0.037234043 1   0.990632319 0.990632319
            0.031914894 1   0.992974239 0.992974239
            0.026595745 1   0.992974239 0.992974239
            0.021276596 1   0.992974239 0.992974239
            0.015957447 1   1   1
            0.010638298 1   1   1
            0.005319149 1   1   1
            0   1   1   1
            0.893617021 0.629976581 0.585480094 0.92936803
            0.888297872 0.644028103 0.592505855 0.92
            0.882978723 0.658079625 0.613583138 0.932384342
            0.877659574 0.672131148 0.62295082  0.926829268
            0.872340426 0.683840749 0.634660422 0.928082192
            0.867021277 0.695550351 0.641686183 0.922558923
            0.861702128 0.707259953 0.641686183 0.907284768
            0.856382979 0.718969555 0.644028103 0.895765472
            0.85106383  0.730679157 0.655737705 0.897435897
            0.845744681 0.742388759 0.669789227 0.902208202
            0.840425532 0.754098361 0.669789227 0.888198758
            0.835106383 0.763466042 0.669789227 0.877300613
            0.829787234 0.772833724 0.683840749 0.884848485
            0.824468085 0.782201405 0.68852459  0.880239521
            0.819148936 0.791569087 0.700234192 0.884615385
            0.813829787 0.800936768 0.711943794 0.888888889
            0.808510638 0.81030445  0.716627635 0.884393064
            0.803191489 0.817330211 0.723653396 0.885386819
            0.10106383  1   0.971896956 0.971896956
            0.095744681 1   0.974238876 0.974238876
            0.090425532 1   0.974238876 0.974238876
            0.085106383 1   0.974238876 0.974238876
            0.079787234 1   0.974238876 0.974238876
            0.074468085 1   0.976580796 0.976580796
            0.069148936 1   0.978922717 0.978922717
            0.063829787 1   0.978922717 0.978922717
            0.058510638 1   0.981264637 0.981264637
            0.053191489 1   0.981264637 0.981264637
            0.04787234  1   0.981264637 0.981264637
            0.042553191 1   0.990632319 0.990632319
            0.037234043 1   0.990632319 0.990632319
            0.031914894 1   0.992974239 0.992974239
            0.026595745 1   0.992974239 0.992974239
            0.021276596 1   0.992974239 0.992974239
            0.015957447 1   1   1
            0.010638298 1   1   1
            0.005319149 1   1   1
            0   1   1   1
            0.638297872 0.948477752 0.880562061 0.928395062
            0.632978723 0.950819672 0.880562061 0.926108374
            0.627659574 0.953161593 0.880562061 0.923832924
            0.622340426 0.955503513 0.880562061 0.921568627
            0.617021277 0.957845433 0.880562061 0.919315403
            0.611702128 0.960187354 0.880562061 0.917073171
            0.606382979 0.962529274 0.880562061 0.914841849
            0.10106383  1   0.971896956 0.971896956
            0.095744681 1   0.974238876 0.974238876
            0.090425532 1   0.974238876 0.974238876
            0.085106383 1   0.974238876 0.974238876
            0.079787234 1   0.974238876 0.974238876
            0.074468085 1   0.976580796 0.976580796
            0.069148936 1   0.978922717 0.978922717
            0.063829787 1   0.978922717 0.978922717
            0.058510638 1   0.981264637 0.981264637
            0.053191489 1   0.981264637 0.981264637
            0.04787234  1   0.981264637 0.981264637
            0.042553191 1   0.990632319 0.990632319
            0.037234043 1   0.990632319 0.990632319
            0.031914894 1   0.992974239 0.992974239
            0.026595745 1   0.992974239 0.992974239
            0.021276596 1   0.992974239 0.992974239
            0.015957447 1   1   1
            0.010638298 1   1   1
            0.005319149 1   1   1
            0   1   1   1
            0.521276596 1   0.915690867 0.915690867
            0.515957447 1   0.915690867 0.915690867
            0.510638298 1   0.915690867 0.915690867
            0.505319149 1   0.915690867 0.915690867
            0.5 1   0.915690867 0.915690867
            0.494680851 1   0.918032787 0.918032787
            0.489361702 1   0.918032787 0.918032787
            0.484042553 1   0.920374707 0.920374707
            0.478723404 1   0.920374707 0.920374707
            0.473404255 1   0.920374707 0.920374707
            0.468085106 1   0.920374707 0.920374707
            0.462765957 1   0.922716628 0.922716628
            0.457446809 1   0.922716628 0.922716628
            0.45212766  1   0.925058548 0.925058548
            0.446808511 1   0.925058548 0.925058548
            0.441489362 1   0.925058548 0.925058548
            0.436170213 1   0.925058548 0.925058548
            0.10106383  1   0.971896956 0.971896956
            0.095744681 1   0.974238876 0.974238876
            0.090425532 1   0.974238876 0.974238876
            0.085106383 1   0.974238876 0.974238876
            0.079787234 1   0.974238876 0.974238876
            0.074468085 1   0.976580796 0.976580796
            0.069148936 1   0.978922717 0.978922717
            0.063829787 1   0.978922717 0.978922717
            0.058510638 1   0.981264637 0.981264637
            0.053191489 1   0.981264637 0.981264637
            0.04787234  1   0.981264637 0.981264637
            0.042553191 1   0.990632319 0.990632319
            0.037234043 1   0.990632319 0.990632319
            0.031914894 1   0.992974239 0.992974239
            0.026595745 1   0.992974239 0.992974239
            0.021276596 1   0.992974239 0.992974239
            0.015957447 1   1   1
            0.010638298 1   1   1
            0.005319149 1   1   1
            0   1   1   1
            0.367021277 1   0.948477752 0.948477752
            0.361702128 1   0.948477752 0.948477752
            0.356382979 1   0.950819672 0.950819672
            0.35106383  1   0.950819672 0.950819672
            0.345744681 1   0.950819672 0.950819672
            0.340425532 1   0.950819672 0.950819672
            0.335106383 1   0.950819672 0.950819672
            0.329787234 1   0.950819672 0.950819672
            0.324468085 1   0.950819672 0.950819672
            0.319148936 1   0.950819672 0.950819672
            0.313829787 1   0.950819672 0.950819672
            0.10106383  1   0.971896956 0.971896956
            0.095744681 1   0.974238876 0.974238876
            0.090425532 1   0.974238876 0.974238876
            0.085106383 1   0.974238876 0.974238876
            \end{filecontents}


            \begin{document}

            \section{This is a VERY LONG TABLE}
            \begin{multicols*}{2}
            \TrickSupertabularIntoMulticols
            %%% Code from Dr. Christian ------ for not using headers.----------------------
            \pgfkeysifdefined{/pgfplots/table/output empty row/.@cmd}{
                % upcoming releases offer this more convenient option:
                \pgfplotstableset{
                    empty header/.style={
                      every head row/.style={output empty row},
                      outfile=pgfplotstable.example1.out.tex,
                    }
                }
            }{
                % versions up to and including 1.5.1 need this:
                \pgfplotstableset{
                    empty header/.style={
                        typeset cell/.append code={%
                            \ifnum\pgfplotstablerow=-1 %
                                \pgfkeyssetvalue{/pgfplots/table/@cell content}{}%
                            \fi
                        }
                    }
                }
            }

            \noindent
            {\scriptsize
            % define tab first header
            \tablefirsthead{\multicolumn{2}{c}{\emph{c}} & \multicolumn{2}{c}{$\dfrac{G(c)}{G_{TOT}}$} & \multicolumn{2}{c}{$\dfrac{\hat{G}(c)}{G_{TOT}}$} & \multicolumn{2}{c}{$\phi(c)$} \\[7pt] \toprule\\}
            %define subsequent headers
            \tablehead{\multicolumn{8}{c}%
                {{\bfseries Table \thetable\ \textit{(Continued)}}}\\
                \toprule
                %
                \multicolumn{2}{c}{\emph{c}} & \multicolumn{2}{c}{$\dfrac{G(c)}{G_{TOT}}$} & \multicolumn{2}{c}{$\dfrac{\hat{G}(c)}{G_{TOT}}$} & \multicolumn{2}{c}{$\phi(c)$} \\[7pt] \toprule\\}
            %define tails
            \tabletail{ \midrule \multicolumn{8}{r}{{Continued on next column}} \\ \bottomrule\\}
            %define last tail
            \tablelasttail{\midrule\multicolumn{8}{r}{{End of Table}} \\ \bottomrule\\}}
            %define caption
            \tablecaption{This is a Table with Data}
            \pgfplotstabletypeset[col sep=space,empty header,
            columns={c,G(c)GTOT,GhatGTOT,MODELPERFORM},      % display specified columns
            begin table=\begin{supertabular},
            end table=\end{supertabular},
            columns/c/.style={column type={c},dec sep align,precision=4,fixed,fixed zerofill},
            columns/G(c)GTOT/.style={column type={c},dec sep align,precision=4,fixed,fixed zerofill},
            columns/GhatGTOT/.style={column type={c},dec sep align,precision=4,fixed,fixed zerofill},
            columns/MODELPERFORM/.style={column type={c},dec sep align,precision=4,fixed,fixed zerofill},
            every head row/.append style={before row={%
                \label{tab:DataTable}
                }},
            ]{verylong.txt}

            \end{multicols*} %restores one-column output

            test
            \end{document} 

产量:

在此处输入图片描述


细节

  • \TrickSupertabularIntoMulticols在你的序言中包括关于和的代码\usepackage{multicol}

  • 摆脱\twocolumn\onecolumn

  • 在表格前使用\begin{multicols*}{2}(假设您需要两列)。这个带星号的版本根本不想在最后一页获得完美平衡的列(我建议保留带星号的版本)

  • 紧接着使用\TrickSupertabularIntoMulticols

  • 把代码放在那里(即\pgfkeysifdefined

  • 在表格末尾放\end{multicols*}

相关内容