答案1
由于您没有提供任何内容MWE
,我假定您正在使用标准类文件和字体,并且是MWE
:
\documentclass{book}
\usepackage[T1]{fontenc}
\begin{document}
This is for test. This is for test. This is for test. This is for
test. This is for test. This is for test. This is for test. This is
for test. \texttt{This is for test}. This is for test.
\end{document}
fonts
同一段落中其他标签可有所不同: \textsf
,等等。
答案2
这里有最少的示例。我建议你在提问时提交最少的示例代码特克斯那么我能否为您的问题提供精确的解决方案?
我用来{}
隔离句子和段落的环境,并为句子提供自己的字体。
\documentclass{article}
\usepackage[T1]{fontenc}
\begin{document}
This document is a sample document to
test font families and font typefaces.{\fontfamily{qcr}\selectfont
This text uses a different font for function().}This document is a sample document to
test font families and font typefaces.
\end{document}
答案3
提供的文本片段显示代码中的命令是逐字给出的。那么为什么不使用命令\verb*
来实现与上述答案相同的效果呢?
\documentclass\[12pt\]{article}
\usepackage\[a4paper,text={18.0cm,26cm},top=2.0cm,left=2.0cm\]{geometry}
\begin{document}
In a text about coding, explaining how code can be used to create programs, macro's, templates and such, it is often required to give a code command in a different font than the rest of the sentence or paragraph as is shown in the text image in the question, where a typewriter font is used inside a serif font text fragment.
There are serveral options to do that. For example the code:
\verb*|{\fontfamily{<fontname>}\selectfont command or coding text}| will set the \textsf{command or coding text} in a different font in midsentence. The same reult can be obtained using commands like \verb*|\textsf| -- printing in a sans serif font, \verb*|\texttt| -- printing in a typewriter font or \verb*|\textrm| --printing in a serif font. Whereas \verb*|\fontfamily{<name>} \selectfont| will give you more freedom about the font used to typeset these parts, the latter trio is always present even when no font is specifically loaded in the preamble, like in this example.
The code words in the provided text fragment are actually set as verbatim. As you can see in the MWE of this example, the command \verb*~\verb*|text|~ is used to change the font of a (group of) words midsentence. \verb*~\verb*|text|~ essentially typesets the text between the bars in typewriter font, so it is equivalent to using \verb*|\texttt{text}|. Note that \verb*|\verb*| doesn't use curly brackets, but a set of characters to denote the start and end of the text to be printen verbatim. In this MWE the characters bar and tilde are used to do that.
\end{document}