51

I would like to have "something" (a package, a trick, a macro, ...?) that makes it possible for me to nicely play with the margins (or the layout) in order to set the average or typical number of characters per line.

Ideally, this "system" would help me keep this ratio (66, 2.5 alphabets, or any other number I choose/input) independent from changes in font families (such as with the use of the package pslatex or txfonts for example), in font sizes (with a 10pt or 12pt class option for example).

I've looked around a bit, and I kind of understood, that using KOMA-Script classes or the memoir class may be part of a solution, be I would prefer not (especially because I have never used any so far).

An important point for me is that the whole proportions or principles of the original layout must be kept. For example, if there was a set ratio between left and right margins, then, just playing around with one margin or with textwidth/linewidth would not satisfy me.

Why I'd like to do this? Because I like to use the pslatex package, but this put the average number of charaters per line from about 65 without to about 75+ with.

Note, I have already gone or skimmed through:

And, also there may be answers there, I couldn't (too easily) find them.

3
  • 1
    The necessary part of KOMA-script can be used standalone:\usepackage[DIV=calc]{typearea} . Maybe this helps.
    – sebschub
    Jun 13, 2012 at 7:38
  • @S. Schubert: This is a very interesting idea. I just tried it. It could do the trick. However, it tends to put the bottom of the page (end of text, page numbers...) a bit too high for my taste.
    – Christophe
    Jun 13, 2012 at 9:36
  • @S. Schubert: Another problem (that I think I've seen) is that it seems to work better (or only?) with the a4paper option for the article class [and less (or not?) with the letterpaper option]. If this is true, I'd be curious to know why...
    – Christophe
    Jun 13, 2012 at 9:52

3 Answers 3

43

The statement about 2.5 times the length of the lowercase alphabet is just an indication. However you can play with geometry:

\documentclass{book}

%%\usepackage{newtxtext}
\newlength{\alphabet}
\settowidth{\alphabet}{\normalfont abcdefghijklmnopqrstuvwxyz}

\usepackage{geometry}
\geometry{textwidth=2.5\alphabet,hmarginratio={2:3}}

\begin{document}
\the\textwidth
\end{document}

This will use a ratio for the margins as indicated (2:3 is actually the default, in twoside mode). Well behaved font packages should work correctly.

With the default fonts I get a textwidth of 318.96pt, while with newtxtext I get 298.58pt (with mathptmx the result is 298.57pt).

Notice that pslatex is a very obsolete package and that its descendant mathptmx is rather inadequate for serious typesetting involving math. If you don't need mathematics, other choices based on (Linotype) Times Roman are

  • newtxtext (based on txfonts, but with corrected metrics)

  • tgtermes

The former has the companion math package newtxmath.

You can choose whatever ratio you prefer for the margins. It's customary, in twoside printing, to have the outer margin wider than the inner one. If you want to automatize the choice between oneside printing (equal margins) and twoside, then

\geometry{textwidth=2.5\alphabet}
\makeatletter
\if@twoside
  \geometry{hmarginratio={2:3}}
\else
  \geometry{hmarginratio={1:1}}
\fi
\makeatother

could be used. The options for geometry can be given in distinct \geometry commands. Don't forget to specify the paper size (you can do it either in \geometry or as a class option).

You can also test the loaded class:

\makeatletter
\geometry{hmarginratio={1:1}} % fallback

\@ifclassloaded{book}
 {
  \if@twoside
    \geometry{hmarginratio={2:3}}
  \else
    \geometry{hmarginratio={1:1}}
  \fi
 }{}

\@ifclassloaded{article}
 {
  \if@twoside
    \geometry{hmarginratio={4:2}}
  \else
    \geometry{hmarginratio={1:1}}
  \fi
 }{}
\makeatletter

(the setting 4:2 is just by way of example).

However there's no "catch all" format: what you finally choose for a document depends on the document itself.


How to set the horizontal margin ratio to be equal to that fixed by the class? This is a bit difficult, because the standard setting uses a different model than geometry.

\documentclass{article}
\usepackage{newtxtext}
\usepackage{geometry}

\newlength{\alphabet}
\sbox0{\normalfont abcdefghijklmnopqrstuvwxyz}
\setlength{\alphabet}{\wd0}

\makeatletter
\begingroup
\dimendef\innermargin=\z@
\dimendef\outermargin=\tw@
\innermargin=\dimexpr\oddsidemargin+1in+\hoffset\relax
\outermargin=\dimexpr\paperwidth-\innermargin-\textwidth\relax
\outermargin=.002\outermargin
\innermargin=2\innermargin
\count@=\innermargin
\divide\count@ \outermargin
\xdef\standardhmarginratio{\number\count@:1000}
\endgroup

\geometry{textwidth=2.5\alphabet,hmarginratio=\standardhmarginratio}

\begin{document}

text width = \the\textwidth

horizontal margin ratio = \standardhmarginratio

\end{document}

With the article class we get 1000:1000, with book (twoside mode) the result is 667:1000 that's, for all practical purposes, 2:3.

10
  • Your alphabet doesn't have x. Why not just use 26em?
    – StrongBad
    Jun 12, 2012 at 22:50
  • Thank you for your answer and the extra comments on pslatex. However, I suspect that hmarginratio={2:3} would be specific to the book class and would need to be changed for another class (such as article or letter). If I'm right, then I can't accept your answer (yet).
    – Christophe
    Jun 12, 2012 at 22:58
  • 1
    @DanielE.Shub Thanks for spotting the missing letter. The em is usually the width of an uppercase M, so 26em is way larger than \alphabet.
    – egreg
    Jun 12, 2012 at 23:29
  • @egreg: do you know if hmarginratio can be obtained? I mean, could you do something like: define ThisClassRatio by getting the numbers from commands and then \geometry{textwidth=2.5\alphabet,hmarginratio={ThisClassRatio}}.
    – Christophe
    Jun 13, 2012 at 0:02
  • 1
    @Christophe The standard classes use a different model for defining the page parameters. I'll add some example of computation.
    – egreg
    Jun 13, 2012 at 6:35
30

Robert Bringhurst, in "The Elements of Typographic Style", gives a table of preferred line lengths for different fonts. A least squares optimization fit of the table data revealed that it can be approximated quite well with the following macro:

\newcommand*\GetTextWidth[3][\normalfont]{{#1%
    \settowidth{#2}{abcdefghijklmnopqrstuvwxyz}%
    \setlength{#2}{0.03193#2}%
    \addtolength{#2}{0.44961pt}%
    \setlength{#2}{#3#2}%
    \global#2=#2}}

Which can be used together with geometry, etc. to set the text width

\newlength\bringhurstwdt
\GetTextWidth{\bringhurstwdt}{66}
\geometry{textwidth=\bringhurstwdt}

I assume that this is valid for standard English which have relative short words. In a language such as Afrikaans (my native language) we have a lot very long words and the 66 characters per line does not alway look right. For other languages the character count for good typography may differ, but I have no idea what would be best.

3
  • Thank you for your answer. I'm a bit lost in the units and variables used. Maybe you could help me on this: Do you know if the formula you're using (from "The Elements of Typographic Style") is related in anyway to the one given in the memoir class documentation (here) (section 2.4, page 13)? Thanks again.
    – Christophe
    Jun 15, 2012 at 13:50
  • 1
    @Christophe: My formula is basicaly L = (0.03193 W + 0.44961pt)*N with W the alphabet width in points, N the number of chars and L the line width in points. The formula in memoir is for N=65 and it differs slightly from mine but not by much.
    – Danie Els
    Jun 16, 2012 at 3:20
  • 2
    Very useful. It seems that one has to add \normalsize after \normalfont in order to get results suitable for 11pt or 12pt documents.
    – Thérèse
    Jul 16, 2012 at 5:48
20

ConTeXt provides a macro called \averagecharwidth that calculates the average width of a character based on language specific character frequency. There is no proper interface for it, so you have manually load the required files.

 \input lang-frq.mkii %macros to calculate average length
 \input lang-frd.mkii %language frequency tables

 \setuplayout[width=66\averagecharwidth]

See lang-frd.mkii for language frequency tables, and lang-frq.mkii for macros to calculate average width. From the documentation:

This module implements a method for determining the width of an average character in a language. It uses the dimensions of the current fonts.

Method~1 ignores the widths and assumes that each character has a width of .5em, which is true for most monospaced fonts. Method~2 takes the x as starting point, and assumes that it's height kind of matches its width. Method~3 is the best one, and determines the average width based on the language specific character table. Method~4 is a mixture between the first two methods: character specific widths applied to an equal distribution. Method~0 reports the total count, which normally is~100.

The documentation also includes the following figure showing the frequency tables for English, Dutch, and German.

enter image description here

Although the files have .mkii extension, the code is fairly low-level TeX and works with ConTeXt MkIV as well. It should also work with LaTeX with minor changes.

For a true "average of 66 characters per line", you can first preprocess your text to generate the frequency table, and then use that frequency table to compute the average character width!

Note: The \averagecharwidth macro takes the font sizes from the current font and chooses the character frequency from the current language. So, it should be used after the document font and language have been specified.

3
  • I am more and more fascinated by ConTeXt.
    – Sveinung
    Jun 15, 2012 at 18:14
  • @Aditya there is a similar method in latex?
    – Aurelius
    Aug 19, 2012 at 0:49
  • @Sveinung: come to the dark side, we have cookies! (Easter eggs?)
    – Esteis
    Aug 21, 2012 at 21:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .