Fonts & Character SetsMonospace problems

Information and discussion about fonts and character sets (e.g. how to use language specific characters)
Post Reply
Enomis
Posts: 1
Joined: Mon Mar 05, 2012 6:21 pm

Monospace problems

Post by Enomis »

Hello,
I have to write a document with a monospace font. After the usage of:

Code: Select all

\renewcommand*\familydefault{\ttdefault}
The text blocks are not well rendered anymore. It seems hyphenation and word-wrapping does not work correctly. I use Koma-script book for the document.

Thanks for your help
Last edited by Stefan Kottwitz on Mon Mar 05, 2012 7:21 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Monospace problems

Post by Stefan Kottwitz »

Obviously hyphenation is disabled with your monospaced font. And with a monospaced font, also spaces between words are fixed, which prevents justification.

Here's an example showing a way how you can enable hyphenation and even full justification. It uses the everysel package.

Code: Select all

\documentclass{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\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
}
\begin{document}
\section{Test}
\begin{minipage}{0.7\textwidth}
  \blindtext
\end{minipage}
\end{document}
typewriter-justified.png
typewriter-justified.png (21.37 KiB) Viewed 4866 times
For further explanation, perhaps have a look at: Full justification with typewriter font, there I explained it earlier in my blog.

With scrbook, you probably would like to have chapter and section headings in typewriter font too. They are sans serif by default, you can change it by

Code: Select all

\setkomafont{sectioning}{\normalfont\bfseries}
which gives typewriter as it's now the default font.

Stefan
LaTeX.org admin
Post Reply