Chapter 2 – Tuning the Text

Here are the Code examples of this chapter. You can compile them online right on this web page by pressing the Typeset / Compile button. You can also edit them for testing and compile them again.

The code pages here are partially based on the First Edition of the book and are currently being edited to match the code of the Second Edition with all the additional examples. It is not complete yet since the focus was on the book production until weeks ago; please visit again soon!

Adding margin notes

\documentclass[paper=a4,oneside,fontsize=11pt,
  parskip=full]{scrartcl}
\usepackage{marginnote}
\usepackage{xcolor}
\renewcommand*{\marginfont}{\strut\color{blue}%
  \sffamily\scriptsize}
\begin{document}
\addsec{Introduction}
This document will be our starting point for simple
documents.\marginnote{No chapters supported!}
It is suitable for a single page or up to
a couple of dozen pages.

The text will be divided into sections.
\marginnote{Subsections are the next level.}
\end{document}

Reversed:

\documentclass[paper=a4,oneside,fontsize=11pt,
  parskip=full]{scrartcl}
\usepackage{marginnote}
\usepackage{xcolor}
%\usepackage{showframe}
\renewcommand*{\marginfont}{\strut\color{blue}%
  \sffamily\scriptsize}
\begin{document}
\addsec{Introduction}
\reversemarginpar
This document will be our starting point for simple
documents.\marginnote{No chapters supported!}
It is suitable for a single page or up to
a couple of dozen pages.

The text will be divided into sections.
\marginnote{Subsections are the next level.}
\end{document}

Converting numbers to words

\documentclass{article}
\usepackage{fmtcount}
\begin{document}
\section{Introduction}
This document should have \numberstringnum{32}
pages, now we are on page \numberstring{page}
in the \ordinalstring{section} section.
\end{document}

Modified numbered list:

\documentclass{article}
\usepackage{moreenum}
\begin{document}
\begin{enumerate}[label=\Nthwords*]
  \item live
  \item long
  \item prosper
\end{enumerate}
\end{document}

Putting text into a colorful box

\documentclass{article}
\usepackage[english]{babel}
\usepackage[pangram]{blindtext}
\usepackage{tcolorbox}
\begin{document}
\begin{tcolorbox}
  \blindtext
\end{tcolorbox}

\begin{tcolorbox}[title=\textbf{Examples},
  colback=blue!5!white,colframe=blue!75!white]
  The text below consists of pangrams.
  \tcblower
  \blindtext[3]
\end{tcolorbox}

\tcbset{colframe=green!50!black,colback=white,
  colupper=green!30!black,fonttitle=\bfseries, center title,
  nobeforeafter, tcbox raise base}
  Normal text \tcbox{Boxed text}
\tcbox[left=0pt,right=0pt,top=0.5ex,bottom=0pt,boxsep=0pt,
  toptitle=0.5ex,bottomtitle=0.5ex,title=Sample table]{
  \begin{tabular}[t]{rl}
    Number & 100 \\
    Sum    & 350
  \end{tabular}}
\end{document}

Visualizing the layout

\documentclass[paper=a4,oneside,fontsize=11pt,
  parskip=full]{scrartcl}
\usepackage{showframe}
\pagestyle{empty}
\begin{document}
\tableofcontents
\addsec{Introduction}
This document will be our starting point for simple
documents. It is suitable for a single page or up to
a couple of dozen pages.

The text will be divided into sections.
\section{The first section}
This first text will contain
\begin{itemize}
  \item a table of contents,
  \item a bulleted list,
  \item headings and some text and math in section,
  \item referencing such as to section \ref{sec:maths} and
      equation (\ref{eq:integral}).
\end{itemize}
We can use this document as a template for filling in
our own content.
\section{Some maths}
\label{sec:maths}
When we write a scientific or technical document, we usually
include math formulas. To get a brief glimpse of the look of
maths, we will look at an integral approximation of a function
$f(x)$ as a sum with weights $w_i$:
\begin{equation}
  \label{eq:integral}
  \int_a^b f(x)\,\mathrm{d}x \approx (b-a)
  \sum_{i=0}^n w_i f(x_i)
\end{equation}
\end{document}

With the geometry package:

\documentclass[paper=a4,oneside,fontsize=11pt,
  parskip=full]{scrartcl}
