0

This might be a silly question but I cannot find a way to solve it. Below is a MWE:

\documentclass{article}

\usepackage[margin=1in]{geometry}

\usepackage{blindtext}

\begin{document}

\ttfamily What can we do in this case? What should we do about this? What can we do in this case? What should we do about this?

\blindtext

\end{document}

The result is like this:

result

As you can see, the right side is completely misaligned. I've tried to set the \hyphenpenalty but it seems to be useless.

How should one fix this?

Jinwen
  • 8,518
  • Does https://tex.stackexchange.com/q/290731/35864 help? – moewe Nov 26 '20 at 07:21
  • @moewe Thanks for this link. I think my question is almost the same with it, but the solution there doesn't work for me. It is probably because that I'm using pdflatex. – Jinwen Nov 26 '20 at 07:43

1 Answers1

1

Similar to this: wordbreaking, justification and ttfamily

This might work for you:

\documentclass{article}

\usepackage[margin=1in]{geometry}

\usepackage{blindtext}

\begin{document}

\ttfamily\hyphenchar\font=`-\spaceskip=.5em plus .5em\xspaceskip=.5em What can we do in this case? What should we do about this? What can we do in this case? What should we do about this? \blindtext

\end{document}

enter image description here

Roland
  • 6,655
  • May I ask what is \spaceskip=.5em plus .5em\xspaceskip=.5em for? – Jinwen Nov 26 '20 at 08:02
  • \spaceskip and \xspaceskip are ways to control interword spacing in ragged macros. For example \spaceskip of 0.5em makes every interword space exactly 0.5em and xspaceskip is for the spacing between sentences. – Roland Nov 26 '20 at 23:34