About
Shop
LaTeX
Software
Books
Gallery
News
Contact
Blog
Settings
Latest news 2019-11-04: The giveaway of two signed copies of “Quack, quack, quack. Give my hat back!” has closed and the winning entrants have been selected. Thank you to everyone who took part.


2.8.2 Optional Arguments

Some commands may have one or more optional arguments. Unlike mandatory arguments, optional arguments must always be enclosed in square brackets [ ].

Example:

The command \\ ends a line. So the following segment of code:

Line one\\Line two.

will produce the following output:

Line one <newline> Line two

However the \\ command also has an optional argument that allows you to specify how big the gap between the two lines should be. So the following segment of code:

Line one\\[1cm]Line two.

will produce the following output:

Line one <1cm vertical gap> Line two

Incidentally, note the difference between the previous example, and the following example:

Line one\\{[1cm]} Line two.

Image showing typeset output (click here for a more detailed description).

[Start of line goes awry]In this example the [1cm] has been placed inside a group, so it is no longer considered to be an optional argument, and since the command \\ does not take a mandatory argument, the [1cm] is simply interpreted as ordinary text.

Example:

The command \framebox (which will be covered later in §4.7.1. Framed Boxes) takes a mandatory argument and two optional arguments. \framebox puts a frame around the contents of its mandatory argument:

\framebox{Some Text}

Image of the words 'Some Text' inside a rectangular
box where there is a narrow gap between the edge of the text and the
frame

The first optional argument can be used to make the box a specified width:

\framebox[4cm]{Some Text}

Image of the words 'Some Text' centred inside a
rectangular box of width 4cm (plus a narrow gap)

The second optional argument specifies the justification of the text (left, right or centred) within the box:

\framebox[4cm][r]{Some Text}

Image of the words 'Some Text' right justified inside a
rectangular box of width 4cm (plus a narrow gap)

In general, if a command has both optional and mandatory arguments, the optional arguments are usually specified first (although there are a few exceptions).


This book is also available as A4 PDF or 12.8cm x 9.6cm PDF or paperback (ISBN 978-1-909440-00-5).

© 2012 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.

Terms of Use Privacy Policy Cookies Site Map FAQs