我正在尝试将目录中的子部分字体更改为斜体,并已成功做到这一点,就像使用pdflatexmk
适用于 MacOS 的 TeXShop 应用程序排版的 MWE 一样:
%% Define document class with options
\documentclass[12pt,twoside,openright]{report}
\usepackage[T1]{fontenc} % Output font encoding. Standard option.
\usepackage[utf8]{inputenc} % Input font encoding. Standard option.
\usepackage{lipsum}
\usepackage{geometry} % Easy modification of the page layout.
\geometry{a4paper,inner=28mm,outer=25mm,top=25mm,bottom=25mm} % Required layout
\pagestyle{headings} % Standard pagestyle with headers (section/chapter names) and footer (page number)
% Modify chapter headings:
\usepackage{titlesec}
\makeatletter
\def\@makechapterhead#1{%
\vspace*{50\p@}%
{\parindent \z@ \raggedright \normalfont
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
%\huge\bfseries \@chapapp\space \thechapter
\Huge\bfseries \thechapter.\space%
%\par\nobreak
%\vskip 20\p@
\fi
\fi
\interlinepenalty\@M
\Huge \bfseries #1\par\nobreak
\vskip 40\p@
}}
\makeatother
% Make subsection headings boldformat and in italics in text.
\titleformat{\subsection}
{\normalfont\fontsize{14}{12}\bfseries\itshape}{\thesection}{1em}{}
% For subsection TOC headings
\usepackage{titletoc}
\titlecontents{subsection} % set formatting for \section -
[6em] % adjust left margin
{\itshape} % font formatting
{\contentslabel{2.3em}} % section label and offset
{\hspace*{-2.3em}}
{\titlerule*[1pc]{.}\contentspage}
\usepackage[dvipsnames]{xcolor} % Allows text and background colors to be controlled
\usepackage{hyperref}
\hypersetup{ % hyperref package options
pdffitwindow=false, % controls whether window is resized to fit pdf-page when pdf-viewer is opened
pdfstartview={FitV}, % fits the pdf-page to the window when pdf-viwer is opened
pdftitle={My title}, % title for pdf-file properties
pdfauthor={MSc Candidate}, % author for pdf-file properties
pdfsubject={MSc Thesis}, % subject of the document for pdf-file properties
pdfkeywords={keyword1} {keyword2} {keyword3} {keyword4}, % list of keywords for pdf-file properties
pdfnewwindow=true, % links open in new window
linktoc=page, % only page numbers in toc act as links (instead of the whole entry)
colorlinks=true, % false: links are shown as boxes around text; true: links are shown as colored text
linkcolor=BrickRed, % color of internal links (change box color with linkbordercolor). Default: red
}
\begin{document}
\setcounter{tocdepth}{2} % Control the depth of the table of contents entries (1=section, 2=subsection, 3=subsubsection)
\setcounter{secnumdepth}{1}
\cleardoublepage % Start new page for the \addcontentsline{toc} command
\phantomsection % Needed for hyperref to correctly link to the table of contents
\addcontentsline{toc}{section}{Table of Contents} % Add the table of contents to the table of contents at the section level
\tableofcontents % Produce the table of contents
\thispagestyle{plain} % Remove headers from second page of table of contents
\chapter{Chapter heading}
\section{Section heading}
\lipsum[1]
\subsection{Subsection heading in italics}
\end{document}
但是,如图所示,页码和点号也都是斜体。此外,点之间的间距更大。我试图将点号和页码保持在标准格式,即不斜体,并且点之间的间距为标准,但我不知道该怎么做,而且我也没有找到关于这个问题的其他帖子。因此,我希望在这里得到一些帮助。
干杯!
答案1
使用tocloft
包代替titletoc
子部分 ToC 条目。
% tocsubsecprob.tex SE 601868
%% Define document class with options
\documentclass[12pt,twoside,openright]{report}
\usepackage{comment}
\usepackage[T1]{fontenc} % Output font encoding. Standard option.
\usepackage[utf8]{inputenc} % Input font encoding. Standard option.
\usepackage{lipsum}
\usepackage{geometry} % Easy modification of the page layout.
\geometry{a4paper,inner=28mm,outer=25mm,top=25mm,bottom=25mm} % Required layout
\pagestyle{headings} % Standard pagestyle with headers (section/chapter names) and footer (page number)
% Modify chapter headings:
\usepackage{titlesec}
\makeatletter
\def\@makechapterhead#1{%
\vspace*{50\p@}%
{\parindent \z@ \raggedright \normalfont
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
%\huge\bfseries \@chapapp\space \thechapter
\Huge\bfseries \thechapter.\space%
%\par\nobreak
%\vskip 20\p@
\fi
\fi
\interlinepenalty\@M
\Huge \bfseries #1\par\nobreak
\vskip 40\p@
}}
\makeatother
% Make subsection headings boldformat and in italics in text.
\titleformat{\subsection}
{\normalfont\fontsize{14}{12}\bfseries\itshape}{\thesection}{1em}{}
% For subsection TOC headings
\begin{comment}
\usepackage{titletoc}
\titlecontents{subsection} % set formatting for \section -
[6em] % adjust left margin
{\itshape} % font formatting
{\contentslabel{2.3em}} % section label and offset
{\hspace*{-2.3em}}
{\titlerule*[1pc]{.}\contentspage}
\end{comment}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{tocloft}
\renewcommand{\cftsubsecfont}{\itshape}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[dvipsnames]{xcolor} % Allows text and background colors to be controlled
\usepackage{hyperref}
\hypersetup{ % hyperref package options
pdffitwindow=false, % controls whether window is resized to fit pdf-page when pdf-viewer is opened
pdfstartview={FitV}, % fits the pdf-page to the window when pdf-viwer is opened
pdftitle={My title}, % title for pdf-file properties
pdfauthor={MSc Candidate}, % author for pdf-file properties
pdfsubject={MSc Thesis}, % subject of the document for pdf-file properties
pdfkeywords={keyword1} {keyword2} {keyword3} {keyword4}, % list of keywords for pdf-file properties
pdfnewwindow=true, % links open in new window
linktoc=page, % only page numbers in toc act as links (instead of the whole entry)
colorlinks=true, % false: links are shown as boxes around text; true: links are shown as colored text
linkcolor=BrickRed, % color of internal links (change box color with linkbordercolor). Default: red
}
\begin{document}
\setcounter{tocdepth}{2} % Control the depth of the table of contents entries (1=section, 2=subsection, 3=subsubsection)
\setcounter{secnumdepth}{1}
\cleardoublepage % Start new page for the \addcontentsline{toc} command
\phantomsection % Needed for hyperref to correctly link to the table of contents
\addcontentsline{toc}{section}{Table of Contents} % Add the table of contents to the table of contents at the section level
\tableofcontents % Produce the table of contents
\thispagestyle{plain} % Remove headers from second page of table of contents
\chapter{Chapter heading}
\section{Section heading}
\lipsum[1]
\subsection{Subsection heading in italics}
\end{document}
答案2
为了使点和页码保持标准格式,您可以在\normalfont
其前面添加一个。对于点间距问题,我没有弄清楚如何使其行为与 LaTeX 默认行为完全相同,但我添加了一个单独的\titlecontents
for 部分以匹配子部分的点。
\usepackage{titletoc}
\titlecontents{section}
[3.8em]
{}
{\contentslabel{2.3em}}
{\hspace*{-2.3em}}
{\normalfont\titlerule*[.8pc]{.}\contentspage}
\titlecontents{subsection} % set formatting for \section -
[6em] % adjust left margin
{\itshape} % font formatting
{\contentslabel{2.3em}} % section label and offset
{\hspace*{-2.3em}}
{\normalfont\titlerule*[.8pc]{.}\contentspage}
以下是完整的代码。
%% Define document class with options
\documentclass[12pt,twoside,openright]{report}
\usepackage[T1]{fontenc} % Output font encoding. Standard option.
\usepackage[utf8]{inputenc} % Input font encoding. Standard option.
\usepackage{lipsum}
\usepackage{geometry} % Easy modification of the page layout.
\geometry{a4paper,inner=28mm,outer=25mm,top=25mm,bottom=25mm} % Required layout
\pagestyle{headings} % Standard pagestyle with headers (section/chapter names) and footer (page number)
% Modify chapter headings:
\usepackage{titlesec}
\makeatletter
\def\@makechapterhead#1{%
\vspace*{50\p@}%
{\parindent \z@ \raggedright \normalfont
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
%\huge\bfseries \@chapapp\space \thechapter
\Huge\bfseries \thechapter.\space%
%\par\nobreak
%\vskip 20\p@
\fi
\fi
\interlinepenalty\@M
\Huge \bfseries #1\par\nobreak
\vskip 40\p@
}}
\makeatother
% Make subsection headings boldformat and in italics in text.
\titleformat{\subsection}
{\normalfont\fontsize{14}{12}\bfseries\itshape}{\thesection}{1em}{}
% For subsection TOC headings
\usepackage{titletoc}
\titlecontents{section}
[3.8em]
{}
{\contentslabel{2.3em}}
{\hspace*{-2.3em}}
{\normalfont\titlerule*[.8pc]{.}\contentspage}
\titlecontents{subsection} % set formatting for \section -
[6em] % adjust left margin
{\itshape} % font formatting
{\contentslabel{2.3em}} % section label and offset
{\hspace*{-2.3em}}
{\normalfont\titlerule*[.8pc]{.}\contentspage}
\usepackage[dvipsnames]{xcolor} % Allows text and background colors to be controlled
\usepackage{hyperref}
\hypersetup{ % hyperref package options
pdffitwindow=false, % controls whether window is resized to fit pdf-page when pdf-viewer is opened
pdfstartview={FitV}, % fits the pdf-page to the window when pdf-viwer is opened
pdftitle={My title}, % title for pdf-file properties
pdfauthor={MSc Candidate}, % author for pdf-file properties
pdfsubject={MSc Thesis}, % subject of the document for pdf-file properties
pdfkeywords={keyword1} {keyword2} {keyword3} {keyword4}, % list of keywords for pdf-file properties
pdfnewwindow=true, % links open in new window
linktoc=page, % only page numbers in toc act as links (instead of the whole entry)
colorlinks=true, % false: links are shown as boxes around text; true: links are shown as colored text
linkcolor=BrickRed, % color of internal links (change box color with linkbordercolor). Default: red
}
\begin{document}
\setcounter{tocdepth}{2} % Control the depth of the table of contents entries (1=section, 2=subsection, 3=subsubsection)
\setcounter{secnumdepth}{1}
\cleardoublepage % Start new page for the \addcontentsline{toc} command
\phantomsection % Needed for hyperref to correctly link to the table of contents
\addcontentsline{toc}{section}{Table of Contents} % Add the table of contents to the table of contents at the section level
\tableofcontents % Produce the table of contents
\thispagestyle{plain} % Remove headers from second page of table of contents
\chapter{Chapter heading}
\section{Section heading}
\lipsum[1]
\subsection{Subsection heading in italics}
\end{document}