当我将字体从默认更改为 pcr 时(通过遵循此答案这里)似乎我的文本失去了对齐(两端对齐)并且文本覆盖了边距。
这是一个最小的工作示例:
\documentclass{article}
\usepackage{geometry, ragged2e}
\usepackage{lipsum}
\begin{document}
\section{Properly aligned (justified) with default font}
\lipsum[1]
\section{I change font to pcr and the text is not properly aligned}
\fontfamily{pcr}\selectfont
\lipsum[1]
\end{document}
答案1
如果只是为了评论,我会使用 ragged right。无论如何,这里有一种可能性:
\documentclass{article}
\usepackage{lipsum}
\newenvironment{jcomment}
{\par\addvspace{\medskipamount}%
\normalfont\fontfamily{pcr}\selectfont
\ifnum\hyphenchar\font=`\- \else\hyphenchar\font`\-\fi
\spaceskip=\fontdimen2\font plus .5\fontdimen2\font minus .2\fontdimen2\font
\ignorespaces}
{\par\addvspace\medskipamount}
\begin{document}
\section{Properly aligned (justified) with default font}
\lipsum[2]
\section{I change font to pcr and the text is not properly aligned}
\begin{jcomment}
\lipsum*[2]
\end{jcomment}
\end{document}
答案2
鉴于您只想要可区分的评论,我的建议是不要使用 Courier 字体,而是使用“打字机”但比例的字体拉丁现代单比例或者拉丁现代单声道 Z:
\documentclass{article}
%\renewcommand*\ttdefault{lmvtt} % for Latin Modern Mono Proportional
\usepackage[scaled=1.05,proportional,lightcondensed]{zlmtt}
\usepackage{lipsum}
\begin{document}
\section{Justified with standard font}
\lipsum[1]
\section{May be better not change to \texttt{pcr}}
\ttfamily
\lipsum*[1]
\end{document}
当然,使用{\ttfamily ...}
还是\texttt{...}
要限制打字机字体的范围。
答案3
我刚刚更改了单词间距设置。正如http://texblog.net/latex-archive/plaintex/full-justification-with-typewriter-font/
\documentclass{article}
\usepackage{geometry, ragged2e}
\usepackage{lipsum}
\usepackage{everysel}
\renewcommand*\familydefault{\ttdefault}
\EverySelectfont{
\fontdimen2\font=0.3em
\fontdimen3\font=0.2em
\fontdimen4\font=0.1em
\fontdimen7\font=0.1em
\hyphenchar\font=`\-
}
\begin{document}
\section{Justified with standard font}
\lipsum[1]
\section{I change font to ``pcr'' and this is not justified}
\fontfamily{pcr}\selectfont
\lipsum[1]
\end{document}