9

I am often confronted with the need of fitting in more content into an already quite crammed document. Given that LaTeX automatically stretches spaces to beautifully and optimally fill the pages, I find it sometimes hard to locate where additional lines might fit in.

Are there some tips on how to locate stretched spaces that might be exploited, possibly a package that colors the difference between the minimum space required and the stretch-space added automatically? Other tips are also welcome.

3
2

My comment last month nagged at me, until I remembered an answer I gave at Rounded box around placeholder text that supports line breaking (in which I was trying to eliminate this gapping effect), and decided it was worth trying to adapt to enhance it. What I do is paint the natural spaces of alternating letters in alternating colors (here cyan!80 and cyan!60). I paint spaces their natural width in cyan and periods in cyan!95. I found it got too confusing if I chose vastly different colors.

Horizontally stretched lines can be quickly observed with white gaps between words. I chose a \vgap between lines of 2.5pt, since that value set the cyan color rules at a similar height to the letters themselves (if the gap is too small, the cyan rules themselves affect the line spacing). Nonetheless, vertical gap differences can be noted.

I should point out that this approach will inhibit hyphenation, and so it may not be a direct comparison to the unmarked text, where line breaks are involved. By the same token, while I have applied it to the complete document text in this MWE, one can selectively include partial text (it is of a macro form, embracing the text in a {} group) and possibly acquire the desired data by highlighting only a small fraction of the overall text.

\documentclass{article}
\usepackage{censor}
\usepackage{xcolor}
\newlength\vgap
\vgap=2.5pt% GAP BETWEEN ADJACENT LINES (THIS VALUE CONFORMS TO LETTER SIZES)
\textheight=3.03in

\makeatletter
\def\mystrut{\rule%
  [\dimexpr-\dp\strutbox+.5\vgap]{0pt}{\dimexpr\ht\strutbox+\dp\strutbox-\vgap}}
% SET ALL LAPS TO 0pt...
\periodrlap=0pt\relax
\afterperiodlap=0pt\relax
\lletterlap=0pt\relax
\rletterlap=0pt\relax
% EXCEPT THE SPACE LAP, WHICH IS SET TO NATURAL SPACE WIDTH
\setbox0=\hbox{ }
\afterspacelap=\wd0\relax% THE NATURAL SPACE WIDTH

\renewcommand\censorrule[1]{%
\protect\colorbox{cyan}{\mystrut\rule[\censorruledepth]{#1}{0pt}}}

\newcounter{colindex}
\edef\cencolora{cyan!80}
\edef\cencolorb{cyan!60}
\def\chcolor{\stepcounter{colindex}\ifnum\thecolindex=2%
  \def\cencolor{\cencolorb}\setcounter{colindex}{0}\else%
  \def\cencolor{\cencolora}\fi}
\chcolor

\renewcommand\@cenword[1]{\colorbox{\cencolor}{\mystrut#1}\chcolor}

\def\censordot{\colorbox{cyan!95}{\mystrut.}}

\let\marktext\xblackout

\makeatother
\fboxsep=0pt
\parindent 0in
\flushbottom
\begin{document}

\marktext{Note however, that auto-hypenation will NOT work with this approach.

Can this procedure go across paragraphs boundaries?

Why yes it can.

Gaps can arise if glue is stretched too far.

NEXT LINE STARTS A PARBOX:}

\parbox{.8\textwidth}{\marktext{%
This tests marking a multiline block of text.  This tests marking a multiline block of text.
This tests marking a multiline block of text.  This tests marking a multiline block of text.
This tests marking a multiline block of text.}}

\marktext{%
NOT IN A PARBOX:

This tests marking a multiline block of text.  This tests marking a multiline block of text.
This tests marking a multiline block of text.  This tests marking a multiline block of text.
This tests marking a multiline block of text.}
\end{document}

In the global view, we can see that the vertical gap above and below the parbox has been squeezed out significantly.

enter image description here

In this zoom, we observe the horizontal stretching differences on different lines. The "f" on the last line is not squeezed... it naturally overhangs its bounding box.

enter image description here

If one looks closely, compressed text also exhibits visible cramping, as in this comparison of the letter "e", where the kern on the right has been abolished by an inter-word space.

uncompressed vs compressed

. . . enter image description here. . . . . . .enter image description here

2
  • This is a very nice answer! But fact that it inhibits hyphenation may be a problem in practical use. Have to try it... – rec May 18 '14 at 7:41
  • @rec I agree. In practical use, it may make sense to apply it not everywhere at once, but only over "suspect" areas of text. That may make it more feasible to manually avoid hyphenation issues. – Steven B. Segletes May 18 '14 at 10:40

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.