
Я использую его 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}
дает следующий результат