LaTeX/Paragraph Formatting

Altering the paragraph formatting is rarely necessary in academic writing. It is primarily used for formatting text in floats or for more exotic documents.

Paragraph alignment
Paragraphs in LaTeX are usually fully justified, i.e. flush with both the left and right margins. For whatever reason, should you wish to alter the justification of a paragraph, there are three environments at hand, and also LaTeX command equivalents.

All text between the and  of the specified environment will be justified appropriately. The commands listed are for use within other environments. For example, (paragraph) columns in.

However, if you really need to disable one of the above commands locally (for example because you have to use some broken package), you can use the command from package.

Paragraph indent
By default, the first paragraph after a heading follows the standard Anglo-American publishers' practice of no indentation. The size of subsequent paragraph indents is determined by a parameter called. The default length that this constant holds is set by the document class that you use. It is possible to override it by using the command. This will set paragraph indents to 1cm:

Whitespace in LaTeX can also be made flexible (what Lamport calls "rubber" lengths). This means that values such as extra vertical space inserted before a paragraph can have a default dimension plus an amount of expansion minus an amount of contraction. This is useful on pages in complex documents where not every page may be an exact number of fixed-height lines long, so some give-and-take in vertical space is useful. You specify this in a command like this:

If you want to indent a paragraph that is not indented, you can use

at the beginning of the paragraph. Obviously, this will only have an effect when is not set to zero. If you want to indent the beginning of every section, you can use the package: once loaded, the beginning of any chapter/section is indented by the usual paragraph indentation.

To create a non-indented paragraph, you can use

as the first command of the paragraph. This might come in handy when you start a document with body text and not with a sectioning command.

Be careful, however, if you decide to set the indent to zero, then it means you will need a vertical space between paragraphs in order to make them clear. The space between paragraphs is held in, which could be altered in a similar fashion as above. However, this parameter is used elsewhere too, such as in lists, which means you run the risk of making various parts of your document look very untidy by changing this setting. If you want to use the style of having no indentation with a space between paragraphs, use the package, which does this for you, while making adjustments to the spacing of lists and other structures which use paragraph spacing, so they don't get too far apart. If you want both indent and break, use

To indent subsequent lines of a paragraph, use the TeX command. (While the default behaviour is to apply the hanging indent after the first line, this may be changed with the command.)  An example follows.

The TeX commands and  add additional space to the left and right sides of each line, allowing the formatting for subsequent paragraphs to differ from the overall document margins. This space is in addition to the indentation added by and.

To change the indentation of the last line in a paragraph, use the TeX command.

Paragraph line break
Default style for may seem odd in the first place, as it writes the following text next to the title. If you do not like it, use a class other than the traditional article/book, or use ConTeXt or PlainTeX. Hacking of the class in use is really not the way LaTeX is intended to be used, and you may encounter a lot of frustrating issues.

Anyway, let's analyse the problem. If you add a manual line break with, LaTeX will complain that

There's no line here to end.

Simply adding an empty space will do it:

Alternatively, you can use the shorter, yet not completely equivalent syntax:

You can also change (an empty inline mathematical expression) for   or  in the above makeshift.

Line spacing
To change line spacing in the whole document use the command covered in Text Formatting.

Alternatively, you can use the package, which is also covered in Text Formatting. This package provides the commands, , and , which will specify the line spacing for all sections and paragraphs until another command is used. Furthermore, the package provides the following environments in order to change line spacing within the document but not document-wide:
 * : lines are double spaced;
 * : line spacing set to one-and-half spacing;
 * : normal line spacing;
 * : customizable line spacing, e.g..

See the section on customizing lists for information on how to change the line spacing in lists.

Manual breaks
LaTeX takes care of formatting, breaks included. You should avoid manual breaking as much as possible, for it could lead to very bad formatting.

Controlling the breaks should be reserved to macro and package writers. Here follows a quick reference.


 * If you use these comments to put a break in a section heading, the line will also be broken in the table of contents. To avoid such a division, you can use the command, which is described in sectioning commands.

The page breaks are covered in Page Layout. More details on manual spaces between paragraphs (such as ) can be found in Lengths.

Verbatim text
There are several ways to introduce text that won't be interpreted by the compiler. If you use the environment, everything input between the begin and end commands are processed as if by a typewriter. All spaces and new lines are reproduced as given, and the text is displayed in an appropriate fixed-width font. Any LaTeX command will be ignored and handled as plain text. This is ideal for typesetting program source code. Here is an example:

Note: once in the environment, the only command that will be recognized is. Any others will be output. The font size in the verbatim environment can be adjusted by placing a font size command before. If this is a problem, you can use the package instead, providing an environment with the same name:

Remember to add to your preamble to use it though! Within the environment, you can use the command  to get back the normal font. To write equations within the enviroment, you can use  and  to enclose them, instead of the usual.

When using inside the  enviroment, note that the standard font has no bold TT font. Txtfonts has bold fonts: just add after.

If you just want to introduce a short verbatim phrase, you don't need to use the whole environment, but you have the command:

The first character following is the delimiter: here we have used "+", but you can use any character you like except *;  will print verbatim all the text after it until it finds the next delimiter. For example, the code:

will print, ignoring the effect should have on text.

For more control over formatting, however, you can try the package, which provides a  environment (note the capital letter) which lets you draw a rule round the verbatim text, change the font size, and even have typographic effects inside the   environment. It can also be used in conjunction with the package and it can add reference line numbers (useful for chunks of data or programming), and it can even include entire external files.

To use verbatim in beamer, the frame needs to be made fragile:.

Typesetting URLs
One of either the or  packages provides the  command, which properly typesets URLs, for example:

will show this URL exactly as typed (similar to the command), but the  command also performs a hyphenless break at punctuation characters (only in PDFLaTeX, not in plain LaTeX+ dvips). It was designed for Web URLs, so it understands their syntax and will never break midway through an unpunctuated word, only at slashes and full stops. Bear in mind, however, that spaces are forbidden in URLs, so using spaces in arguments will fail, as will using other non-URL-valid characters.

When using this command through the package, the URL is "clickable" in the PDF document, whereas it is not linked to the web when using only the  package. Also when using the package, to remove the border placed around a URL, insert  inside the. (Alternately might work if the four zeroes do not.)

You can put the following code into your preamble to change the style, how URLs are displayed to the normal font:

See also Hyperlinks

Listing environment
This is also an extension of the verbatim environment provided by the package. The extra functionality it provides is that it can add line numbers alongside the text. The command is. The mandatory first line argument is for specifying which line the numbering should start at. The optional step is the step between numbered lines (the default is 1, which means every line will be numbered).

To use this environment, remember to add to the document preamble.

Multiline comments
As we have seen, the only way LaTeX allows you to add comments is by using the special character, that will comment out all the rest of the line after itself. This approach is really time-consuming if you want to insert long comments or just comment out a part of your document that you want to improve later, unless you're using an editor that automates this process. Alternatively, you can use the package, to be loaded in the preamble as usual:

(you can also use the package instead) you can use an environment called that will comment out everything within itself. Here is an example:

Note that this won’t work inside complex environments, like math for example. You may be wondering, why should I load a package called to have the possibility to add comments? The answer is straightforward: commented text is interpreted by the compiler just like verbatim text, the only difference is that verbatim text is introduced within the document, while the comment is just dropped.

Alternatively, you can define a command, by adding the following to the document's preamble:

Then, to comment out text, simply do something like this:

This approach can, however, produce unwanted spaces in the document, so it may work better to use

Then if you supply only one argument to, this has the desired effect without producing extra spaces.

Another drawback is that content is still parsed and possibly expanded, so you cannot put anything you want in it (such as LaTeX commands).

Skipping parts of the source
A more robust way of making the TeX engine skip some part of the source is to use the TeX -conditional. The typical use is

The -conditional is always false.

Quoting text
LaTeX provides several environments for quoting text; they have small differences and they are aimed for different types of quotations. All of them are indented on either margin, and you will need to add your own quotation marks if you want them. The provided environments are:
 * for a short quotation, or a series of small quotes, separated by blank lines.
 * for a short quotation, or a series of small quotes, separated by blank lines.


 * for use with longer quotations, of more than one paragraph, because it indents the first line of each paragraph.
 * for use with longer quotations, of more than one paragraph, because it indents the first line of each paragraph.


 * is for quotations where line breaks are important, such as poetry. Once in, new stanzas are created with a blank line, and new lines within a stanza are indicated using the newline command, . If a line takes up more than one line on the page, then all subsequent lines are indented until explicitly separated with.
 * is for quotations where line breaks are important, such as poetry. Once in, new stanzas are created with a blank line, and new lines within a stanza are indicated using the newline command, . If a line takes up more than one line on the page, then all subsequent lines are indented until explicitly separated with.

Abstracts
In scientific publications it is customary to start with an abstract which gives the reader a quick overview of what to expect. See Document Structure.