[Tex/LaTex] pdfpages, addtolist and list of tables

pdfpdfpagestable of contents

These may be separate questions, but the following MWE:

\addcontentsline{lot}{subsection}{\ref{tab:UserRoles} \textbf{User Roles}}  
\includepdf[pages={-}, pagecommand={\label{tab:UserRoles}}, offset=0in -1in, addtolist={9, table, {The User Roles table}, tab:UserRoles}]{UserRolesTable}  

has several unexpected behaviors.

  1. I get the following warning:

    Package pdfpages Warning: There's something wrong with the entries of `addtolist'.
    Not all entries were processed. Check `addtolist' [in the MWE]."  
  2. Probably due to the \label not being bound to the inserted pdf (in a table environment), my inserted PDF is numbered using the section, and not the expected "Table X" value.

  3. The manually-inserted LoT line (which also uses the section number rather than the incremented table number) is not formatted like the other lines in the LoT – the number lines up, but the table caption itself is not aligned with the others in the list.

The source PDF has no errors and displays correctly in the output PDF.

PDFLaTeX -> BibTex


\textbf{Table \ref{tab:UserRoles} - The User Roles Table} \addcontentsline{lot}{subsection}{\ref{tab:UserRoles} 
\textbf{User Roles}} % manual entry in ToC 
\includepdf[pages={-}, pagecommand={\label{tab:UserRoles}}, offset=0in -1in, addtolist={9, table, {The User Roles table}, tab:UserRoles, lot}]{UserRolesTable}

Best Answer

There are some errors in the MWE:

  • pagecommand={\label{tab:UserRoles}}: This is executed on each builded page. In case of more than one page the result are warnings because of multiply defined labels. Also the label setting is already done by your option setting for addtolist. (Edit: Fix of PolGab applied, thanks)
  • The argument list for addtolist expects four parameters, the page number, the type, the title and the label. However there is a fifth element lot in the MWE. The package pdfpages sets the list entry by calling \caption, where \@makecaption is a dummy. Thus the caption is not actually typeset, but the counter is incremented and the entry for the list is done.
  • With a working addtolist the manual \addcontentsline is not longer needed. Also it should be called at the right page to get the correct page number.

The corrected MWE:


\section*{Table \ref{tab:UserRoles} - The User Roles Table}
  offset=0in -1in,
  addtolist={3, table, {The User Roles table}, tab:UserRoles},

The result:


The first page contains the list of tables and the "table section title". The third page of the included pages gets the entry in the list of tables, that is the fourth page.

Related Question