You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Overleaf LaTeX中使用TTF文件设置全局标准字体方案

更新说明

目前大部分问题已修复:首先完成了TTF字体的导入配置,后续排查解决了所有标题相关的格式异常问题,文末附可直接运行的最终实现代码。


步骤1/3:初始需求

需要修改Overleaf平台LaTeX测试文档的默认标准字体,现有参考示例必须通过自定义命令才能调用TTF字体,无法满足将TTF字体设置为全文档所有位置默认字体的需求。
初始测试代码如下:

% 自定义TTF字体调用参考示例
% 示例使用的自定义字体为LoKinderSchrift
\documentclass{article}

\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}

\newcommand\customfont[1]{{\usefont{T1}{custom}{m}{n} #1 }}

\title{Example: Custom Font}
\author{writeLaTeX}

\begin{document}
\maketitle

Normal Font Text.

\Huge\customfont{Custom Font Text!}

\end{document}

步骤2/3:导入后遇到的格式问题

目前已成功将TTF字体导入文档,但存在以下待解决的格式异常:

  • 章节编号的字号相比正文偏小
  • 章节编号末尾存在多余的句点需要删除
  • 需要将章节名称设置为加粗效果

经测试目录显示效果正常。
该阶段调试代码如下:

% !TeX TS-program = xelatex

\documentclass{report}

\usepackage[german]{babel}
%\usepackage[utf8x]{inputenc} % 不建议使用`utf8x`编码

%\newcommand\customfont[1]{{\usefont{T1}{custom}{m}{n} #1 }}
\usepackage{titlesec}
\titleformat{\chapter}[hang]{\Huge\bfseries}{\thechapter{. }}{0pt}{\Huge\bfseries}


\usepackage{fontspec}
\setmainfont{test.ttf}

\title{Example: Custom Font}
\author{writeLaTeX}

\begin{document}

\maketitle

\tableofcontents

\chapter{Testchapter}
How to delete the point before the chapter?

The NUMBER looks smaller than the TEXT ?!
WHY?
\section{testsection}
this is a section test
Normal Font Text.
\section{testsection}
this is a section test
Normal Font Text.
\section{testsection}
this is a section test
Normal Font Text.
\section{testsection}
this is a section test
Normal Font Text.
It
\chapter{Testchapter}
How to delete the point before the chapter?
Why 
this is a chaptertext
\section{testsection}
this is a section test
Normal Font Text.
\section{testsection}
this is a section test
Normal Font Text.
\section{testsection}
this is a section test
Normal Font Text.
\section{testsection}
this is a section test
Normal Font Text.
It
\end{document}

步骤3/3:最终解决方案

通过调整文档类和字体配置,可实现TTF字体全局默认生效且无前述格式异常,最终可运行代码如下:

\documentclass[report]{scrreprt} 

\usepackage[fontsize=12pt]{fontsize}

\usepackage[left=6cm,right=1cm,top=1.5cm,bottom=1cm,includeheadfoot]{geometry} 
\usepackage[ngerman]{babel} 
\usepackage{blindtext} 

\usepackage{fontspec}

\setmainfont{test.ttf}
\begin {document} 
\tableofcontents 
\blinddocument 
\end {document}

内容的提问来源于stack exchange,提问作者pgapga

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.28 00:39:18