將 \sffamily 移至 Latex 序言

將 \sffamily 移至 Latex 序言

我正在使用\rmfamily\sffamily在文件中的兩種字體之間切換,一種用於部分,另一種用於文字的其餘部分。但是,我無法找到一種方法來移動我的\sffamily命令\begin{document},並且仍然將其應用於節標題之外的文字。我怎麼能在我的序言中包含\sffamily它可以做到這一點?

\documentclass[{12pt}]{article}

%import font styles Play for headers and Lato for body
\usepackage{Play} 
\usepackage[defaultsans]{lato} 

\usepackage{titlesec}

\titleformat{\section}{\rmfamily}{{}}{0em}{}

\begin{document}    

\sffamily
    
\section{Section}
words words words
        
\end{document}

答案1

\documentclass{article}

%import font styles Play for headers and Lato for body
\usepackage{Play} 
\usepackage[defaultsans]{lato} 
\renewcommand\familydefault{\sfdefault}%% <===== 

\usepackage{titlesec}

\titleformat{\section}{\rmfamily}{{}}{0em}{}

\begin{document}    
    
    \section{Section}
    words words words
    
\end{document}

答案2

使用default,不使用defaultsans

\documentclass[12pt]{article}

%import font styles Play for headers and Lato for body
%\usepackage{Play}
\usepackage[default]{lato}

\usepackage{titlesec}

\titleformat*{\section}{\rmfamily\bfseries}

\begin{document}

\section{Section}
words words words

\end{document}

在此輸入影像描述

相關內容