4

I'm currently writing my second thesis template for LyX 2.0.6 under MiKTeX 2.9, and since I'm using the article document class I have to manually organize the page numbering inside the ToC, LoF, LoT et similia.

Thanks to fancyhdr I had no problems for the specific page number typesetting on the document body, which will be shown in the MWE; but when I began to organize my ToC formatting I encountered an issue that required this kind of help.

My goal is to obtain the Roman numbering for the pseudo-frontmatter inside the ToC without selecting pagenumbering{Roman}, because I want to use the Small Caps font selection.

The MWE is as follows:

\documentclass[11pt,twoside,british,italian]{article}
%
\usepackage[T1]{fontenc}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{babel}
\usepackage{lipsum}
%
\makeatletter
%
% define the page style, note \pagestyle{fancy} already in the preamble
\renewcommand{\sectionmark}[1]{\markboth{Sezione\ \thesection.\ #1}{}}
\renewcommand{\subsectionmark}[1]{\markright{#1}}
\fancyhf{}
\fancyhead[RE]{\nouppercase{\slshape \leftmark}}
\fancyhead[LO]{\nouppercase{\slshape \lastrightmark}}
\fancyhead[LE,RO]{\itshape \thepage}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0pt}

% create new \fancypagestyles in respect to short sections
\usepackage{slantsc}
\usepackage{extramarks} 
%
\fancypagestyle{plain}{%
\fancyhf{} 
\fancyfoot[CE,CO]{\slshape{\scshape \thepage}}  % Page numbers with my defined style
\renewcommand{\headrulewidth}{0pt}%
}
\fancypagestyle{nonTOCplain}{%
\fancyhf{} 
\fancyhead[LE,RO]{\itshape \thepage}
\renewcommand{\headrulewidth}{0pt}%
}
\fancypagestyle{TOCplain}{%
\fancyhf{} 
\fancyhead[RE]{\nouppercase{\slshape \leftmark}}
\fancyhead[LO]{\nouppercase{\slshape \lastrightmark}}
\fancyhead[LE,RO]{\slshape{\scshape \thepage}}  % Page numbers with my defined style
\renewcommand{\headrulewidth}{0.4pt}%
}
% 
% the pages of the ToC/LoF/LoT are numbered Lowercase Roman 
\let\myTOC\tableofcontents
\renewcommand\tableofcontents{%
 \pagenumbering{roman}   % I don't want "Roman" because there are too big letters!
 \thispagestyle{plain}
 \myTOC%
}
%
\makeatother
%
\begin{document}
%
\thispagestyle{plain}
\addcontentsline{toc}{section}{Indice Generale}
\tableofcontents{}
\clearpage{}
%
\thispagestyle{TOCplain}
\cleardoublepage{}
%
\thispagestyle{TOCplain}
\addcontentsline{toc}{section}{Elenco delle Figure}
\listoffigures
\clearpage{}
%
\thispagestyle{TOCplain}
\cleardoublepage{}
\pagenumbering{arabic}
%
\thispagestyle{nonTOCplain}
\section{Introduzione}
\lipsum[1]
%
\cleardoublepage{}
%
\thispagestyle{nonTOCplain}
\section{Prima sezione }
\lipsum[3]
\subsection{Prima sottosezione }
\lipsum[3]
%
\end{document}

As it is complied, the frontmatter pages have slanted small caps roman numerals:

enter image description here

but inside the ToC they appear only lowercase upright roman:

enter image description here

My question so remains on how to obtain the document body number style inside the ToC, maybe using this imaginary command:

\newcommand*\ToCpagefont{\bfseries\scshape}  % roman-smallcaps-bold page number

Although I tried tocloft with the useful command:

\usepackage{tocloft}
\renewcommand*{\cftsecpagefont}{\uppercase\bfseries}

it gives me only undefined control sequences, and I think it is more reliable if every element inside the ToC formatting was adapted to this package; since I don't use it I'd like to know if there is some sort of solution to this starts-to-wear-me-off issue.


EDIT: Here is the MWE with addition of Hyperref:

\documentclass[11pt,twoside,british,italian]{article}
%
\usepackage[T1]{fontenc}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{babel}
\usepackage{lipsum}
%
\usepackage[unicode=true,
bookmarks=true,bookmarksnumbered=true,bookmarksopen=false,
breaklinks=false,pdfborder={0 0 1},backref=false,colorlinks=true]
{hyperref}
%
\makeatletter
%
% define the page style, note \pagestyle{fancy} already in the preamble
\renewcommand{\sectionmark}[1]{\markboth{Sezione\ \thesection.\ #1}{}}
\renewcommand{\subsectionmark}[1]{\markright{#1}}
\fancyhf{}
\fancyhead[RE]{\nouppercase{\slshape \leftmark}}
\fancyhead[LO]{\nouppercase{\slshape \lastrightmark}}
\fancyhead[LE,RO]{\itshape \thepage}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0pt}

% create new \fancypagestyles in respect to short sections
\usepackage{slantsc}
\usepackage{extramarks} 
%
\fancypagestyle{plain}{%
\fancyhf{} 
\fancyfoot[CE,CO]{\slshape{\scshape \thepage}}  % Page numbers with my defined style
\renewcommand{\headrulewidth}{0pt}%
}
\fancypagestyle{nonTOCplain}{%
\fancyhf{} 
\fancyhead[LE,RO]{\itshape \thepage}
\renewcommand{\headrulewidth}{0pt}%
}
\fancypagestyle{TOCplain}{%
\fancyhf{} 
\fancyhead[RE]{\nouppercase{\slshape \leftmark}}
\fancyhead[LO]{\nouppercase{\slshape \lastrightmark}}
\fancyhead[LE,RO]{\slshape{\scshape \thepage}}  % Page numbers with my defined style
\renewcommand{\headrulewidth}{0.4pt}%
}
% 
% the pages of the ToC/LoF/LoT are numbered Lowercase Roman 
\let\myTOC\tableofcontents
\renewcommand\tableofcontents{%
 \pagenumbering{roman}   % I don't want "Roman" because there are too big letters!
 \thispagestyle{plain}
 \myTOC%
}
%
\makeatother
%
\begin{document}
%
\thispagestyle{plain}
\addcontentsline{toc}{section}{Indice Generale}
\tableofcontents{}
\clearpage{}
%
\thispagestyle{TOCplain}
\cleardoublepage{}
%
\thispagestyle{TOCplain}
\addcontentsline{toc}{section}{Elenco delle Figure}
\listoffigures
\clearpage{}
%
\thispagestyle{TOCplain}
\cleardoublepage{}
\pagenumbering{arabic}
%
\thispagestyle{nonTOCplain}
\section{Introduzione}
\lipsum[1]
%
\cleardoublepage{}
%
\thispagestyle{nonTOCplain}
\section{Prima sezione }
\lipsum[3]
\subsection{Prima sottosezione }
\lipsum[3]
%
\end{document}

3 Answers 3

2

One way would be to replace your \addcontentsline by \addtocontents more detailed macros. (in code comments: the more complicated case with package hyperref loaded)

\documentclass[11pt,twoside,british,italian]{article}
%
\usepackage[T1]{fontenc}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{babel}
\usepackage{lipsum}

% \usepackage[unicode=true,
% bookmarks=true,bookmarksnumbered=true,bookmarksopen=false,
% breaklinks=false,pdfborder={0 0 1},backref=false,colorlinks=true]
% {hyperref}
% %
% % see commented out lines below for this case with hyperref


\makeatletter
%
% define the page style, note \pagestyle{fancy} already in the preamble
\renewcommand{\sectionmark}[1]{\markboth{Sezione\ \thesection.\ #1}{}}
\renewcommand{\subsectionmark}[1]{\markright{#1}}
\fancyhf{}
\fancyhead[RE]{\nouppercase{\slshape \leftmark}}
\fancyhead[LO]{\nouppercase{\slshape \lastrightmark}}
\fancyhead[LE,RO]{\itshape \thepage}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0pt}

% create new \fancypagestyles in respect to short sections
\usepackage{slantsc}
\usepackage{extramarks} 
%
\fancypagestyle{plain}{%
\fancyhf{} 
\fancyfoot[CE,CO]{\slshape{\scshape \thepage}}  % Page numbers with my defined style
\renewcommand{\headrulewidth}{0pt}%
}
\fancypagestyle{nonTOCplain}{%
\fancyhf{} 
\fancyhead[LE,RO]{\itshape \thepage}
\renewcommand{\headrulewidth}{0pt}%
}
\fancypagestyle{TOCplain}{%
\fancyhf{} 
\fancyhead[RE]{\nouppercase{\slshape \leftmark}}
\fancyhead[LO]{\nouppercase{\slshape \lastrightmark}}
\fancyhead[LE,RO]{\slshape{\scshape \thepage}}  % Page numbers with my defined style
\renewcommand{\headrulewidth}{0.4pt}%
}
% 
% the pages of the ToC/LoF/LoT are numbered Lowercase Roman 
\let\myTOC\tableofcontents
\renewcommand\tableofcontents{%
 \pagenumbering{roman}   % I don't want "Roman" because there are too big letters!
 \thispagestyle{plain}
 \myTOC%
}
%
\makeatother
%
\begin{document}
%
\thispagestyle{plain}
%\addcontentsline{toc}{section}{Indice Generale}
\addtocontents{toc}{\protect\contentsline{section}{Indice
    Generale}{{\bfseries\scshape\thepage}}}

% in case hyperref is loaded use rather:
% \makeatletter
% \addtocontents{toc}{\protect\contentsline{section}{Indice
%     Generale}{{\bfseries\scshape\thepage}}{\@currentHref }}
% \makeatother

\tableofcontents{}
\clearpage{}
%
\thispagestyle{TOCplain}
\cleardoublepage{}
%
\thispagestyle{TOCplain}
%\addcontentsline{toc}{section}{Elenco delle Figure}
\addtocontents{toc}{\protect\contentsline{section}{Elenco delle
    Figure}{{\bfseries\scshape\thepage}}} 
% if hyperref:
% \makeatletter
% \addtocontents{toc}{\protect\contentsline{section}{Elenco delle
%     Figure}{{\bfseries\scshape\thepage}}{\@currentHref }} 
% \makeatother

\listoffigures
\clearpage{}
%
\thispagestyle{TOCplain}
\cleardoublepage{}
\pagenumbering{arabic}
%
\thispagestyle{nonTOCplain}
\section{Introduzione}
\lipsum[1]
%
\cleardoublepage{}
%
\thispagestyle{nonTOCplain}
\section{Prima sezione }
\lipsum[3]
\subsection{Prima sottosezione }
\lipsum[3]
%
\end{document}

page numbers in toc

2
  • I think the lines suggested are to be used with hyperref, so I'll edit my question to add the hyperref requirements (by the way the code works great without the above mentioned package)
    – TheVal
    Sep 7, 2013 at 9:46
  • I have copied your hyperref loading to the code in my answer. What to do in that case with hyperref is indicated in the commented out parts of the code.
    – user4686
    Sep 7, 2013 at 9:56
2

After receiving the needed advices I came up with the final code edited only to create this particular macro that follows hyperref with the conditional \@ifpackageloaded:

\@ifpackageloaded{hyperref}{%
 \newcounter{forfunnysections}%
 \newcommand{\addtoMYcontents}[3]{% 
  \addtocontents{#1}{%
   \protect\contentsline{#2}{#3}{{\bfseries\scshape\thepage}}{\@currentHref}%
  }\stepcounter{forfunnysections}\pdfbookmark[1]{#3}{funny.\arabic{forfunnysections}}%
 }%
}{%
 \newcommand{\addtoMYcontents}[3]{% 
  \addtocontents{#1}{%
   \protect\contentsline{#2}{#3}{{\bfseries\scshape\thepage}}%
  }%
 }%  
}

In order to write someting similar to the previous command:

\addcontentsline{toc}{section}{Elenco delle Figure}  % old command
%
\addtoMYcontents{toc}{section}{Elenco delle Figure}  % new command, with or without Hyperref

With this solution the preamble is not greatly altered and those sequences can be used easily to substitute the old command, giving now a more coherent typesetting inside the ToC.

Here is the final code:

\documentclass[11pt,a4paper,twoside,british,italian]{article}
%
\usepackage[T1]{fontenc}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{babel}
\usepackage{lipsum}
%
\usepackage[unicode=true,
 bookmarks=true,bookmarksnumbered=true,bookmarksopen=false,
 breaklinks=false,pdfborder={0 0 1},backref=false,colorlinks=true]
{hyperref}
%
\makeatletter
% Newly defined command for Hyperref/Correct symbols
\@ifpackageloaded{hyperref}{%
 \newcounter{forfunnysections}% 
 \newcommand{\addtoMYcontents}[3]{% 
  \addtocontents{#1}{%
   \protect\contentsline{#2}{#3}{{\bfseries\scshape\thepage}}{\@currentHref}%
  }\stepcounter{forfunnysections}\pdfbookmark[1]{#3}{funny.\arabic{forfunnysections}}%
 }%
}{%
 \newcommand{\addtoMYcontents}[3]{% 
  \addtocontents{#1}{%
   \protect\contentsline{#2}{#3}{{\bfseries\scshape\thepage}}%
  }%
 }%  
}
%
% define the page style, note \pagestyle{fancy} already in the preamble
\renewcommand{\sectionmark}[1]{\markboth{Sezione\ \thesection.\ #1}{}}
\renewcommand{\subsectionmark}[1]{\markright{#1}}
\fancyhf{}
\fancyhead[RE]{\nouppercase{\slshape \leftmark}}
\fancyhead[LO]{\nouppercase{\slshape \lastrightmark}}
\fancyhead[LE,RO]{\itshape \thepage}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0pt}
%
% create new \fancypagestyles in respect to short sections
\usepackage{slantsc}
\usepackage{extramarks} 
%
\fancypagestyle{plain}{%
\fancyhf{} 
\fancyfoot[CE,CO]{\slshape{\scshape \thepage}}  % Page numbers with my defined style
\renewcommand{\headrulewidth}{0pt}%
}
\fancypagestyle{nonTOCplain}{%
\fancyhf{} 
\fancyhead[LE,RO]{\itshape \thepage}
\renewcommand{\headrulewidth}{0pt}%
}
\fancypagestyle{TOCplain}{%
\fancyhf{} 
\fancyhead[RE]{\nouppercase{\slshape \leftmark}}
\fancyhead[LO]{\nouppercase{\slshape \lastrightmark}}
\fancyhead[LE,RO]{\slshape{\scshape \thepage}}  % Page numbers with my defined style
\renewcommand{\headrulewidth}{0.4pt}%
} 
%  
% the pages of the ToC/LoF/LoT are numbered Lowercase Roman 
\let\myTOC\tableofcontents
\renewcommand\tableofcontents{%
 \pagenumbering{roman}   % I don't want "Roman" because there are too big letters!
 \thispagestyle{plain}
 \myTOC%
}
%
\makeatother
%
\begin{document}
%
\thispagestyle{plain}
\addtoMYcontents{toc}{section}{Indice Generale}
\tableofcontents{}
\clearpage{}
%
\thispagestyle{TOCplain}
\cleardoublepage{}
%
\thispagestyle{TOCplain}
\addtoMYcontents{toc}{section}{Elenco delle Figure}
\listoffigures
\clearpage{}
%
\thispagestyle{TOCplain}
\cleardoublepage{}
\pagenumbering{arabic}
%
\thispagestyle{nonTOCplain}
\section{Introduzione}
\lipsum[1]
%
\cleardoublepage{}
%
\thispagestyle{nonTOCplain}
\section{Prima sezione }
\lipsum[3]
\subsection{Prima sottosezione }
\lipsum[3]
%
\end{document}

The result given is as follows:

enter image description here

12
  • one subtle point I passed under silence is that if you do a pdf and view the file in a viewer, the bookmarks will not have references to Indice Generale... this is because hyperref patches \addcontentsline but it does not patch \addtocontents and the patch does the thing for the bookmarks.
    – user4686
    Sep 7, 2013 at 11:17
  • So to being able to connect the bookmarks neither phantomsection would work in this case. At this point is there any substitutible command to obtain the Indice Generale on the PDF bookmarks?
    – TheVal
    Sep 7, 2013 at 11:34
  • Yes, add to your macro in the hyperref case: \pdfbookmark[1]{#3}{#3}.
    – user4686
    Sep 7, 2013 at 12:00
  • The code now works but could you please tell me if the edit I've done is now correct? I'm asking this because I don't know if there are more correct potitions to place this specific string.
    – TheVal
    Sep 7, 2013 at 12:11
  • You should move \pdfbookmark[1]{#3}{#3} after the closing brace of the \addtocontents. Besides my suggestion is only if nothing fancy is in your section title: no èà... else the second #3 should rather be something like funny.\arabic{mycounter} where mycounter is a LaTeX counter to be incremented by your macro. (I must check now...)
    – user4686
    Sep 7, 2013 at 12:13
1

You can use \pagenumbering{Roman} and correctly issue \lowercase in the headers:

\documentclass[11pt,twoside,british,italian]{article}
%
\usepackage[T1]{fontenc}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{babel}
\usepackage{lipsum}
%
\usepackage[unicode=true,
bookmarks=true,bookmarksnumbered=true,bookmarksopen=false,
breaklinks=false,pdfborder={0 0 1},backref=false,colorlinks=true]
{hyperref}
%
\makeatletter
%
% define the page style, note \pagestyle{fancy} already in the preamble
\renewcommand{\sectionmark}[1]{\markboth{Sezione\ \thesection.\ #1}{}}
\renewcommand{\subsectionmark}[1]{\markright{#1}}
\fancyhf{}
\fancyhead[RE]{\nouppercase{\slshape \leftmark}}
\fancyhead[LO]{\nouppercase{\slshape \lastrightmark}}
\fancyhead[LE,RO]{\itshape \thepage}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0pt}

% create new \fancypagestyles in respect to short sections
\usepackage{slantsc}
\usepackage{extramarks} 
%
\fancypagestyle{plain}{%
\fancyhf{} 
\fancyfoot[CE,CO]{\slshape{\scshape \thepage}}  % Page numbers with my defined style
\renewcommand{\headrulewidth}{0pt}%
}
\fancypagestyle{nonTOCplain}{%
\fancyhf{} 
\fancyhead[LE,RO]{\itshape \thepage}
\renewcommand{\headrulewidth}{0pt}%
}
\fancypagestyle{TOCplain}{%
\fancyhf{} 
\fancyhead[RE]{\nouppercase{\slshape \leftmark}}
\fancyhead[LO]{\nouppercase{\slshape \lastrightmark}}
\fancyhead[LE,RO]{\slshape{\scshape \expandafter\lowercase\expandafter{\thepage}}}  % Page numbers with my defined style
\renewcommand{\headrulewidth}{0.4pt}%
}
% 
% the pages of the ToC/LoF/LoT are numbered Lowercase Roman 
\let\myTOC\tableofcontents
\renewcommand\tableofcontents{%
 \pagenumbering{Roman}   % I don't want "Roman" because there are too big letters!
 \thispagestyle{plain}
 \myTOC%
}
%
\makeatother
%
\begin{document}
%
\thispagestyle{plain}
\addcontentsline{toc}{section}{Indice Generale}
\tableofcontents{}
\clearpage{}
%
\thispagestyle{TOCplain}
\cleardoublepage{}
%
\thispagestyle{TOCplain}
\addcontentsline{toc}{section}{Elenco delle Figure}
\listoffigures
\clearpage{}
%
\thispagestyle{TOCplain}
\cleardoublepage{}
\pagenumbering{arabic}
%
\thispagestyle{nonTOCplain}
\section{Introduzione}
\lipsum[1]
%
\cleardoublepage{}
%
\thispagestyle{nonTOCplain}
\section{Prima sezione }
\lipsum[3]
\subsection{Prima sottosezione }
\lipsum[3]
%
\end{document}
5
  • That's an answer that gives not the Small Caps font for the page number inside the ToC, as my question was related to this transformation in the first place; but still +1 for the time you spent thinking of a solution.
    – TheVal
    Sep 7, 2013 at 9:51
  • @tochecz looks as if your comment is in reply to the comment posted by AndreaL below my answer, not yours ?
    – user4686
    Sep 7, 2013 at 9:59
  • @jfbu Damn, you're correct! I'll delete it.
    – yo'
    Sep 8, 2013 at 11:23
  • @AndreaL. Well, in my opinion, the logical thing is that you want "Roman" just looking as "small-caps roman", which is what I do. Or when you refer to the page by \pageref, you want it to show iii instead of III?
    – yo'
    Sep 8, 2013 at 11:48
  • This turned out just like you said, as I wrote my personal answer to my next related question
    – TheVal
    Sep 8, 2013 at 11:51

You must log in to answer this question.

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