\usepackage[a4paper,bindingoffset=5mm,showframe]{geometry}
\geometry{showframe}
\begin{document}
\tableofcontents
\addsec{Introduction}
This document will be our starting point for simple
documents. It is suitable for a single page or up to
a couple of dozen pages.

The text will be divided into sections.
\section{The first section}
This first text will contain
\begin{itemize}
  \item a table of contents,
  \item a bulleted list,
  \item headings and some text and math in section,
  \item referencing such as to section \ref{sec:maths} and
        equation (\ref{eq:integral}).
\end{itemize}
We can use this document as a template for filling in
our own content.
\section{Some maths}
\label{sec:maths}
When we write a scientific or technical document, we usually
include math formulas. To get a brief glimpse of the look of
maths, we will look at an integral approximation of a function
$f(x)$ as a sum with weights $w_i$:
\begin{equation}
  \label{eq:integral}
  \int_a^b f(x)\,\mathrm{d}x \approx (b-a)
  \sum_{i=0}^n w_i f(x_i)
\end{equation}
\end{document}

Page layout:

\documentclass[paper=a4,oneside,fontsize=11pt,
  parskip=full]{scrartcl}
\usepackage{layout}
\begin{document}
\layout
\tableofcontents
\addsec{Introduction}
This document will be our starting point for simple
documents. It is suitable for a single page or up to
a couple of dozen pages.

The text will be divided into sections.
\section{The first section}
This first text will contain
\begin{itemize}
  \item a table of contents,
  \item a bulleted list,
  \item headings and some text and math in section,
  \item referencing such as to section \ref{sec:maths} and
        equation (\ref{eq:integral}).
\end{itemize}
We can use this document as a template for filling in
our own content.
\section{Some maths}
\label{sec:maths}
When we write a scientific or technical document, we usually
include math formulas. To get a brief glimpse of the look of
maths, we will look at an integral approximation of a function
$f(x)$ as a sum with weights $w_i$:
\begin{equation}
  \label{eq:integral}
  \int_a^b f(x)\,\mathrm{d}x \approx (b-a)
  \sum_{i=0}^n w_i f(x_i)
\end{equation}
\end{document}

Visualizing boxes of letters and symbols

% !TEX=lualatex
\documentclass[paper=a4,oneside,fontsize=11pt,
  parskip=full]{scrartcl}
\usepackage{lua-visual-debug}
\pagestyle{empty}
\begin{document}
\tableofcontents
\addsec{Introduction}
This document will be our starting point for simple
documents. It is suitable for a single page or up to
a couple of dozen pages.

The text will be divided into sections.
\section{The first section}
This first text will contain
\begin{itemize}
  \item a table of contents,
  \item a bulleted list,
  \item headings and some text and math in section,
  \item referencing such as to section \ref{sec:maths} and
        equation (\ref{eq:integral}).
\end{itemize}
We can use this document as a template for filling in
our own content.
\section{Some maths}
\label{sec:maths}
When we write a scientific or technical document, we usually
include math formulas. To get a brief glimpse of the look of
maths, we will look at an integral approximation of a function
$f(x)$ as a sum with weights $w_i$:
\begin{equation}
  \label{eq:integral}
  \int_a^b f(x)\,\mathrm{d}x \approx (b-a)
  \sum_{i=0}^n w_i f(x_i)
\end{equation}
\end{document}

Typesetting in a grid

