TeX - LaTeX Asked by Mads on December 23, 2020
How can I remove the subsection header in the document (over the PDF file in this case), but still have the header in TOC?
Code:
includepdf[pages=1,pagecommand=subsection{Header1} thispagestyle{empty}]{xx.pdf}
includepdf[pages=2-,pagecommand=]{xx.pdf}
Don't use subsection{Header1}
but instead use
refstepcounter{subsection}
addcontentsline{toc}{subsection}
{%
ifnum2>value{secnumdepth}elseprotectnumberline{thesubsection}fi Header1%
}
Complete MWE:
documentclass[]{article}
begin{document}
tableofcontents
section{something}
refstepcounter{subsection}
addcontentsline{toc}{subsection}
{%
ifnum2>value{secnumdepth}elseprotectnumberline{thesubsection}fi Header1%
}
end{document}
Result:
One could as well create a macro that does take two arguments, the sectioning level and the heading and create a TOC entry without typesetting a heading, if this is needed multiple times. The following should work for the standard classes.
usepackage{pdftexcmds}
makeatletter
def@getsecnum@fin#1else#2fi{fi#1}
def@getsecnum@nonefi{fi1000}
newcommand*@getsecnum@a[2]
{%
fiifnumpdf@strcmp{#1}{#2}=0 @getsecnum@fin
}
newcommand*@getsecnum[1]
{%
ifnumpdf@strcmp{#1}{part}=0 @getsecnum@fin{-1}%
else@getsecnum@a{#1}{chapter}{0}%
else@getsecnum@a{#1}{section}{1}%
else@getsecnum@a{#1}{subsection}{2}%
else@getsecnum@a{#1}{subsubsection}{3}%
else@getsecnum@a{#1}{paragraph}{4}%
else@getsecnum@a{#1}{subparagraph}{5}%
else@getsecnum@none
fi
}
newcommandTOConlySection@[3]
{%
ifnum#1>c@secnumdepth
else
refstepcounter{#2}%
fi
addcontentsline{toc}{#2}
{%
ifnum#1>c@secnumdepth
else
ifnum#1=-1
theparthspace{1em}%
else
protectnumberline{csname the#2endcsname}%
fi
fi
#3%
}%
}
newcommandTOConlySection[2]
{%
expandafterTOConlySection@expandafter
{romannumeral-`0@getsecnum{#1}}{#1}{#2}%
}
Usage would be
TOConlySection{part}{part heading}
TOConlySection{section}{section heading}
TOConlySection{subsection}{subsection heading}
Answered by Skillmon on December 23, 2020
If this is needed for the included pdf, then you can use option addtotoc={⟨page number ⟩,⟨section ⟩,⟨level ⟩,⟨heading ⟩,⟨label ⟩}
for includepdf
.
addtotoc={1,subsection,2,<heading>,<label>}
Example:
documentclass{article}
usepackage{pdfpages}
begin{document}
tableofcontents
section{A section}
See subsection~ref{subsec:H1} on page pageref{subsec:H1}.
includepdf[pages=-,addtotoc={1,subsection,2,Header1,subsec:H1}]{dummy}
end{document}
Result:
Answered by esdd on December 23, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP