TeXblog

 Typography with TeX and LaTeX

Archive for the 'Layout' Category

Prevent page breaks

11 June 2008 by Stefan Kottwitz

A page break directly after a first item of a itemize oder enumerate environment or other lists may be annoying. How to prevent that? A common way to prevent a page break is to use a minipage (or samepage) environment, but you cannot use that for just a part of the list.
The needspace package allows to define how much vertical space is needed. If there is enough space it continues normally, but if the space left on the page is less than requested a page break is inserted. The documentation of needspace is inside the sty-file itself. Her is an example:

\usepackage{needspace}
...
\needspace{5\baselineskip}
Remarks:
  \begin{itemize}
    \item ...
...

Then immediately after Remarks: no pagebreak could happen.

This topic was discussed in the LaTeX Community Forum, on Matheplanet and on mrunix.de.

Category: Layout | No Comments »

Full justification with typewriter font

14 May 2008 by Stefan Kottwitz

In a typewriter font aka monospaced font each character is given the same width. Monospaced fonts are frequently used by programmers to increase the readability of source code, but long text passages with monospace typeface are considerably less readable than those with variable-width fonts.

The space between words is fixed too, that prevents justification, and hyphenation may be disabled too. That’s useful for presenting source code, but sometimes a typewriter font is wanted but justification is required. This post will give some information how to fulfill that. We will use the Computer Modern Typewriter font (cmtt) you get by default when using \ttdefault, \ttfamily, \texttt.

The following code prints some of the font properties:

\documentclass[a4paper,10pt]{article}
\renewcommand*\familydefault{\ttdefault}
\begin{document}
\begin{description}
  \item[slant] \the\fontdimen1\font
  \item[interword space] \the\fontdimen2\font
  \item[interword stretch] \the\fontdimen3\font
  \item[interword shrink] \the\fontdimen4\font
  \item[extra space] \the\fontdimen7\font
  \item[xspaceskip] \the\xspaceskip
  \item[hyphenchar] \the\hyphenchar\font
\end{description}
\end{document}

The font cmtt10 is used, the result is:
slant 0.0pt
interword space 5.24995pt
interword stretch 0.0pt
interword shrink 0.0pt
extra space 5.24995pt
xspaceskip 0.0pt
hyphenchar -1

The space between words is 1em, the same is valid for the extra space following the end of a sentence. Zero stretch and shrink means the space between the words will always be 1em. The hyphenchar is set to -1, that’s why hyphenation is disabled. Let’s look how a normal text is set when typewriter is used:

\documentclass{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\renewcommand*\familydefault{\ttdefault}
\begin{document}
\section{Test}
\begin{minipage}{0.7\textwidth}
\blindtext
\end{minipage}
\end{document}

Output:

monospace typewriter (\ttfamily) flush left

To get justification I just modify some of the font parameters above, that the spaces may be stretched and shrinked. I use the everysel package to ensure that my changes are applied every time the font is selected. Further I set the \hyphenchar to the - symbol.

\documentclass{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{everysel}
\renewcommand*\familydefault{\ttdefault}
\EverySelectfont{%
\fontdimen2\font=0.4em% interword space
\fontdimen3\font=0.2em% interword stretch
\fontdimen4\font=0.1em% interword shrink
\fontdimen7\font=0.1em% extra space
\hyphenchar\font=`\-% to allow hyphenation
}
\begin{document}
\section{Test}
\begin{minipage}{0.7\textwidth}
\blindtext
\end{minipage}
\end{document}

This is the justified result:

monospace typewriter (\ttfamily) justified

We get full justification and a good grayness of the paragraph. One line shows that hyphenation is active though it was rarely necessary.

This topic was discussed on CQF.info. In the LaTeX Community Forum we talked about similar issues with font dimensions.

Category: Layout, Fonts and Symbols, plain TeX | 2 Comments »

Changing margins for just one paragraph

2 May 2008 by Stefan Kottwitz

If you want to indent a paragraph just by a certain length but the standard LaTeX environments don’t meet the requirements you could use the TeX primitive \leftskip. To limit its effect it can be enclosed in \begingroup … \endgroup. The equivalent for the right margin is \rightskip. Here’s an example:

\documentclass[a4paper,10pt]{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\parindent0em
\parskip\baselineskip
\begin{document}
\blindtext
\par
\begingroup
\leftskip4em
\rightskip\leftskip
\blindtext
\par
\endgroup
\blindtext
\end{document}

A downscaled screenshot of the output:

paragraph with different left and right margin

This topic was discussed on Matheplanet and ChemieOnline.

Category: Layout, plain TeX | 1 Comment »