3

I got text justifying problem when I change the default font to a monospaced font, as you can see in my MWE.

Note that this does not only happen in article class, but also in memoir, book, as well.

\documentclass[12pt]{article}
\usepackage{lipsum}
\usepackage{tgcursor}
\renewcommand*\familydefault{\ttdefault} 
\begin{document}
\lipsum
\end{document}

How can I fix it? Please help me.

Thanks

6

The problem here is, that monospaced fonts also have a fixed width space between words, so TeX cannot stretch these spaces. You have to adjust the interword space settings. The following solution is adapted from http://texblog.net/latex-archive/plaintex/full-justification-with-typewriter-font/

\documentclass[12pt]{article}
\usepackage{lipsum}
\usepackage{everysel}
\renewcommand*\familydefault{\ttdefault}
\EverySelectfont{%
\fontdimen2\font=0.4em% interword space
\fontdimen3\font=0.2em% interword stretch
\fontdimen4\font=0.1em% interword shrink
\fontdimen7\font=0.1em% extra space
\hyphenchar\font=`\-% to allow hyphenation
}
\usepackage{tgcursor}

\begin{document}
\selectfont % Force initial font feature selection
\lipsum
\end{document}

OUTPUT:

justify

  • Using the appropriate hyphenation patters for latin will improve the result too: \usepackage[latin]{babel} – Andrew Swann Feb 24 '16 at 15:49
  • Sure. One should always load babel with the right language. Although I don't think it is a good idea to add it to the MWE. That could be confusing for beginners who maybe think it is necessary for their document even though they most likely do not write in latin. – Benjamin Feb 24 '16 at 16:02
  • Agreed - I mentioned it because loading the correct hyphenation patterns improves the original layout quite a bit. – Andrew Swann Feb 24 '16 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.