2

I am using TexShop and because there is nothing like a navigation (or at least I don't know how to create it) and my document comprises about 200-300 pages, I try to build my own navigation in the footer of my PDF-file by using the package fancyhdr and the \nameref.

The problem is that my headlines are very long. I used the short title to cut them down, but now my ToC is cut down as well. I wonder if there is a possibility to use the short title just for \nameref while putting the full title in the ToC.

If someone knows a solution it would be really great. Thanks in advance.

Hi again,

as you ask for the minimal code. Here it is (I hope it is minimal, am relatively new to this things):

\documentclass{book}

\usepackage[colorlinks,cross-references,bookmarks=true]{hyperref}

\usepackage{fancyhdr} 
\pagestyle{fancy}
\lfoot{\nameref{S:A}, \nameref{S:B}, \nameref{S:C}}

\begin{document}

\tableofcontents
\newpage

\section[Intro]{Vorbemerkung}\label{S:A}
\newpage

\section[Paul]{Paul ist ein Mann von Format}\label{S:B}
\newpage

\section[Klaus]{Klaus}\label{S:C}

\end{document}

@Caramdir: My TexShop displays the document in his own pdf which enables me to switch from this pdf to the tex file and back by clicking "apple + mouse" and is one of my navigation tools which works as follows: I go to the toc of my pdf, by hyperlink I get to the section I want and there I click "apple + mouse" in the document to get exactly to the same point in the tex document. Many steps I know, but I see no other way. By placing hypertext in the header I can improve this process because I can easily jump back close to the toc (exactly to the first chapter).

The "apple + mouse"-option doesn't work when I open the document with other programs and thats why your suggestion doesn't help in this case.

4
  • 2
    If you use hyperref and compile with pdflatex, you should get a toc in the side bar of your pdf viewer.
    – Caramdir
    Mar 17, 2011 at 19:09
  • 1
    Which document class are you using? Could you post some minimal, complete and compilable code showing us your current settings? Mar 17, 2011 at 19:15
  • Welcome to tex.sx! It's not necessary to sign your questions (as there is already a box with your username below it) or to begin them with a greeting. Mar 17, 2011 at 19:46
  • To add to @Caramdir's pointer, click the icon in the menu bar of the preview window that looks like two photos. The sidebar will open up with the navigation. Mar 17, 2011 at 19:47

1 Answer 1

3

If you want to keep the contents of the mandatory argument of the sectional units in the ToC while using the contents of the optional argument in the headers/footers, you need to redefine the commands \@part (which controls the information for parts), \@chapter (which controls the information for chapters) and \@sect (which controls the information for the other sectional units). Here's an example code of the redefinition (the lines between \makeatletter and \makeatother):

\documentclass{book}
\usepackage[colorlinks,bookmarks=true]{hyperref}
\usepackage{fancyhdr} 
\pagestyle{fancy} 
\lfoot{\nameref{S:A}, \nameref{S:B}, \nameref{S:C}}

\makeatletter
\def\@part[#1]#2{%
    \ifnum \c@secnumdepth >-2\relax
      \refstepcounter{part}%
      \addcontentsline{toc}{part}{\thepart\hspace{1em}#2}%
    \else
      \addcontentsline{toc}{part}{#2}%
    \fi
    \markboth{}{}%
    {\centering
     \interlinepenalty \@M
     \normalfont
     \ifnum \c@secnumdepth >-2\relax
       \huge\bfseries \partname~\thepart
       \par
       \vskip 20\p@
     \fi
     \Huge \bfseries #2\par}%
    \@endpart}
\def\@chapter[#1]#2{\ifnum \c@secnumdepth >\m@ne
                       \if@mainmatter
                         \refstepcounter{chapter}%
                         \typeout{\@chapapp\space\thechapter.}%
                         \addcontentsline{toc}{chapter}%
                                   {\protect\numberline{\thechapter}#2}%
                       \else
                         \addcontentsline{toc}{chapter}{#2}%
                       \fi
                    \else
                      \addcontentsline{toc}{chapter}{#2}%
                    \fi
                    \chaptermark{#1}%
                    \addtocontents{lof}{\protect\addvspace{10\p@}}%
                    \addtocontents{lot}{\protect\addvspace{10\p@}}%
                    \if@twocolumn
                      \@topnewpage[\@makechapterhead{#2}]%
                    \else
                      \@makechapterhead{#2}%
                      \@afterheading
                    \fi}
\def\@sect#1#2#3#4#5#6[#7]#8{%
  \ifnum #2>\c@secnumdepth
    \let\@svsec\@empty
  \else
    \refstepcounter{#1}%
    \protected@edef\@svsec{\@seccntformat{#1}\relax}%
  \fi
  \@tempskipa #5\relax
  \ifdim \@tempskipa>\z@
    \begingroup
      #6{%
        \@hangfrom{\hskip #3\relax\@svsec}%
          \interlinepenalty \@M #8\@@par}%
    \endgroup
    \csname #1mark\endcsname{#7}%
    \addcontentsline{toc}{#1}{%
      \ifnum #2>\c@secnumdepth \else
        \protect\numberline{\csname the#1\endcsname}%
      \fi
      #8}%
  \else
    \def\@svsechd{%
      #6{\hskip #3\relax
      \@svsec #8}%
      \csname #1mark\endcsname{#7}%
      \addcontentsline{toc}{#1}{%
        \ifnum #2>\c@secnumdepth \else
          \protect\numberline{\csname the#1\endcsname}%
        \fi
        #8}}%
  \fi
  \@xsect{#5}}
\makeatother

\begin{document}

\tableofcontents
\part[Short part title]{A part title not so short}
\chapter[Short title]{A really really really really really really really long title}
\section[Intro]{Vorbemerkung}\label{S:A} \newpage

\section[Paul]{Paul ist ein Mann von Format}\label{S:B} \newpage

\section[Klaus]{Klaus}\label{S:C}

\end{document}
3
  • Hi, this way is realy great. It works perfectly well. But I have one more question. Can you provide me such a definition for \part{asdfadsf}\label{P:A} as well, that would really help. I thought there will be an easy solution, which I can apply to other things (like parts) as well, but what you created transcends my abilities by far.And one more thing: This version doesnt show the page numbers. How to change that?
    – Philip
    Mar 18, 2011 at 0:18
  • @Philip: I added the redefinition for parts. I also suppressed \fancyhf{} so now the page numbers will be shown. Mar 18, 2011 at 1:07
  • Hi, this way it satisfy all my needs. Thank you very much!
    – Philip
    Mar 18, 2011 at 8:17

You must log in to answer this question.

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