# Robert Sedgewick - Algorithms Fourth Edition Style in LaTeX

Recently, I've read "Algorithms" (in Java) - Fourth Edition by Robert Sedgewick. Aside the useful and interesting contents of the book, I was also captivated by book's style. Later on, I read some papers written by this professor and really like his typesetting style.

Here is an example.

I know that this style should be complicated in settings... However, is there anyone has ideas about how to make papers similar to this style.

-
Welcome to TeX.sx! Usually, we don't put a greeting or a “thank you” in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Accepting and upvoting answers is the preferred way here to say “thank you” to users who helped you. –  Papiro May 1 '13 at 10:56
It was set with Adobe InDesign using Minion and Lucida Sans Typewrite mostly –  David Carlisle May 1 '13 at 11:25

That paper does look decent, and a lot better than most other science papers produced in *TeX (, InDesign or whatever application). @David: I don't think that Sedgewick's choosing InDesign is a major factor in the overall look of this particular document: pretty much all of what he does can be done in TeX (and some of it done better).

However, some of his choices I find pretty poor, such as:

• the awfully long lines (sometimes > 100 characters!) resulting from the combination of wide measure & Adobe's Minion in too small a point size.

• use of a neo-humanist, i.e. late 1400s-style typeface in bold variants. I know, people do that all the time but once you've realized that bold type wasn't invented until the mid-1800s, it starts to look odd in a context that alludes to late-mediaeval typography. More appropriate choices would be using the body typeface's uppercase, small caps, or italics -- or the bold of a matching sans serif: Minion Regular + Myriad Bold; Palatino Regular + Syntax Bold; Bembo Regular + Scala Sans Bold, etc.

• the crammyness of the overall appearance. That paper would benefit from less hey-look-at-me-I'm-a-fancy-text-wrapped-figure figures (I'd say: abandon wrapping altogether), more generous leading (to compensate for the loss of readability inflicted by the line length), and a clearer separation of the sections. I do like run-in headings, but in this case I find standalone headings would have been a better choice. Look at p. 3 for example. IMHO it's not immediately obvious if the last paragraph of that page is part of the »2-3 trees« section, or if it's outside the sectioning signified by the run-in headings. Plus, his use of run-in headings as headings for a sectioning level as high as 2 (!) fails to give the eye a chance to ›rest‹ between sections. To me it's just section after section, with only faint additional vertical whitespace inbetween. Saving trees is a purpose I endorse, but no tree is going to be harmed if an electronic document is two or three pages longer due to design choices that improve readability. Yes, there's people (like me) who'd prefer printing prior to reading it, but if it were less crammed, maybe +1pt in type size, it would be easily printable in tree-friendly 2x2 pages per sheet.

• the lack of page numbers: I wouldn't know how to work with a working paper that I can't cite properly

• the use of the archaic ›anglo-saxon spacing‹, i.e. the emulation of hitting the space bar twice after a full stop like back in the typewriter days: \nonfrencspacing in LaTeX

• the mixing of different styles of alignments: there's centered elements, there's left-aligned elements, and there's even right-aligned elements. Call me conservative, but I wouldn't even mix two of them within one book.

