我有以下代码:
\documentclass{book}
\usepackage{fontspec}
\begin{document}
\part{title}
\chapter{\fontspec{Latin Modern Roman} chapter title}
\part{title}
\chapter{title}
\end{document}
我使用包字体规格切换字体。如本代码所示,我想使用字体排版章节标题拉丁现代罗马。实际上,它适用于报告和回忆录类。但它会产生一个错误书类。我该如何修复它?
答案1
使用scrbook
KOMA-Script 的 -class:
所有标题(章节、部分等)均采用衬线字体
\documentclass{scrbook}
\usepackage{fontspec}
\addtokomafont{disposition}{\rmfamily}
\begin{document}
\chapter{Hello World}
Test
\end{document}
或者使用 fontspec 明确设置字体:
\documentclass{scrbook}
\usepackage{fontspec}
\newfontfamily{\headingsfont}{Latin Modern Roman}
\addtokomafont{disposition}{\headingsfont}
\begin{document}
\chapter{Hello World}
Test
\end{document}
如果标准衬线字体是 Latin Modern Roman,则结果是相同的,您可以使用以下方式设置\setromanfont{<fontname>}
:
如果您只想更改某些结构元素,请使用例如\addtokomafont{chapter}{}
或\addtokomafont{section}{}
等:
\documentclass[open=any]{scrbook}
\usepackage{fontspec}
\setmainfont{Tex Gyre Pagella}
\newfontfamily{\partnumfont}{Comic Sans MS}
\newfontfamily{\partfont}{Latin Modern Roman}
\newfontfamily{\chapterfont}{Tex Gyre Chorus}
\newfontfamily{\sectionfont}{Tex Gyre Heros}
\usepackage{xcolor}
\addtokomafont{partnumber}{\color{red}\partnumfont}
\addtokomafont{part}{\partfont}
\addtokomafont{chapter}{\chapterfont}
\addtokomafont{section}{\sectionfont}}
\begin{document}
\part{Test}
\section{my first Koma-Script book}
\end{document}
使用标准book
类和包titlesec
:
您可能需要调整设置。
\documentclass{book}
\usepackage{fontspec}
\setmainfont{Tex Gyre Pagella}
\newfontfamily{\partfont}{Tex Gyre Heros}
\newfontfamily{\chapterfont}{Tex Gyre Chorus}
\newfontfamily{\sectionfont}{Tex Gyre Heros}
\usepackage{xcolor}
\usepackage{titlesec}
\titleformat{\part}[display]{\partfont\Huge\bfseries\centering}{\partname\ \thepart}{20pt}{}
\titleformat{\chapter}{\chapterfont\huge\bfseries}{\chaptername\ \thechapter}{20pt}{}
\titleformat{\section}{\sectionfont\large\bfseries}{\thesection}{20pt}{}
\begin{document}
\part{Test}
\chapter{Hello Worl.}
\section{standard book}
Hello World!
\end{document}
答案2
我使用该xpatch
包挂接到排版章节标题的命令。这将更改所有章节的字体。
\documentclass{book}
\usepackage{fontspec,xpatch}
\makeatletter
\xpatchcmd{\@makechapterhead}{\normalfont}{\fontspec{Latin Modern Roman}}{}{}
\makeatother
\begin{document}
\part{title}
\chapter{chapter title}
\part{title}
\chapter{title}
\end{document}
我们可以使用此解决方案轻松地调整每章的字体
\documentclass{book}
\usepackage{fontspec,xpatch}
\newcommand*\setchapterfont[1]{\xdef\chapterfont{#1}}
\setchapterfont{Latin Modern Roman}
\makeatletter
\xpatchcmd{\@makechapterhead}{\normalfont}{\fontspec\chapterfont}{}{}
\makeatother
\begin{document}
\setchapterfont{Latin Modern Sans}
\chapter{Test 1}
\setchapterfont{TeX Gyre Heros}
\chapter{Test 2}
\setchapterfont{TeX Gyre Schola}
\chapter{Test 3}
\end{document}
和memoir
\documentclass{memoir}
\usepackage{fontspec,blindtext}
\newcommand*\setchapterfont[2][]{
\renewcommand*\chapnamefont{\huge\bfseries\fontspec[#1]{#2}}
\renewcommand*\chapnumfont{\huge\bfseries\fontspec[#1]{#2}}
\renewcommand*\chaptitlefont{\Huge\bfseries\fontspec[#1]{#2}}
}
\newcommand*\setsectionfont[2][]{
\setsecheadstyle{\Large\bfseries\fontspec[#1]{#2}}
}
\newcommand*\setsubsectionfont[2][]{
\setsubsecheadstyle{\large\bfseries\fontspec[#1]{#2}}
}
\newcommand*\setsubsubsectionfont[2][]{
\setsubsubsecheadstyle{\normalsize\bfseries\fontspec[#1]{#2}}
}
\begin{document}
\setchapterfont{Latin Modern Sans}
\setsectionfont[Numbers=OldStyle]{TeX Gyre Cursor}
\setsubsectionfont[Color=009911]{Linux Libertine O}
\setsubsubsectionfont{Raleway}
\blinddocument
\end{document}