Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

So I know that a common technique in typography to avoid hyphens at a line break is to adjust the spacing of words and letters slightly. I was not aware of LaTeX doing this until today, but now it is causing me a problem.

EDIT: After adding tags, I see that this phenomenon of letter spacing is called "tracking".

I am writing up a homework, where the parts look like this:

\textbf{a.} \hspace{5 pt} {\color{NavyBlue} Does the above tweak work? If yes, then 
prove it, if not, then provide a counter example.}

\textbf{b.} \hspace{5 pt} {\color{NavyBlue} Implement the above version of the Bakery
algorithm in Java, and dependent on your answer to part (a) either show a set of 
(say 4) threads reciting the declaration of independence cohesively, or else not.}

The problem is that the "Does" and the "Implement" are not aligned with each other, because it appears that the spacing thing I mentioned above is pushing the position of "Implement" farther forward. Here's a screenshot:

enter image description here

Is there a command I can use to allow hyphenation instead of the adjusted spacing, so that the beginnings line up properly?

Here's a MWE:

\documentclass[a4 paper,11pt]{article}
\usepackage{amsmath, amsfonts, amssymb, parskip, dsfont, amsthm, wasysym, mathrsfs}
\usepackage{graphicx}
\usepackage[usenames, dvipsnames]{xcolor}
\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{mathrsfs}
\usepackage[normalem]{ulem}
\usepackage[breaklinks=true]{hyperref}
\usepackage{soul, color} % for highlighting
\usepackage{pifont} % for cool symbols in text mode
\usepackage{changepage} % for block quotes -- \begin{addmargin}[left][right]

\begin{document}

\textbf{a.} \hspace{5 pt} {\color{NavyBlue} Does the above tweak work? If yes, then 
prove it, if not, then provide a counter example.}

\textbf{b.} \hspace{5 pt} {\color{NavyBlue} Implement the above version of the Bakery
algorithm in Java, and dependent on your answer to part (a) either show a set of 
(say 4) threads reciting the declaration of independence cohesively, or else not.}

\end{document}
share|improve this question
1  
LaTeX would naturally hyphenate, so why isn't it? Also, there are far better ways of providing an enumerated environment with consistent spacing/alignment. –  Werner Apr 10 at 4:33
    
That's what I thought - I don't get why it isn't. I'll post my preamble. As for using another environment, I'm going to put my solutions (including graphics) between the a. and b. parts, so using a list environment would get unwieldy. –  AmadeusDrZaius Apr 10 at 4:35
2  
Don't just post your preamble... post a complete, minimal working example (MWE) that replicates your problem. We want to copy-and-paste it and see exactly what your problem is. –  Werner Apr 10 at 4:37
    
Well a MWE really is just that preamble plus the two lines I posted above. But I'll post it in entirety. –  AmadeusDrZaius Apr 10 at 4:45
1  
@AmadeusDrZaius By removing your packages one by one and rerunning your code, you can discover what packages might be causing your problem. Please read meta.tex.stackexchange.com/a/3225/9077 –  Sverre Apr 12 at 12:39

4 Answers 4

up vote 5 down vote accepted

LaTeX is hyphenating. The problem is that you provide LaTeX with space at the start of enumerate, that can stretch (the default space). Delete the spaces at the beginning and the problem goes away. By the way if LaTeX does not know the word or you want different breaks you can use \- e.g., ans\-wer.

\documentclass[a4 paper,11pt]{article}
\usepackage{amsmath, amsfonts, amssymb, parskip, dsfont, amsthm, wasysym, mathrsfs}
\usepackage{graphicx}
\usepackage[usenames, dvipsnames]{xcolor}
\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{mathrsfs}
\usepackage[normalem]{ulem}
\usepackage[breaklinks=true]{hyperref}
\usepackage{soul, color} % for highlighting
\usepackage{pifont} % for cool symbols in text mode
\usepackage{changepage} % for block quotes -- \begin{addmargin}[left][right]

\begin{document}

\textbf{a.}\hspace{5pt}{\color{NavyBlue}Does the above tweak work? If yes, then 
prove it, if not, then provide a counter example.}

\textbf{b.}\hspace{5pt}{\color{NavyBlue}Implement the above version of the Bakery
algorithm in Java, and dependent on your ans\-wer to part (a) either show a set of 
(say 4) threads reciting the declaration of independence cohesively, or else not.}

\end{document}

enter image description here

share|improve this answer
    
Interesting. Could you expand a little bit on why the space messes it up? They both had the same spaces so I wonder why they acted differently. –  AmadeusDrZaius Apr 10 at 5:32
    
The other answer(s) were great too, especially Peter Grill's, but your answer involved the smallest change to my current code, and allowed the most flexibility between parts (a.) and (b.), so I'm giving you the check. –  AmadeusDrZaius Apr 10 at 5:42
1  
@AmadeusDrZaius -- Unfortunately, while this answer solves your immediate problem, the other answers offer better solutions. In general, if you're typing the same basic 'markup' several times over in a document, it is better to encode it in a macro because that makes it easier to make 'global' formatting changes. enumitem in this case makes your job much easier. As for the first comment: TeX in general prefers no hyphenation to hyphenation, and the whitespace on either side of the \hspace gives it lots of space to stretch in favour of hyphenating words; this answer took away that space. –  jon Apr 10 at 5:50
1  
Inserting a space between words is inserting a glue that has a default length and can shrink or stretch by some amount. I think exact size of glue depends on the font used and also can be changed by \spaceskip and \xspaceskip or \spacefactor –  Tahtisilma Apr 10 at 5:51
    
