Anda di halaman 1dari 10

Sections and chapters - ShareLaTeX, Online LaTeX Editor 2/8/17 13(48

Sections and chapters


Documents usually have some levels of chapters and/or sections to keep its
contents organized. LaTeX supports this type of organization and also
customization of the sectioning and numbering.

Introduction

Commands to organize a document vary depending on the document type,


the simplest form of organization is the sectioning, available in all formats.

\documentclass{article}
\usepackage{blindtext}
\usepackage[utf8]{inputenc}

\title{Sections and Chapters}


\author{Gubert Farnsworth}
\date{\today}

\begin{document}

\maketitle

\section{Introduction}

This is the first section.

Lorem ipsum dolor sit amet, consectetuer adipiscing


elit. Etiam lobortisfacilisis sem. Nullam nec mi et
neque pharetra sollicitudin. Praesent imperdietmi nec ante.
Donec ullamcorper, felis non sodales...

\section{Second Section}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.


Etiam lobortis facilisissem. Nullam nec mi et neque pharetra
sollicitudin. Praesent imperdiet mi necante...

\end{document}

https://www.sharelatex.com/learn/Sections_and_chapters Página 1 de 10
Sections and chapters - ShareLaTeX, Online LaTeX Editor 2/8/17 13(48

The command \section{} marks the beginning of a new section, inside the
braces is set the title. Section numbering is automatic and can be disabled.

Open an example in ShareLaTeX

Document Sectioning

LaTeX can organize, number, and index chapters and sections of


document. There are up to 7 levels of depth for defining sections
depending on the document class:

-1 \part{part}

0 \chapter{chapter}

1 \section{section}

2 \subsection{subsection}

3 \subsubsection{subsubsection}

4 \paragraph{paragraph}

5 \subparagraph{subparagraph}

\part and \chapter are only available in report and book document

https://www.sharelatex.com/learn/Sections_and_chapters Página 2 de 10
Sections and chapters - ShareLaTeX, Online LaTeX Editor 2/8/17 13(48

classes.

Open an example in ShareLaTeX

Numbered and unnumbered sections

To get an unnumbered chapter, section, sub-section, etc. add an asterisk


before the opening curly brace. These will not go into the table of contents.

\documentclass{article}
\usepackage{blindtext}
\usepackage[utf8]{inputenc}

\title{Sections and Chapters}


\author{Gubert Farnsworth}
\date{\today}

\begin{document}

\maketitle

\section*{Introduction}

This is the first section.

Lorem ipsum dolor sit amet, consectetuer adipiscing


elit. Etiam lobortisfacilisis sem. Nullam nec mi et
neque pharetra sollicitudin. Praesent imperdietmi nec ante.
Donec ullamcorper, felis non sodales...

\section*{Second Section}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.


Etiam lobortis facilisissem. Nullam nec mi et neque pharetra
sollicitudin. Praesent imperdiet mi necante...

\end{document}

https://www.sharelatex.com/learn/Sections_and_chapters Página 3 de 10
Sections and chapters - ShareLaTeX, Online LaTeX Editor 2/8/17 13(48

To add an unnumbered section to the table of contents, use the


\addcontentsline command like this:

\addcontentsline{toc}{section}{Title of the section}

See the article Table of contents for an example and description of this
command.

Open an example in ShareLaTeX

Document chapters and sections in a Book/Report

As mentioned before, \chapter can be used in documents and reports.


Below you can see an example:

\documentclass{report}

\begin{document}

\tableofcontents{}

\chapter{Editing compile}

https://www.sharelatex.com/learn/Sections_and_chapters Página 4 de 10
Sections and chapters - ShareLaTeX, Online LaTeX Editor 2/8/17 13(48

\section{First Compile}

how to compile basic hello world into a pdf.

Write your favorite text editor create file and copy/paste the following (with hel

\subsection{Output formats}

different output formats (dvi, pdf)

The output of this command \$latex hello.tex will be a dvi


file (hello.dvi). This file (.dvi) can be converted by \$dvipdf
hello.dvi The get an pdf file from tex file, run this
command \$texi2pdf hello.tex

\chapter{Document Structure}

\section{Reserved Characters}

The following symbols characters are reserved by LATEX because


they introduce a command and have a special meaning.

\end{document}

Books are the most complex type of documents when it comes to grouping
the content in sections. Below a complete example with parts, chapters,
sections and subsections

https://www.sharelatex.com/learn/Sections_and_chapters Página 5 de 10
Sections and chapters - ShareLaTeX, Online LaTeX Editor 2/8/17 13(48

\documentclass{book}
\usepackage[utf8]{inputenc}

\title{42}
\author{Jane Doe}
\date{\today}

\begin{document}

\maketitle

\tableofcontents

\part{First Part of this document}

\chapter{First}

\section{Introduction}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
enim ad minim veniam, quis nostrud exercitation ullamco...

\subsection{Sample subsection}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
enim ad minim veniam, quis nostrud exercitation ullamco laboris..

\subsubsection{Sample subsubsection}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
enim ad minim veniam, quis nostrud exercita...

https://www.sharelatex.com/learn/Sections_and_chapters Página 6 de 10
Sections and chapters - ShareLaTeX, Online LaTeX Editor 2/8/17 13(48

Open an example in ShareLaTeX

Customize chapters and sections

You can use the titlesec package to customize chapters, sections and
subsections style in an easy way.

\documentclass[a4paper,12pt]{book}
\usepackage[utf8]{inputenc}
\usepackage{titlesec}

\titleformat
{\chapter} % command
[display] % shape
{\bfseries\Large\itshape} % format
{Story No. \ \thechapter} % label
{0.5ex} % sep
{
\rule{\textwidth}{1pt}
\vspace{1ex}
\centering
} % before-code
[
\vspace{-0.5ex}%
\rule{\textwidth}{0.3pt}
] % after-code

\titleformat{\section}[wrap]
{\normalfont\bfseries}
{\thesection.}{0.5em}{}

\titlespacing{\section}{12pc}{1.5ex plus .1ex minus .2ex}{1pc}

\begin{document}

\chapter{Let's begin}

\section{First Attempt}

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do


eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut

https://www.sharelatex.com/learn/Sections_and_chapters Página 7 de 10
Sections and chapters - ShareLaTeX, Online LaTeX Editor 2/8/17 13(48

enim ad minim veniam, quis nostrud exercitation ullamco laboris...

\section{Second attempt}

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do


eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
enim ad minim veniam, quis nostrud exercitation ullamco laboris...

\end{document}

There are two general commands:

\titleformat{<command>}[<shape>]{<format>}{<label>}{<sep>}{<before-code>}[

where [<shape>] and [<after-code>] are optional parameters, and:

<command> is the sectioning command to be redefined: \part, \chapter,


\section, \subsection, \subsubsection, \paragraph or \subparagraph.
<shape> is sectioning paragraph shape; possible values are: hang,
block, display, runin, leftmargin, rightmargin, drop, wrap, frame.
<format> is the format to be applied to the title, label, and text; for
example \normalfont\Large\bfseries
<label> specify sectioning label.
<sep> is the horizontal separation between label and title body and it

https://www.sharelatex.com/learn/Sections_and_chapters Página 8 de 10
Sections and chapters - ShareLaTeX, Online LaTeX Editor 2/8/17 13(48

must be a length and not be empty.


<before-code> is code preceding the title body.
<after-code> is code following the title body.

and

\titlespacing{<command>}{<left>}{<before-sep>}{<after-sep>}

where:

<left> increases the left margin.


<before-sep> is the vertical space before the title.
<after-sep> is the separation between title and non-sectioning text.

The starred version of this command (\titlespacing*) kills the


indentation of the paragraph following the title.

Open an example of the titlesec package in ShareLaTeX

Further reading

For more information see:

Creating a document in LaTeX


Bold, italics and underlining
Table of contents
Cross referencing sections and equations
Management in a large project
Multi-file LaTeX projects
Hyperlinks
Page numbering
Single sided and double sided documents
Multiple columns
Counters

https://www.sharelatex.com/learn/Sections_and_chapters Página 9 de 10
Sections and chapters - ShareLaTeX, Online LaTeX Editor 2/8/17 13(48

Font sizes, families, and styles


titlesec package manual

https://www.sharelatex.com/learn/Sections_and_chapters Página 10 de 10