4

After using tex.stackexchange.com/a/373987/134144, I have some code that will make a table that spans multiple pages and displays the page count at the top of each table. The issue that I am having is I do not want the page count if the table does not in fact cover multiple pages. For instance, if the table starts at the top of the page and can fit on the page it starts on, the page count should not be included. If the same table instead starts, say, halfway down the page, and would spill over onto a new page, then I want the page count to appear. This is what I have so far but I am not sure on how to only have something appear if and only if the table spans multiple pages.

    \documentclass{article}

    \usepackage{booktabs,supertabular}
    \usepackage{lastpage}
    \usepackage[table]{xcolor}

    \begin{document}

    \tablehead{
      \multicolumn{2}{l}{\textbf{Table 1.1 (Sheet~\thepage~of~\pageref{LastPage})}}\\
      \hline\multicolumn{1}{c|}{\cellcolor{gray!25}\textbf{Foo}} & 
      \multicolumn{1}{|c}{\cellcolor{gray!25}\textbf{Bar}}\\
      \hline }
    \tablefirsthead{
      \multicolumn{2}{l}{\textbf{Table 1.1 (Sheet~\thepage~of~\pageref{LastPage})}}\\
      \hline\multicolumn{1}{c|}{\cellcolor{gray!25}\textbf{Foo}} & 
      \multicolumn{1}{|c}{\cellcolor{gray!25}\textbf{Bar}}\\
      \hline }
    \tabletail{\hline}
    \tablelasttail{\hline}

    \begin{supertabular}{l|l} 
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline
      Lorem Ipsum & John Doe \\[5pt] \hline

    \end{supertabular}

    \end{document}

enter image description here enter image description here

1 Answer 1

0

I was able to solve this using counters and if conditionals. When you add a bunch of content to the table, the sheet count will be added to the table head. There may be a better way, but here is my solution:

\documentclass{article}

\usepackage{booktabs,supertabular}
\usepackage{lastpage}
\usepackage[table]{xcolor}
\usepackage{refcount}

\begin{document}
Hello
\clearpage

%Begin table stuff
\newcounter{StartTableCounter}
\newcounter{EndTableCounter}
\setcounter{StartTableCounter}{\getpagerefnumber{startTable}}
\setcounter{EndTableCounter}{\getpagerefnumber{endTable}}
\newcommand{\TableHeader}{Table 1.1}

\ifnum\value{StartTableCounter}=\value{EndTableCounter}
  \renewcommand{\TableHeader}{Table 1.1}
\else
  \renewcommand{\TableHeader}{Table 1.1 (Sheet~\the\numexpr\value{page}+1-\the\numexpr\value{StartTableCounter}~of~\the\numexpr\value{EndTableCounter}+1-\the\numexpr\value{StartTableCounter})}
\fi

\tablehead{
  \multicolumn{2}{l}{\textbf{\TableHeader}}\\\hline
  \multicolumn{1}{c|}{\cellcolor{gray!25}\textbf{Foo}} & 
  \multicolumn{1}{|c}{\cellcolor{gray!25}\textbf{Bar}}\\\hline
}
\tablefirsthead{
  \multicolumn{2}{l}{\textbf{\TableHeader}}\\\hline
  \multicolumn{1}{c|}{\cellcolor{gray!25}\textbf{Foo}} & 
  \multicolumn{1}{|c}{\cellcolor{gray!25}\textbf{Bar}}\\\hline
}
\tabletail{\hline}
\tablelasttail{\hline}

\label{startTable}
\begin{supertabular}{l|l} 
  Lorem Ipsum & John Doe \\ \hline
  Lorem Ipsum & John Doe \\ \hline
  Lorem Ipsum & John Doe \\ \hline
\end{supertabular}
\label{endTable}

\clearpage
goodbye

\end{document}

You must log in to answer this question.

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