@jon I see about the spaces now, thanks for clarifying that. Part of the reason I chose this answer btw is that it 1) sparks a discussion about spacing, and 2) I had to write answers between the parts a. and b. which were left-aligned. The enumerate/enumitem environments put the inter-item text at the same tab as the items themselves. –  AmadeusDrZaius Apr 10 at 7:38

It is better to use an enumerate list to do what you're doing.

If you want to reproduce exactly the same output, load enumitem and use the following settings

leftmargin=0pt,align=left,labelsep=10pt,itemindent=*,label={\bfseries\alph*.}

MWE:

\documentclass[a4 paper,11pt]{article}
\usepackage{amsmath, amsfonts, amssymb, parskip, dsfont, amsthm, wasysym, mathrsfs}
\usepackage{graphicx}
\usepackage[usenames, dvipsnames]{xcolor}
\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{mathrsfs}
\usepackage[normalem]{ulem}
\usepackage[breaklinks=true]{hyperref}
\usepackage{soul, color} % for highlighting
\usepackage{pifont} % for cool symbols in text mode
\usepackage{changepage} % for block quotes -- \begin{addmargin}[left][right]

\usepackage{enumitem}

\begin{document}

\noindent Your output

\textbf{a.} \hspace{5 pt} {\color{NavyBlue} Does the above tweak work? If yes, then
prove it, if not, then provide a counter example.}

\textbf{b.} \hspace{5 pt} {\color{NavyBlue} Implement the above version of the Bakery
algorithm in Java, and dependent on your answer to part (a) either show a set of
(say 4) threads reciting the declaration of independence cohesively, or else not.}

\bigskip
\noindent Output with \texttt{enumerate}

\begin{enumerate}[leftmargin=0pt,align=left,labelsep=10pt,itemindent=*,label={\bfseries\alph*.}]
\item  {\color{NavyBlue} Does the above tweak work? If yes, then
prove it, if not, then provide a counter example.}

\item  {\color{NavyBlue} Implement the above version of the Bakery
algorithm in Java, and dependent on your answer to part (a) either show a set of
(say 4) threads reciting the declaration of independence cohesively, or else not.}
\end{enumerate}

\end{document} 

Output:

enter image description here

share|improve this answer

Just using the enumitem package seems to solve the issues:

enter image description here


Without using an enumerate type of environment, you can use an \mbox to ensure that you get consistent spacing -- although I would not recommend this:

enter image description here


Code: \enumitem

\documentclass[a4 paper,11pt]{article}
\usepackage{amsmath, amsfonts, amssymb, parskip, dsfont, amsthm, wasysym, mathrsfs}
\usepackage{graphicx}
\usepackage[usenames, dvipsnames]{xcolor}
\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{mathrsfs}
\usepackage[normalem]{ulem}
\usepackage[breaklinks=true]{hyperref}
\usepackage{soul, color} % for highlighting
\usepackage{enumitem}
\begin{document}

\begin{enumerate}[label={\bfseries\alph*.}]
\item {\color{NavyBlue} Does the above tweak work? If yes, then 
prove it, if not, then provide a counter example.}

\item {\color{NavyBlue} Implement the above version of the Bakery
algorithm in Java, and dependent on your answer to part (a) either show a set of 
(say 4) threads reciting the declaration of independence cohesively, or else not.}
\end{enumerate}
\end{document}

Code: \mbox

\documentclass[a4 paper,11pt]{article}
\usepackage{amsmath, amsfonts, amssymb, parskip, dsfont, amsthm, wasysym, mathrsfs}
\usepackage{graphicx}
\usepackage[usenames, dvipsnames]{xcolor}
\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{mathrsfs}
\usepackage[normalem]{ulem}
\usepackage[breaklinks=true]{hyperref}
\usepackage{soul, color} % for highlighting
\usepackage{pifont} % for cool symbols in text mode
\usepackage{changepage} % for block quotes -- \begin{addmargin}[left][right]

\begin{document}

\mbox{\textbf{a.}\hspace{5 pt}}{\color{NavyBlue} Does the above tweak work? If yes, then 
prove it, if not, then provide a counter example.}

\mbox{\textbf{b.}\hspace{5 pt}}{\color{NavyBlue} Implement the above version of the Bakery
algorithm in Java, and dependent on your answer to part (a) either show a set of 
(say 4) threads reciting the declaration of independence cohesively, or else not.}

\end{document}
share|improve this answer
    
Thanks for your answer. The mbox example seems to work perfectly, but I guess there must be a catch? Could you explain what mbox does? –  AmadeusDrZaius Apr 10 at 5:27
    
I really don't understand the purpose of the space in front of \hspace{5pt}; I'd simply do something like \mbox{\textbf{a.}\enspace}; but, of course, the list method is better. –  egreg Apr 10 at 8:57
    
@egreg: Thanks. Have removed that spurious space. –  Peter Grill Apr 11 at 0:55

Just wanted to add to the answer of @Tahtisilma that you can also use \hyphenation{wo-rd, w-ord} to manually set hyphenation patterns for specific words in you document.

Also, \phantom{word} will act as if "word" was printed, except that it isn't. Great little trick for last-ditch fine-tuning of spacing where \hspace{} doesn't work (note: not in this specific case).

However, I would in most cases recommend using defined environments (like enumerate) and not trying to override *tex unless you have a specific reason for it.

share|improve this answer
    
Welcome to TeX.SX! –  Heiko Oberdiek Apr 10 at 14:46
    
Thanks, @HeikoOberdiek! –  Knut Gjerden Apr 11 at 9:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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