41

My objective is to fit more words within one line.

In order to show what I mean, I will exaggerate the word spacing here:

Pretend this is a normal line in the document:

Lorem   ipsum   dolor   sit   amet,   consectetuer   adipiscing   elit.

Since I want to fit more words in the same line, I would like to change the word spacing to look like:

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Add more words.

What command will allow me to shrink the word spacing in the entire line?

39

There are a number of factors involved in font spacing, including inter word spacing, inter character spacing, inter word stretch, etc. Stefan Kottwitz' blog on Full justification with typewriter font covers all these in an example based on the Computer Modern Typewriter font (\ttfamily, \texttt, etc.).

More specifically, the following dimensions may be set for a font:

  • Slant: \fontdimen1
  • Inter word space: \fontdimen2
  • Inter word stretch: \fontdimen3
  • Inter word shrink: \fontdimen4
  • Extra space: \fontdimen7
  • xspace skip: \xspaceskip
  • Hyphenation character: \hyphenchar

In order to decrease the space between words, you can either change the inter word space/stretch. here are some examples that show the difference:

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{lipsum}
\begin{document}
  \newdimen\origiwspc%
  \newdimen\origiwstr%
  \origiwspc=\fontdimen2\font% original inter word space
  \origiwstr=\fontdimen3\font% original inter word stretch
  \lipsum[1]% normal text
  \fontdimen2\font=0.2ex% inter word space
  \lipsum[1]% decreased inter word space
  \fontdimen2\font=\origiwspc% (original) inter word space
  \fontdimen3\font=0.1em% inter word stretch
  \lipsum[1]% decreased inter word stretch
  \fontdimen3\font=\origiwstr% (original) inter word stretch
  \fontdimen2\font=1em% inter word space
  \lipsum[1]% increased inter word space and stretch
  \fontdimen2\font=\origiwspc% (original) inter word space
  \fontdimen3\font=\origiwstr% (original) inter word stretch
  \lipsum[1]% original/normal text
\end{document}

This is what it looks like:

enter image description here

  • Nice answer, also learned about the other functions that may come in handy in the future. How do I change back to default values if I don't need to word space/shrink anymore? – Level1Coder Jul 23 '11 at 18:33
  • @Level1Coder: I've updated my answer to reflect how you can store the original/default values. Scoping via {...} doesn't work here. So, it works best to set it the beginning and reset after using it. – Werner Jul 23 '11 at 18:56
  • Why do you write %'s at the end of the lines \newdimen\origiwspc% and \newdimen\origiwstr%? I've seen other people do this as well. – tparker Nov 29 '17 at 23:01
  • 2
    @tparker: It's not needed in this specific case, since the code line ends with a control sequence. However, if it doesn't one may see a spurious space in your output. See What is the use of percent signs (%) at the end of lines? – Werner Nov 29 '17 at 23:15
11

With pdfTeX, I would use the microtype package. Besides providing an interface to pdfTeX’s micro-typographic extensions, it can also be used to modify interword spacing and additional kerning and also letterspacing.

Interword spacing can be customized by \SetExtraSpacing, described in the section 5.5 Interword spacing in the microtype manual.

microtype can improve the justification and may also save space for you. Have a look at this example, where just loading that package removes bad boxes and improves the appearance: Full Justification: pdfLaTeX vs. LaTeX.

11

here an example where the interword space is really small with 1pt

\documentclass{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\begin{document}
%current value: \the\fontdimen2\font 
\blindtext

\fontdimen2\font=1pt
\blindtext

\end{document} 

enter image description here

  • 1
    What is the default pt value for \fontdimen2\font=?pt – Level1Coder Jul 23 '11 at 18:25
  • 1
    you can output into your tex file with \the\fontdimen2\font. It is for my system 3.33333pt. But there are are two more values for plus and minus (stretching and shrinking) – user2478 Jul 23 '11 at 18:38
4

Edited as suggested by manuel.

I found Werner's answer so usefull, I made simple enviroment of it:

\documentclass{article}
\usepackage[english]{babel}
\usepackage{blindtext}

    % declare new dimensions
    \newdimen\origiwspc
    \newdimen\origiwstr

    \newenvironment{fontspace}[2]
        {\par
            % set default value of new dimensions
            \origiwspc=\fontdimen2\font% original inter word space
            \origiwstr=\fontdimen3\font% original inter word stretch
            % set dimensions to arguments given
            \fontdimen2\font=#1\origiwspc
            \fontdimen3\font=#2\origiwstr
        }
        {\par
            % reset original dimensions
            \fontdimen2\font=\origiwspc
            \fontdimen3\font=\origiwstr
        }

\begin{document}

    \blindtext

    \begin{fontspace}{1.5}{2}
        \blindtext
    \end{fontspace}

\end{document} 

enter image description here

  • 1
    You must not declare \newdimen everytime you call the environment. Just declare them outside. – Manuel Dec 26 '15 at 21:47
3

If you are interested in stretching or shrinking the spaces between letters (not words), microtype's \textls macro does wonders:

\documentclass{memoir}
\usepackage{microtype}

\newcommand{\dummytext}{Some words that demonstrate the effect of typographic tracking. Some words that demonstrate the effect of typographic tracking. Some words that demonstrate the effect of typographic tracking. Some words that demonstrate the effect of typographic tracking. Some words that demonstrate the effect of typographic tracking. Some words that demonstrate the effect of typographic tracking. Some words that demonstrate the effect of typographic tracking. Some words that demonstrate the effect of typographic tracking. Some words that demonstrate the effect of typographic tracking. Some words that demonstrate the effect of typographic tracking. Some words that demonstrate the effect of typographic tracking.}


\begin{document}

\dummytext{} \textbf{Start of tracking.} \textls[-60]{\dummytext} \textbf{End of tracking.} \dummytext

\end{document}

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.