0

I am having difficulties formatting a supertabular table that spans multiple pages, is the width of the page, and has images and text combined inside cells. My first problem is that the table seem to be wider than the \textwidth that I am trying to set the width to. Secondly, when an image is inserted, the rest of the text is bumped down. Thirdly, when using the image and having enough rows to span more than one page, the first page turns out empty, the second page contains the first cells of the table, and the third page contains the third page of cells from the table. Here is my code followed by some images to show what I mean.

\documentclass{book}

\usepackage{graphicx}
\usepackage{placeins}
\usepackage[margin=1.0in]{geometry}
\usepackage{booktabs,supertabular}
\usepackage[table]{xcolor}
\usepackage{refcount}
\usepackage{makecell}

\pagestyle{plain}

\newcommand{\TableHeaderContent}[3]{
\ifnum\value{#1}=\value{#2}
#3
\else
#3 (Sheet~\the\numexpr\value{page}+1-\the\numexpr\value{#1}~of~\the\numexpr\value{#2}+1-\the\numexpr\value{#1})
\fi
}

\newcommand{\TableCell}[1]{
\multicolumn{1}{p{0.25\linewidth}}{#1}
}

\begin{document}

\newcounter{StartTableCounter}
\newcounter{EndTableCounter}
\setcounter{StartTableCounter}{\getpagerefnumber{StartTable}}
\setcounter{EndTableCounter}{\getpagerefnumber{EndTable}}

\tablehead{
\multicolumn{4}{l}{\textbf{\TableHeaderContent{StartTableCounter}{EndTableCounter}{Table 1.1}}}\\\hline
\multicolumn{1}{p{0.25\linewidth}}{\cellcolor{gray!25}\textbf{Header 1}} &
\multicolumn{1}{|p{0.25\linewidth}}{\cellcolor{gray!25}\textbf{Header 2}} &
\multicolumn{1}{|p{0.25\linewidth}}{\cellcolor{gray!25}\textbf{Header 3}} &
\multicolumn{1}{|p{0.25\linewidth}}{\cellcolor{gray!25}\textbf{Header 4}}\\\hline
}
\tablefirsthead{
\multicolumn{4}{l}{\textbf{\TableHeaderContent{StartTableCounter}{EndTableCounter}{Table 1.1}}}\\\hline
\multicolumn{1}{p{0.25\linewidth}}{\cellcolor{gray!25}\textbf{Header 1}} &
\multicolumn{1}{|p{0.25\linewidth}}{\cellcolor{gray!25}\textbf{Header 2}} &
\multicolumn{1}{|p{0.25\linewidth}}{\cellcolor{gray!25}\textbf{Header 3}} &
\multicolumn{1}{|p{0.25\linewidth}}{\cellcolor{gray!25}\textbf{Header 4}}\\\hline
}
\tabletail{\hline}
\tablelasttail{\hline}
\label{StartTable}
\begin{supertabular*}{\linewidth}{p{0.25\linewidth}|p{0.25\linewidth}|p{0.25\linewidth}|p{0.25\linewidth}}

\includegraphics[width=\linewidth]{blackbox.jpeg} &
Content 2 &
Content 3 &
Long text with lots of words thats more than one line but not one really big word which apparently can cause some problems.\\\hline

\end{supertabular*}
\label{EndTable}

\end{document}

which produces: enter image description here

and when I add more rows: enter image description here

As you can see, empty first page, wrong second page. To summarize, why does the table extend past the \textwidth? Why does the picture force the rest of the content down? And why does the page formatting get weird when I introduce pictures into the mix?

EDIT: Here is what the table looks like without a picture: enter image description here

1 Answer 1

1

Aside from the overspill of the columns, I have found a solution to some of the other issue. Simply change the TableCell command to look like:

\newcommand{\TableCell}[1]{
\makecell*[{{p{\linewidth}}}]{#1}
}

Here would be the new code in full. This includes a couple minor changes like centering the table headers and putting the sheet counters in the first and last elements of the table to give more accurate sheet counts.

\documentclass{book}

\usepackage{graphicx}
\usepackage{placeins}
\usepackage{anyfontsize}
\usepackage{fontspec}
\usepackage[margin=1.0in]{geometry}
\usepackage{tocloft}
\usepackage{scrextend}
\usepackage{caption}
\usepackage{booktabs,supertabular}
\usepackage[table]{xcolor}
\usepackage{refcount}
\usepackage{makecell}
\usepackage{tcolorbox}
\usepackage{pifont}
\usepackage{hyperref}

\pagestyle{plain}

\definecolor{noteOutline}{rgb}{0.122, 0.435, 0.698}
\definecolor{noteBackground}{RGB}{161, 192, 255}

\setlength\extrarowheight{2pt}

\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}}
\newcommand{\MyChapter}[2]{
  \phantomsection
  \addcontentsline{toc}{chapter}{#2}
  \begin{center}
    {\textbf{\Huge{#1}}}\\[15pt]

    {\textbf{\huge{#2}}}
  \end{center}
}

\newcommand{\TableHeaderContent}[3]{
\ifnum\value{#1}=\value{#2}
#3
\else
#3 (Sheet~\the\numexpr\value{page}+1-\the\numexpr\value{#1}~of~\the\numexpr\value{#2}+1-\the\numexpr\value{#1})
\fi
}

\newcommand{\TableCell}[1]{
\makecell*[{{p{\linewidth}}}]{#1}
}

\newcommand{\thickline}{
\Xhline{4\arrayrulewidth}
}

\begin{document}

\MyChapter{Section 1}{Title}

\begin{center}
\addcontentsline{lot}{table}{Table 1.1 }
\newcounter{Table10StartTableCounter}
\newcounter{Table10EndTableCounter}
\setcounter{Table10StartTableCounter}{\getpagerefnumber{Table10StartTable}}
\setcounter{Table10EndTableCounter}{\getpagerefnumber{Table10EndTable}}

\tablehead{
\multicolumn{3}{l}{\textbf{\TableHeaderContent{Table10StartTableCounter}{Table10EndTableCounter}{Table 1.1 }}}\\\thickline
\multicolumn{1}{>{\centering}p{0.333262\linewidth}|}{\cellcolor{gray!25}{Cell 1}} &
\multicolumn{1}{|>{\centering}p{0.333369\linewidth}}{\cellcolor{gray!25}{Cell 2}} &
\multicolumn{1}{|>{\centering}p{0.333369\linewidth}}{\cellcolor{gray!25}{Cell 4}}
\\\hline
}
\tablefirsthead{
\multicolumn{3}{l}{\textbf{\TableHeaderContent{Table10StartTableCounter}{Table10EndTableCounter}{Table 1.1 }}}\\\thickline
\multicolumn{1}{>{\centering}p{0.333262\linewidth}|}{\cellcolor{gray!25}{Cell 1}} &
\multicolumn{1}{|>{\centering}p{0.333369\linewidth}}{\cellcolor{gray!25}{Cell 2}} &
\multicolumn{1}{|>{\centering}p{0.333369\linewidth}}{\cellcolor{gray!25}{Cell 4}}
\\\hline
}
\tabletail{\thickline}
\tablelasttail{\thickline}
\begin{supertabular*}{\linewidth}{p{0.333262\linewidth}|p{0.333369\linewidth}|p{0.333369\linewidth}}
\TableCell{Cell 4}\label{Table10StartTable} &
\TableCell{Cell 5} &
\TableCell{\includegraphics[width=0.333369\linewidth]{image1.jpg}}\\\hline
\TableCell{Cell 7} &
\TableCell{Cell 8} &
\TableCell{\includegraphics[width=0.333369\linewidth]{image1.jpg}}\\\hline
\TableCell{Cell 1} &
\TableCell{Cell 2} &
\TableCell{\includegraphics[width=0.333369\linewidth]{image1.jpg}}\\\hline
\TableCell{Cell 4} &
\TableCell{Cell 5} &
\TableCell{\includegraphics[width=0.333369\linewidth]{image1.jpg}}\\\hline
\TableCell{Cell 7} &
\TableCell{Cell 8} &
\TableCell{\includegraphics[width=0.333369\linewidth]{image1.jpg}}\\\hline
\TableCell{Cell 1} &
\TableCell{Cell 2} &
\TableCell{\includegraphics[width=0.333369\linewidth]{image1.jpg}}\\\hline
\TableCell{Cell 4} &
\TableCell{Cell 5} &
\TableCell{\includegraphics[width=0.333369\linewidth]{image1.jpg}}\\\hline
\TableCell{Cell 7} &
\TableCell{Cell 8} &
\TableCell{\includegraphics[width=0.333369\linewidth]{image1.jpg}}\\\hline
\TableCell{Cell 1} &
\TableCell{Cell 2} &
\TableCell{\includegraphics[width=0.333369\linewidth]{image1.jpg}}\\\hline
\TableCell{Cell 4} &
\TableCell{Cell 5} &
\TableCell{\includegraphics[width=0.333369\linewidth]{image1.jpg}}\\\hline
\TableCell{Cell 7} &
\TableCell{Cell 8} &
\TableCell{\includegraphics[width=0.333369\linewidth]{image1.jpg}}\label{Table10EndTable}\\
\end{supertabular*}
\end{center}

\end{document}

You must log in to answer this question.

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