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?

2
  • Does tex.stackexchange.com/q/290731/35864 help?
    – moewe
    Nov 26 '20 at 7: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 7:43
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

2
  • May I ask what is \spaceskip=.5em plus .5em\xspaceskip=.5em for?
    – Jinwen
    Nov 26 '20 at 8: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

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.