1

Here is my MWE. I wish for text with full justification, that is the text lines up perfectly with the right margin. I can not find a simple answer to this, Please help.

\documentclass[oneside,12pt]{article}
\setlength{\oddsidemargin}{0.25 in}
\setlength{\evensidemargin}{-0.25 in}
\setlength{\topmargin}{-0.6 in}
\setlength{\textwidth}{5.5 in}
\setlength{\textheight}{5.75 in}
\setlength{\headsep}{0.75 in}
\setlength{\parindent}{.5 in}
\setlength{\parskip}{0.1 in}

\usepackage{lipsum}

\begin{document}

\ttfamily

\lipsum

\end{document}

enter image description here

2 Answers 2

3

The standard typewriter fonts inhibit hyphenation and have fixed width interword spacing, because they're commonly used for listings where alignment is important.

You can load the fonts with different settings, though.

\documentclass[oneside,12pt]{article}

\setlength{\oddsidemargin}{0.25 in}
\setlength{\evensidemargin}{-0.25 in}
\setlength{\topmargin}{-0.6 in}
\setlength{\textwidth}{5.5 in}
\setlength{\textheight}{5.75 in}
\setlength{\headsep}{0.75 in}
\setlength{\parindent}{.5 in}
\setlength{\parskip}{0.1 in}

\usepackage{lipsum}

\DeclareFontFamily{\encodingdefault}{\ttdefault}{%
  \hyphenchar\font=\defaulthyphenchar
  \fontdimen2\font=0.33333em
  \fontdimen3\font=0.16667em
  \fontdimen4\font=0.11111em
  \fontdimen7\font=0.11111em
}

\begin{document}

\ttfamily\lipsum

\end{document}

If you don't want hyphenation, replace \defaulthyphenchar by -1.

enter image description here

2
  • This worked, but the other styles, bfseries, mdseries, itshape, were all displayed as typewriter. Fran's answer worker better for me. Feb 27, 2022 at 14:46
  • 1
    @ScotParker Just localize the \ttfamily declaration issuing inside a group (or environment). Fran's answer won't work on different font sizes than the normal one.
    – egreg
    Feb 27, 2022 at 14:47
2
\documentclass{article}
\usepackage{lipsum}
\usepackage{microtype}
\begin{document}
\ttfamily
\fontdimen3\font=1ex % interword stretch
\fontdimen4\font=1ex % interword shrink
\fontdimen7\font=1ex % extra space
\lipsum
\end{document}

or ...

\documentclass{article}
\usepackage{lipsum}
\usepackage{tgcursor}
\renewcommand*\familydefault{\ttdefault}
\usepackage[T1]{fontenc}
\usepackage{ragged2e} 
\fontdimen7\font=2pt % extra space
\fontdimen3\font=1em % interword stretch
\fontdimen4\font=1em % interword shrink

\begin{document}
\justify \lipsum
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .