平均能量损失

平均能量损失

在我的 .tex 文档中,我使用带有 \sffamily 的无衬线字体。(而且我不希望它是等宽字体!)

对于我的 algpseudocode,我尝试使用 \texttt。(因为我想使用衬线等宽字体。)

请看一下这个最小的例子

\documentclass[a4paper,10pt,english]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[a4paper,margin=2.5cm,footskip=0.5cm]{geometry}
\usepackage{algpseudocode}

\title{Example Document}

\begin{document}
\sffamily

\section{some content}
So, that's what my written content looks like. Sans-serif. Pretty nice, eh?

\texttt %When I remove this line, no error at all!

\begin{algorithmic}
\State x = 0
\While{x < 10}
  \State x = x+1
\EndWhile
\end{algorithmic}

\sffamily

But for some reason, this doesn't work.

\end{document}

我总是保留这些错误:

monospace-algorithm.tex:19: Paragraph ended before \text@command was complete. []
monospace-algorithm.tex:19: Too many }'s. []
  • 什么是\text@command
  • 我数了一下}{。它们的数量似乎正确。

  • 这些是从哪里来的?

  • 如何使伪代码等宽?(我更喜欢使用标准命令\sffamily而不是字体。)

答案1

algorithm包含一个钩子,您可以重新定义它以将字体设置为等宽字体。

与 moewe 的评论一致,您可以使用该lmodern包来获取粗体等宽字体。

把这写在你的序言中:

% needed for bold tt font
\usepackage[lighttt]{lmodern}
% use sans serif by default
\renewcommand{\familydefault}{\sfdefault}
% use ttfamily for algorithm
\makeatletter
\algrenewcommand\ALG@beginalgorithmic{\ttfamily}
\makeatother

平均能量损失

\documentclass[a4paper,10pt,english]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[a4paper,margin=2.5cm,footskip=0.5cm]{geometry}
\usepackage{algpseudocode}

% needed for bold tt font
\usepackage[lighttt]{lmodern}
% use sans serif by default
\renewcommand{\familydefault}{\sfdefault}
% use ttfamily for algorithm
\makeatletter
\algrenewcommand\ALG@beginalgorithmic{\ttfamily}
\makeatother

\title{Example Document}

\begin{document}

\section{some content}
So, that's what my written content looks like. Sans-serif. Pretty nice, eh?

\begin{algorithmic}
\State x = 0
\While{x < 10}
  \State x = x+1
\EndWhile
\end{algorithmic}

Now this works.

\end{document}

在此处输入图片描述

相关内容