About these ads

On paragraphs in TeX/LaTeX

When writing documents in TeX/LaTeX, it is important to understand how the TeX engine “thinks”. A paragraph is the basic text unit in a document and many TeX/LaTeX commands, when used properly, affect the current paragraph only. TeX provides a set of basic commands controlling the way a paragraphs are typeset. The following article explains the most commonly used commands and illustrates them with examples.

Any piece of text in TeX/LaTeX is a paragraph and follows predefined specifications. Single line-breaks will be ignored by the engine. To end a paragraph, leave a blank line between the end of the current and the beginning of the new paragraph.

...end of the current paragraph.

Beginning of a new paragraph...

The second, indented line marks the beginning of a new paragraph.

ending_paragraph

Alternatively, \par might be used to end a paragraph.

\documentclass{article}
\usepackage{blindtext}
\begin{document}
\blindtext\par\blindtext
\end{document}

 

Paragraph width

In plain TeX, \hsize controls the paragraph width, set to 6.5in by default. The example below shows how to change the paragraph width for a single paragraph.

\documentclass{article}
\usepackage{blindtext}
\begin{document}
\blindtext

\hsize 4in
\blindtext
\end{document}

paragraph-width

The \leftskip and \rightskip commands provide a alternative, reducing the paragraph size from left and right respectively.

\documentclass{article}
\usepackage{blindtext}
\begin{document}
\blindtext

\leftskip=1.5in
\blindtext

\leftskip=0in \rightskip=1.5in
\blindtext
\end{document}

 
LaTeX knows at least two macros to control the paragraph width, the minipage environment and the \parbox command.

%Parbox macro
\parbox{4in}{...}

%Minipage environment
\begin{minipage}{4in}
...
\end{minipage}

 
Within a paragraph, the width is changed through the \hangindent and \hangafter commands. \hangindent controls the amount of indentation from left (positive value) or right (negative value). \hangafter, on the other hand, controls the number of full-width lines before changing the indent (\hangindent). A positive number produces full-width lines at the beginning, whereas a negative number produces them at the end.

Here is an example reducing the paragraph width by 2in from the right after the fifth line.

\documentclass[11pt]{article}
\usepackage{blindtext}
\begin{document}
\hangindent=-2in
\hangafter=5
\blindtext

\blindtext
\end{document}

hangindent-hangafter

 

Paragraph indentation

By default, TeX indents the first line of each paragraphs by 20pt. The \parindent command controls the indentation of paragraphs. To change the indentation document-wide, set \parindent in the document preamble to the desired value. To disable the indentation for a single paragraph, use \noindent at the beginning of the paragraph.

\documentclass{article}
\usepackage{blindtext}
\parindent=0pt % disables indentation
\begin{document}
\blindtext

\blindtext
\end{document}

paragraph-indent

 

Vertical space between paragraphs

TeX leaves no vertical space between paragraphs by default (\parskip=0pt). Similar to \parindent, setting \parskip in the document preamble controls the vertical space between paragraphs document-wide.

\documentclass{article}
\usepackage{blindtext}
\parskip=12pt % adds vertical space between paragraphs
\begin{document}
\blindtext

\blindtext
\end{document}

paragraph-vertical-space

 

Vertical space between lines

While using the default font size (10pt), the line distance is 12pt. A ratio of 1.2 (line height to font size) leaves enough space between lines for a good reading experience and gives a harmonious look. The line height can be changed through \baselineskip.

More on font size in LaTeX.

\documentclass{article}
\usepackage{blindtext}
\begin{document}
\blindtext

\baselineskip=20pt
\blindtext
\end{document}

paragraph-linespace

 

Further readings

A gentle introduction to TeX, a relatively short, but well written introduction to TeX by Michael Doob.

About these ads

4 Responses to “On paragraphs in TeX/LaTeX”

  • Ole J. Forsberg

    Your timing could not be more perfect. I spent much of Friday afternoon trying to do these things. Thank you.

  • Paavo

    Very helpful, thank you!

    Addition: to prevent the indentation of text after an equation, add only ONE line feed between them. (This may be trivial, not for me.)

    Follow-up question: is there an easy way to achieve the same effect after figures (which may be placed by LaTeX virtually anywhere)?

    • tom

      Hi Paavo,

      The same applies for figures and other floats. Do not leave any blank line, just continue your paragraph on the next line, right after \end{figure} and it will be place within the paragraph.

      Here is a MWE:

      \documentclass[11pt]{article}
      \usepackage{graphicx, blindtext}
      \begin{document}
      \blindtext
      \begin{figure}[ht]
      \centering
      \rule{\linewidth}{0.5\linewidth}
      \caption{Some figure}
      \end{figure}
      \blindtext
      \end{document}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 712 other followers

%d bloggers like this: