如何在 ToC 中获得“正确”的罗马数字

如何在 ToC 中获得“正确”的罗马数字

我目前正在为 MiKTeX 2.9 下的 LyX 2.0.6 编写我的第二个论文模板,由于我使用article文档类,所以我必须手动组织 ToC、LoF、LoT 等中的页码。

感谢fancyhdr我在文档主体上排版特定页码时没有遇到任何问题,这些页码将显示在 MWE 中;但是当我开始组织我的 ToC 格式时,我遇到了需要这种帮助的问题。

frontmatter我的目标是在不选择的情况下获得目录内的伪罗马编号pagenumbering{Roman},因为我想使用小型大写字体选择。

MWE如下:

\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}

按照规定,前页有倾斜的小型大写罗马数字

enter image description here

但它们出现在 ToC 内部仅限小写直立罗马字母

enter image description here

我的问题仍然是如何获取目录内的文档正文编号样式,也许使用这个假想的命令:

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

尽管我尝试tocloft使用有用的命令:

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

它只给了我未定义的控制序列,我认为如果 ToC 格式中的每个元素都适应这个包会更可靠;因为我不要使用它我想知道是否有某种方法可以解决这个让我厌烦的问题。


编辑:这是 MWE,添加了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}

答案1

一种方法是\addcontentsline\addtocontents更详细的宏替换你的方法。(在代码注释中:更复杂的情况是使用包超链接已加载)

\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

在收到所需的建议后,我提出了最终的代码编辑,仅创建了这个带有hyperref条件的特定宏\@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}}%
  }%
 }%  
}

为了写一些类似于前面的命令:

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

使用此解决方案,序言不会发生太大改变,并且这些序列可以轻松地用于替代旧命令,从而在目录中提供更连贯的排版。

最终代码如下:

\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}

给出的结果如下:

enter image description here

答案3

您可以在标题中使用\pagenumbering{Roman}并正确发出:\lowercase

\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}

相关内容