Now feel I have to repeat that I still find this paper looks a lot better than the papers produced by most other scientists (let's not talk about the papers produced in the humanities...). That said, I don't mind those papers looking the way they do; as most of them are merely things to work with, and don't claim to to be typographic masterpieces in their own right.

There's nothing all-too complicated about that paper. The only thing that might be easier to do in InDesign than in TeX is the wrapped figures, but even for that there's a package: -- if you really want them. Here's a rough framework to get you started.

\documentclass[12pt,DIV=9]{scrartcl}

\usepackage[english]{babel}
\usepackage{csquotes}              % smarter quotes
\usepackage{blindtext}             % dummy text
\usepackage{xcolor}                % color support
\usepackage{microtype}             % microtypographic tuning
\usepackage{scrpage2}              % smarter headers and footers
\usepackage[para,norule]{footmisc} % smarter footnotes
\usepackage[framemethod=tikz]{mdframed} % background color for paragraphs

% % pdfTeX only:
% \usepackage[utf8]{inputenc}
% \usepackage[T1]{fontenc}
% \usepackage{sourcecodepro} % Source Code Pro from Adobe, should come with your TeX distribution
% \usepackage{sourcesanspro} % Source Sans Pro from Adobe, should come with your TeX distribution
% \usepackage{minionpro}     % the MinionPro package for use with the Minion fonts from Adobe Reader
% %\usepackage{charter}     % another decent font if MinionPro isn't available
% \renewcommand*{\ttfamily}{\fontfamily{SourceCodePro-TOsF}\selectfont}

% Xe and Lua only
% font handling for Xe/LuaLaTeX
\usepackage{fontspec}
\setmainfont[Ligatures=TeX,Numbers={OldStyle,Proportional}]{Minion Pro}
\setsansfont[Ligatures=TeX,Numbers={OldStyle,Proportional},Scale=MatchLowercase]{Source Sans Pro}
\setmonofont[Ligatures=TeX,Scale=0.85]{Source Code Pro}
% how do I disable Minion's T_h ligature?

\definecolor{hks15k}{cmyk}{0.1,1,.8,0}   % #15 from the HKS palette
\definecolor{hks89k}{cmyk}{0,.1,.3,.35}  % #89 from the HKS palette

\setkomafont{section}{\normalfont\sffamily\large\bfseries\color{hks15k}}
\setkomafont{subsection}{\normalfont\sffamily\bfseries\color{hks15k}}
\setkomafont{subsubsection}{\normalfont\sffamily\bfseries\color{hks15k}}
\setkomafont{paragraph}{\normalfont\scshape}

% footer settings
\rofoot{\normalfont\thepage\hspace*{2\baselineskip}}

\setcounter{secnumdepth}{0}             % no section numbering
\setlength{\parindent}{2\baselineskip}  % larger paragraph indent

\frenchspacing                          % no extra space after full stop

% footnote settings
\makeatletter
\deffootnotemark{\color{hks15k}\textsuperscript{\sffamily\bfseries\thefootnotemark}}
\long\def\@makefntext#1{\leavevmode%
{\sffamily\bfseries\color{hks15k}\@thefnmark\enskip}\nobreak
\relax#1%
}
\makeatother

\renewcommand{\blindmarkup}[1]{\emph{#1}}

\begin{document}
\blindtext\par\blindtext

\section{Lorem Ipsum}
\blindtext
\blindlist{enumerate}
\blindtext Footnote.\footnote{Knuth 1981: 123.}
\blindlist{itemize}
\blindtext Footnote.\footnote{\blindtext}
\blindtext\bigskip

\begin{mdframed}[hidealllines=true,backgroundcolor=hks89k!50]
\ttfamily
\begin{raggedright}
\blindtext\par
\end{raggedright}
\end{mdframed}

\blinddocument
\end{document}

-
And what about an example of result? –  m0nhawk May 1 '13 at 16:58
Here's the pdf that the above code results in, if that's what you mean. But there's no voodoo in it: it should work with every contemporary TeX distribution (I'm running vanilla TeXLive 2012) and with both pdfTeX and Xe/LuaLaTeX (I'm using the latter). Did you have trouble running it? –  Nils L May 1 '13 at 19:18
Isn't scrpage2 loaded by default in scrartcl? By the way, I'm still not convinced of the good looking of sans fonts for the titles. At this moment I think it's far more beautiful the main serified font. –  Manuel May 1 '13 at 20:18
I see your point, but IMHO beauty shouldn't be a goal one should pursue in typography. Maybe there even isn't such a thing as absolute beauty (which we could use as a standard by which to once-and-for-all judge a particular design). I'm more interested in how appropriate a particular design choice is in a given context, for a given audience, and for brining across a certain message. Would I use the above design for a book about Leonardo Da Vinci? Definitely not. But would I use this design for a documentation to a TeX package...? –  Nils L May 2 '13 at 20:13
I generally agree with your point. I would never consider this an example of good typesetting. The alignement of figures (one left, one right, text cramped in the middle), the use of bold-italic for captions, the line length ... This text is downright terrible to read. Somebody wanted his text to look fancy, and well he did. –  NauC May 11 '13 at 9:15