\documentclass{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{microtype}
\usepackage[fontsize=10pt,baseline=12pt]{grid}
\begin{document}
\twocolumn
\section*{Two columns}
\blindtext[3]
\begin{figure}
  \centering
  \fbox{\makebox(50,50){}}
  \caption{A dummy figure}
\end{figure}
\begin{gridenv}
  \begin{equation}
    \sum_n f(n)
  \end{equation}
\end{gridenv}
Text
\end{document}

\documentclass{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{microtype}
\begin{document}
\twocolumn
\section*{Two columns}
\blindtext[3]
\begin{figure}
  \centering
  \fbox{\makebox(50,50){}}
  \caption{A dummy figure}
\end{figure}
\begin{equation}
\sum_n f(n)
\end{equation}
Text
\end{document}

\documentclass{article}% compile until last test is stable
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{microtype}
\usepackage[fontsize=10pt,baseline=12pt]{grid}
\usepackage{gridset}
\usepackage{amsmath}
\begin{document}
\twocolumn
\section*{Two columns}
\blindtext[3]
\begin{figure}
  \centering
  \fbox{\makebox(50,50){}}
  \caption{A dummy figure}
\end{figure}
\begin{align}
  y &= \sum_{n=1}^3 f(n) \\
    &= f(1) + f(2) + f(3)
\end{align}
\par\vskipnextgrid\noindent
Text
\end{document}

Absolute positioning of text

\documentclass[a5paper]{article}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{showframe}
\usepackage{eso-pic}
\usepackage{picture}
\pagestyle{empty}
\begin{document}
\AddToShipoutPictureBG{%
  \setlength{\unitlength}{1cm}%
  \put(2.5,2){Test document}%
  \put(\paperwidth-2cm,2cm){\llap{\thepage}}%
}
\AddToShipoutPictureBG*{%
  \AtPageLowerLeft{Page bottom left}%
  \AtPageUpperLeft{\raisebox{-\height}{Page top left}}%
  \AtTextUpperLeft{\raisebox{-\height}{%
    \color{red}Text area top left}}%
}
\AddToShipoutPictureFG{%
  \AtPageCenter{\rotatebox{15}{\makebox[0pt]{%
    \Huge\bfseries\color{red}Confidential}}}%
}
\lipsum
\end{document}

Adding drop caps

\documentclass{book}
\usepackage[a6paper]{geometry}
\usepackage{lettrine}
\begin{document}
\lettrine{O}{nce upon a time}, professional writer used
a mechanical machine called a typewriter. It commonly
printed fixed-width characters. Emphasizing was done by 
writing all capitals, and by underlining.
\end{document}
\documentclass{book}
\usepackage[a6paper,hmargin=1.5cm]{geometry}
\usepackage{microtype}
\usepackage{coloredlettrine}
\renewcommand{\EBLettrineBackColor}{SlateBlue}
\setcounter{DefaultLines}{3}
\renewcommand{\DefaultLraise}{0.25}
\renewcommand{\DefaultFindent}{0.3em}
\renewcommand{\DefaultNindent}{0pt}
\begin{document}
\coloredlettrine{O}{nce upon a time}, professional
writers used a mechanical machine called a typewriter.
It commonly printed fixed-width characters. 
Emphasizing was done by writing all capitals
and by underlining.

\coloredlettrine{T}{oday}, we prefer variable-width
letters. It’s common to provide subtle emphasis by using
italics or to add greater emphasis by using bold text.
\end{document}

Fitting text to a shape

\documentclass{article}
\usepackage{blindtext}
\usepackage{shapepar}
\pagestyle{empty}
\begin{document}
\shapepar{\heartshape}\blindtext[2]
\end{document}

Cutting out shapes

\documentclass{article}
\usepackage{blindtext}
\usepackage{shapepar}
\pagestyle{empty}
\begin{document}
\cutout{l} (5ex,2\baselineskip) \setlength{\cutoutsep}{8pt}
  \shapepar{\circleshape} a few words of text\par
\blindtext
\end{document}

Creating a pull quote

\documentclass{article}
\usepackage{lipsum}
\usepackage{pullquote}
% http://bazaar.launchpad.net/~tex-sx/tex-sx/development/view/head:/pullquote.dtx
\newcommand{\myquote}{%
  \parbox{4cm}{
    \hrule\vspace{1ex}
    \textit{I can’t go to a restaurant and order food
      because I keep looking at the fonts on the menu.}

    \hfill Knuth, Donald (2002)%
    \vspace{1ex}
    \hrule
  }%
}
\pagestyle{empty}
\begin{document}
\begin{pullquote}{object=\myquote}
  \lipsum[1]
\end{pullquote}
\end{document}

\documentclass{article}
\usepackage{lipsum}
\usepackage{pullquote}
% http://bazaar.launchpad.net/~tex-sx/tex-sx/development/view/head:/pullquote.dtx
\usepackage{tikz}
\newcommand{\mylogo}{%
  \begin{tikzpicture} 
    \node[shape=circle,draw=gray!40,line width=3pt,
      fill={gray!15},font=\Huge] {\TeX};
  \end{tikzpicture}%
}
\pagestyle{empty}
\begin{document}
\begin{pullquote}{shape=circular,object=\mylogo}
  \lipsum[1]
\end{pullquote}
\end{document}

Go to next chapter.