如何用titlesec设置LaTeX章节标题为12号粗体?
解决方法
要实现所有章节标题12pt粗体的需求,直接通过titlesec包重新定义chapter、section、subsection的格式即可,以下是修改后的完整代码及关键说明:
关键修改点
- 重新定义
chapter格式:去掉默认章节编号,标题转为大写(匹配你给出的示例),设置为12pt粗体 - 重新定义
section和subsection格式:保留编号,统一设置为12pt粗体 - 修正原代码中
center环境的语法错误(多余的闭合大括号)
修改后的完整代码
\documentclass[12pt]{report} % 文档基础字号已设为12pt \usepackage{graphicx} % 插入图片 \usepackage{geometry} % 调整边距 \usepackage{setspace} % 设置行间距 \usepackage{lipsum} % 生成示例文本 \usepackage[T1]{fontenc} \usepackage{etoolbox} \makeatletter \patchcmd{\@maketitle}{\LARGE}{\Large}{}{} \makeatother \usepackage{titlesec} % 定义chapter格式:无编号、大写、12pt粗体 \titleformat{\chapter}[display] {\normalfont\bfseries} % 12pt粗体(文档基础字号12pt,normalfont即12pt) {} % 取消章节编号 {0pt} % 编号与标题的间距 {\MakeUppercase} % 标题转为大写 % 定义section格式:带编号、12pt粗体,编号与标题间距1em \titleformat{\section}[hang] {\normalfont\bfseries} {\thesection} {1em} {} % 定义subsection格式:带编号、12pt粗体,编号与标题间距1em \titleformat{\subsection}[hang] {\normalfont\bfseries} {\thesubsection} {1em} {} % 可选:调整标题与正文的间距,按需修改 \titlespacing*{\chapter}{0pt}{50pt}{20pt} \titlespacing*{\section}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex} \titlespacing*{\subsection}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex} \usepackage[version=4]{mhchem} % 化学公式 \usepackage{booktabs} % 表格美化 \usepackage[tableposition=top]{caption} % 表格标题置顶 \usepackage{enumerate} % 自定义列表编号 \setcounter{secnumdepth}{2} % 开启到subsection的编号 \usepackage{natbib} % 引用 \setcitestyle{plainnat,open={(},close={)}} \usepackage{fontspec} % 设置字体 \setmainfont{Times New Roman} \usepackage{indentfirst} % 首行缩进 % 边距设置 \newgeometry{ top = 1in, bottom = 1in, outer = 1in, inner = 1in } \doublespacing \begin{document} \vspace*{\fill} \begingroup \begin{center} \pagenumbering{gobble} my awesome title \\ Submitted in partial fulfillment \\ of the requirements for the degree of \\ super smart person \\ in cool science stuff \\ at \\ school of cool science stuff \\ nice university \\ month 2024 \end{center} \endgroup \vspace*{\fill} % 测试示例 \chapter{CHAPTER NAME} \section{Section} \lipsum[1] \subsection{Subsection} \lipsum[2] \end{document}
说明
- 文档基础字号已通过
\documentclass[12pt]{report}设置为12pt,因此标题使用\normalfont\bfseries即可实现12pt粗体 \MakeUppercase用于将chapter标题转为大写,若不需要大写可直接去掉该命令,改为{}titlespacing命令用于调整标题与上下内容的间距,可根据需求自行修改数值
内容的提问来源于stack exchange,提问作者wingardium_leviosa98
相关产品推荐
相关产品推荐

