我的字体是等宽字体,Latex 会将其视为等宽字体吗,或者我该怎么办?

我的字体是等宽字体,Latex 会将其视为等宽字体吗,或者我该怎么办?

我有一个自定义的等宽字体。我想用它写整篇文档。执行 Lorem Ipsum 的输出显示我的等宽字体没有被渲染为等宽字体(即某些字符宽度被挤压,可能是由于线条渲染算法)。我需要在 LaTeX 端进行哪些配置才能使其正常工作?我正在使用 XeLaTeX。

\documentclass[a4paper,12pt]{article}
\usepackage{fontspec}
\usepackage{fullpage}
\setmainfont{MyFont}
\begin{document}
Hello world hello world Hello world hello world Hello world hello world Hello world hello worldHello world hello world Hello world hello worldHello world hello worldHello world hello world Hello world hello world Hello world hello world Hello world hello world Hello world hello world.
\end{document}

我想自定义每页有多少行,每行有多少个字符(因为它是等宽的),或者至少设置一个字体大小并让整个文档以该大小等宽。

答案1

使用fullpage无法设置每行字符数或每页行数。您可以使用 来设置geometry

然而,对齐会使字符不垂直对齐,因为通常不可能有一行包含精确的字符数(包括空格)。如果要垂直对齐,则需要\raggedright\frenchspacing

在示例中,我设置每行 72 个字符(最多),每页 48 行。

\documentclass[a4paper,12pt]{article}
\usepackage{fontspec}
\usepackage{geometry}

\usepackage{kantlipsum}

\setmainfont{Latin Modern Mono}

\newlength{\characterwidth}
\settowidth{\characterwidth}{\normalfont x}
\geometry{textwidth=72\characterwidth,lines=48}
\AtBeginDocument{\raggedright\setlength{\parindent}{3\characterwidth}}
\frenchspacing

\begin{document}

\kant[1-4]

\end{document}

在此处输入图片描述

第一行用方框包围文本块,可以更清楚地显示问题所在:

在此处输入图片描述

如您所见,前两行在边缘结束,但第三行比 72 个字符少两个字符;即使使用连字符,下一个单词也放不下,因为空格算一个字符,而连字符算另一个字符。

答案2

请说得更具体一些。至少在间距方面,flushleft避免间距不均匀。

%!TEX program=xelatex
\documentclass[a4paper,12pt]{article}
\usepackage{fontspec}
\usepackage{fullpage}
\setmainfont{DejaVu Sans Mono}
\begin{document}
\begin{flushleft}
Hello world hello world Hello world hello world Hello world hello world Hello world hello world Hello world hello world Hello world hello worldHello world hello worldHello world hello world Hello world hello world Hello world hello world Hello world hello world Hello world hello world.
\end{flushleft}
\end{document}

在此处输入图片描述

关于每页行数,这可能值得你注意: 如何限制一页的最大行数?

相关内容