1

I have a problem with a cross-reference across two files. My files are arranged like in this example here: https://tex.stackexchange.com/a/148818/147782

two files included in the main file with \input and I'm trying to reference from one to the other. I tried creating some short example files and these work. So I'm assuming the mistake lies with the label.

Is it possible, that \label has to be tied to an object?, as in, can it be on its own or does it need an anchor? Because my appendix is a bit weirdly built as I have to include .pdf files there, so there is no actual object like a title or an image there, just links to files. The really weird thing is, I just found out, that some of the labels work, whereas others don't. E.g. from the ones here, CFA1 and CFBS1 work, whereas NMBS does not, even though they are positioned in the same place and all... I'm using \pageref{NMBS} to reference them.

\section*{Appendix}
\addcontentsline{toc}{section}{Appendix}
\pagebreak
\addcontentsline{toc}{subsection}{Coal Face Shot by Shot Analysis Part I} \label{CFA1}
\includepdf[pages=-, landscape, pagecommand={\thispagestyle{plain}}]{Appendices/CF1Protokoll}
\addcontentsline{toc}{subsection}{Coal Face Bar Sheet Part I} \label{CFBS1}
\includepdf[pages=-,  pagecommand={\thispagestyle{plain}}]{Appendices/CF1Rhythm}
\addcontentsline{toc}{subsection}{Night Mail Bar Sheet} \label{NMBS}
\includepdf[pages=-,  pagecommand={\thispagestyle{plain}}]{Appendices/NM5Rhythm}

zipped short version: https://www.dropbox.com/s/3dbr527094q3pg7/Appendix.zip?dl=0

  • What do you suspect \addcontentsline{toc}{subsection}{Coal Face Shot by Shot Analysis Part I} \label{CFA1} to do? You're labelling basically nothing then – user31729 Jan 13 '18 at 15:02
  • Do you have the sources of your CF1Rhytm etc. files as well? You can directly input them (stripping the documentclass around them), otherwise use \usepackage{xr} and its \externaldocument file, this needs the .aux files of the 'subfiles', however – user31729 Jan 13 '18 at 15:04
  • well it creates an entry in the ToC without printing an actual title which it does, this works for all of them and shows the correct page number. As said, I can't set a real title because then it would use a whole page just for the title as the pdf needs a complete page. – Cinna Jan 13 '18 at 15:07
  • I know what \addcontentsline does, but the \label is pretty useless there – user31729 Jan 13 '18 at 15:08
  • yes I do have the sources, I wrote them myself. I don't think I can strip the stuff around it. I tried it with input in the beginning. The problem is, that I need LaTeX to type the page number on top of the inserted pdf page and this somehow did not work using \input or at least I was too stupid to get it to work. Also: why would it work with one label but not with the other? I can't see any difference between them. – Cinna Jan 13 '18 at 15:10
1

The O.P. missed a comma after pagecommand{}addtotoc, i.e. it should be pagecommand{...},addtotoc=....

\documentclass[12pt]{article}

\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage[german,british]{babel}

\usepackage{pdfpages} % pdf package http://texdoc.net/texmf-dist/doc/latex/pdfpages/pdfpages.pdf

\begin{document}

\tableofcontents % Prints the main table of contents

\input{B}
\input{A}

\end{document}

In A.tex:

\section*{Appendix}
\addcontentsline{toc}{section}{Appendix}
\pagebreak
%\addcontentsline{toc}{subsection}{Coal Face Bar Sheet Part I} \label{CFBS1}
\includepdf[pages=-, pagecommand={\thispagestyle{plain}}, addtotoc={1,subsection,2,Coal Face Bar Sheet Part I,CFBS1}]{CFBS1} 
%\addcontentsline{toc}{subsection}{Coal Face Shot by Shot Analysis Part II} \label{CFA2}
\includepdf[pages=-,  landscape, pagecommand={\thispagestyle{plain}},addtotoc={1,subsection,2,Coal Face Shot by Shot Analysis Part I,CFA2}]{CFA2}

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.