具有默认字体的环境,其他文本为 \textsf

具有默认字体的环境,其他文本为 \textsf

我想将文档的字体设置为 生成的字体\textsf{},但在定义和定理等环境中保留默认字体。我尝试声明

\documentclass[a4paper,12pt]{book} 
\usepackage{amsthm}
\renewcommand{\familydefault}{\sfdefault}
\newtheorem{defi}{Definition}[chapter]
\newtheoremstyle{defi}% name
{3pt}% Space above
{3pt}% Space below
{crm}% Body font
{}% Indent amount
{\itshape}% Theorem head font
{:}% Punctuation after theorem head
{.5em}% Space after theorem head
{}% Theorem head spec (can be left empty, meaning ‘normal’)

\begin{document}

\begin{defi} Text with default font. \end{defi}

Text in sans-serif font.

\end{document}

但它不起作用,因为字体被定义为无衬线字体覆盖整个文本。我想知道我上面提到的正文字体是否正确。如果有人能给我一点提示,我将不胜感激。有人建议我不要使用这种无衬线字体来排版我的文档。所以,我想要一些建议。提前谢谢!

答案1

至少存在以下几个问题:

  • 字体应指定为\rmfamily,而不是cmr

  • 您必须在声明之前调用您的新样式\newtheorem

尝试这个:

% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly 
                                 % declare the paper format.

\usepackage[T1]{fontenc}         % Not always necessary, but recommended.
% End of standard header.  What follows pertains to the problem at hand.

\usepackage{amsmath,amsthm}

\renewcommand{\familydefault}{\sfdefault}

\newtheoremstyle{defi}% name
    {3pt}% Space above
    {3pt}% Space below
    {\rmfamily}% Body font
    {}% Indent amount
    {\rmfamily\itshape}% Theorem head font
    {:}% Punctuation after theorem head
    {.5em}% Space after theorem head
    {}% Theorem head spec (can be left empty, meaning "normal")

\theoremstyle{defi}
\newtheorem{defi}{Definition}[section] % not "chapter" because I'm using the 
                                       % "article" document class



\begin{document}

\section{A title}

Some text before the first definition: this text should be in ``sans-serif''.

\begin{defi}
    This is a definition, and it should be in \verb|\rmfamily| (that is, 
    \emph{with} serifs).
\end{defi}

Some text after the definition, again in \verb|\sffamily|.

\end{document}

你可以自己检查一下结果是否只是糟糕的排版:

代码输出

确实,用无衬线字体排版一篇文章(或者更糟的是,一份报告:你用的是章节,不是吗?)本身就已经值得怀疑了;但要设置,之内这样的文档,带有衬线的定义……

相关内容