Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Hi I'm trying to create a document in LaTeX with a few small subsections on the same page, is there any way to remove the repeated page numbers and keep the numbers when I move onto a new page?

share|improve this question
add comment

3 Answers 3

up vote 1 down vote accepted

Although I've no programming skills, it seems obvious that this possible; e.g. by adding a hook before each line of the toc: "if the pagenumer is the same as in the last line, print dots and number in \color{white} ".

There are some packages on CTAN regarding the table of contents. Do you know the "Topic Index"? Have a look on the packages about the table of contents there.

The closest candidate seems to be the package tocloft. If you've got a full installation, you might get the manual by typing texdoc tocloft on the command line. Maybe you can use \cftXleader or something similar.

However, your readers will miss the numbers and ask themselves (they can not ask you, can they? they are reading in a book!), whether it's a typo or not. So take my advice: print the 'toc' like all others do . . .

share|improve this answer
    
These are all okay workarounds, but I think I will leave it, and change the subsections to headings. Thanks! –  Jas_Young Jul 20 '12 at 23:14
add comment

Here is one way to do this using the tocloft package. The idea is roughly that proposed by Keks Dose, but here are the correct details and a concrete implementation.

You need to redefine the \cftXfillnum macro, where X stands for the relevant section levels, whose numbers you don't want displayed, and at one level above. Each of these needs to store the relevant page number in a some variable. The lower entries need to test the current value against the stored value and act accordingly.

In this example I have assumed you want all sections to be numbered, but subsections and subsections under those with common page numbers are not numbered.

Sample output

\documentclass[12pt,a4paper]{article}

\usepackage{tocloft}

\makeatletter
\def\currentcontentsnumber{0}
\renewcommand{\cftsecfillnum}[1]{
  {\cftsecleader}\nobreak
  \makebox[\@pnumwidth][\cftpnumalign]{%
  {\cftsecpagefont #1}}\cftsecafterpnum\par
  \gdef\currentcontentsnumber{#1}}
\renewcommand{\cftsubsecfillnum}[1]{\expandafter\ifx\currentcontentsnumber#1
  \hfill\nobreak\else
  {\cftsubsecleader}\nobreak
  \makebox[\@pnumwidth][\cftpnumalign]{%
  {\cftsubsecpagefont #1}}\fi
  \cftsubsecafterpnum\par
  \gdef\currentcontentsnumber{#1}}
\renewcommand{\cftsubsubsecfillnum}[1]{\expandafter\ifx\currentcontentsnumber#1
  \hfill\nobreak\else
  {\cftsubsubsecleader}\nobreak
  \makebox[\@pnumwidth][\cftpnumalign]{%
  {\cftsubsubsecpagefont #1}}\fi
  \cftsubsubsecafterpnum\par
  \gdef\currentcontentsnumber{#1}}
\makeatother

\begin{document}

\tableofcontents

\newpage
  \section{Lorem ipsum}
    dolor sit amet
    \subsection{consectetur adipiscing}
      elit. Donec a diam lectus.
        \subsubsection{Sed}
  \section{sit amet}
   ipsum mauris. Maecenas congue[...]
\newpage
  \section{ligula}
    ac quam viverra[...]
    \newpage
    \subsection{nec}
\end{document}
share|improve this answer
add comment

Well, I don't think it's the solution to the problem, but it's just a workaround. The result we want is to number only the sections, subsections, subsubsection.. that are not on the same page as the entry above them. It's only to avoid the repeated page numbers, but not to "disable" page numbering for specified entries.

Thanks,

share|improve this answer
    
this is easy to do with etoc. Please update the original question with the specific aim and especially the document class, in case the only thing you want to modify to the default layout is this. Or if you are not the original poster, post a new question. –  jfbu Nov 14 '13 at 13:14
1  
If you are referring to my answer, then it only supresses a page number if it is the same as the previous entry, it does not switch them off entirely at any given level. –  Andrew Swann Nov 14 '13 at 13:55
    
Thanks a lot, it has a strange behaviour in TexLive 2009, but runs perfectly in the 2013 version. ( tex.stackexchange.com/questions/1092/… ) –  fr33tux Nov 14 '13 at 21:00
    
And is it possible to keep the line points before each page number ? (But always without the duplicate page number) –  fr33tux Nov 20 '13 at 21:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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