
我正在XeTeX
編輯一個我試圖使用的文檔,titlesec
並titling
為某些標題設定不同的字體。
我正在使用建議的方法回覆類似問題,但到目前為止我的成功確實是局部的。
和標題section
會subsection
根據需要更改字體,但chapter
標題會忽略該設定。
這是我的程式碼片段
%%% to allow custom headings
\usepackage{titlesec}
% to change titles font family
\usepackage{titling}
%%% declare fonts and set some formats
% fontspec to use non-latex with xetex
\usepackage{xunicode}
\usepackage{fontspec}
\usepackage{xltxtra}
% font declaration and title settings
\newfontfamily\headingfont[]{Armata}
\titleformat{\chapter}{\LARGE\headingfont}
\titleformat*{\section}{\LARGE\headingfont}
\titleformat*{\subsection}{\Large\headingfont}
\renewcommand{\maketitlehooka}{\headingfont}
章節設定是我在模仿上面連結中提供的解決方案時嘗試的。我了解到,以*
某種方式需要刪除 ,因為easy mode
不適用於章節標題。我還沒找到原因。但事實是,刪除星號也可以消除錯誤......但它似乎對字體設定不起作用。
有任何想法嗎?
謝謝 :)
編輯:我發現了一個非常愚蠢的錯誤,這導致我找到了(部分)解決方案並出現了一個新錯誤。我剛剛設置\documentclass{book}
,現在渲染器嘗試放置所需的字體,但titlesec
拋出錯誤:
Titles must not be nested
LaTeX 程式碼是這樣的:
\begin{document}
\chapter{First Chapter}
The title above does not show any font.
\section{First Section}
Works as desired.
\subsection{Subsection}
Hiya! This also shows up as expected.
\subsubsection{Subsubsection}
We have not declared a titleformat for this heading, and so it is shown with the default font.
\section{Second section}
Repeating the success
\end{document}
標題chapter
是觸發 titlesec 錯誤的標題。
答案1
線路
\titleformat{\chapter}{\LARGE\headingfont}
是罪魁禍首。語法錯誤。正確的一個是
\titleformat{\chapter}[display]
{\huge\headingfont}{\chaptertitlename\ \thechapter}{20pt}{\Huge}
因此,MWE(我使用 Arial 而不是 Armata,因為我沒有安裝該字體):
\documentclass{book}
%%% to allow custom headings
\usepackage{titlesec}
% to change titles font family
\usepackage{titling}
%%% declare fonts and set some formats
% fontspec to use non-latex with xetex
\usepackage{xunicode}
\usepackage{fontspec}
\usepackage{xltxtra}
% font declaration and title settings
\newfontfamily\headingfont[]{Arial}
\titleformat{\chapter}[display]
{\huge\headingfont}{\chaptertitlename\ \thechapter}{20pt}{\Huge}
\titleformat*{\section}{\LARGE\headingfont}
\titleformat*{\subsection}{\Large\headingfont}
\renewcommand{\maketitlehooka}{\headingfont}
\begin{document}
\chapter{First Chapter}
The title above does not show any font.
\section{First Section}
Works as desired.
\subsection{Subsection}
Hiya! This also shows up as expected.
\subsubsection{Subsubsection}
We have not declared a titleformat for this heading, and so it is shown with the default font.
\section{Second section}
Repeating the success
\end{document}
產生以下輸出