现在我正在使用 Overleaf 上的默认章节格式,但我想更改它,以便章节编号比标题大得多,并且位于标题本身之上且与标题本身分开。
目前,我已正确对齐标题(但不是数字),但我似乎无法更改字体或将字体大小增加到当前大小以外。
当前的 MWE,与 Overleaf 上的 titlesec 模板基本相同:
\documentclass[a4paper,12pt]{book}
\usepackage[T1]{fontenc}
\usepackage{titlesec}
\titleformat
{\chapter} % command
[display] % shape
{\bfseries\Large\itshape} % format
%{Story No. \ \thechapter} % label
{\thechapter}
{0.5ex} % sep
{
%\rule{\textwidth}{1pt}
\vspace{1ex}
%\centering
\raggedleft
} % before-code
[
\vspace{-0.5ex}%
%\rule{\textwidth}{0.3pt}
] % after-code
\titleformat{\section}[wrap]
{\normalfont\bfseries}
{\thesection.}{0.5em}{}
\titlespacing{\section}{12pc}{1.5ex plus .1ex minus .2ex}{1pc}
\begin{document}
\chapter{Let's begin}
\section{First Attempt}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
enim ad minim veniam, quis nostrud exercitation ullamco laboris...
\end{document}
我希望它看起来像这样
答案1
尝试一下(并根据需要更改颜色和尺寸):
\documentclass[10pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[italian]{babel}
\usepackage{amsmath}
\usepackage{amsfonts,lmodern}
\usepackage{amssymb}
\usepackage{emptypage,graphicx}
\usepackage{xcolor}
\usepackage{titlesec}
\usepackage{microtype,lipsum}
\titleformat{\chapter}[display]
{\normalfont\bfseries\color{black}}
{\filleft\hspace*{-60pt}%
{\setlength\fboxsep{0pt}%
\colorbox{blue!10}{\parbox[c][3cm][c]{3cm}{%
\centering\color{cyan}\fontsize{80}{70}\selectfont\thechapter}%
}}%
}
{10pt}
{\filleft\LARGE\sffamily}
\begin{document}
\tableofcontents
\chapter{Trip in a new world}
\lipsum[1-2]
\section{One}
\lipsum[3-12]
\setcounter{chapter}{22}
\chapter{The fantastic way of life in the new world}
\lipsum[1-2]
\section{Two}
\lipsum[3-12]
\end{document}
答案2
\documentclass[12pt,a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amsfonts,lmodern}
\usepackage{amssymb}
\usepackage{emptypage,graphicx}
\usepackage{xcolor}
\usepackage{titlesec}
\usepackage{microtype,lipsum}
\titleformat{\chapter}[display]
{\LARGE\bfseries\sffamily}
{\filleft\hspace*{-60pt}{\Huge\colorbox{white}{\parbox[c][3cm][c]{3cm}{\color{orange}\fontsize{3cm}{1cm}\selectfont\centering\thechapter}}}}
{10pt}{\LARGE\filleft}
\begin{document}
\chapter{Trip in a new world}
\end{document}
答案3
它比其他答案所暗示的要简单。
\documentclass[a4paper,12pt]{book}
\usepackage[T1]{fontenc}
\usepackage{fix-cm}
\usepackage{titlesec}
\usepackage{xcolor}
\definecolor{chapternumber}{RGB}{239,107,28}
\newcommand{\makebignumber}[1]{%
\textcolor{chapternumber}{\fontsize{80}{0}\bfseries #1}%
}
\titleformat{\chapter}[display]
{\filleft} % format
{\makebignumber{\thechapter}}
{2ex}
{\Large}
\titleformat{\section}[wrap]
{\normalfont\bfseries}
{\thesection.}
{0.5em}
{}
\titlespacing{\section}{12pc}{1.5ex plus .1ex minus .2ex}{1pc}
\begin{document}
\chapter{Let's begin}
\section{First Attempt}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
enim ad minim veniam, quis nostrud exercitation ullamco laboris...
\end{document}
fix-cm
如果您使用像图像中那样完全可扩展的字体,则不需要。