LaTeX is a high-quality open source typesetting software that produces professional prints and PDF files.

In this LaTeX tutorial, taken from by LaTeX Beginner’s Guide, you’ll learn how to line up text and data in columns and typeset complex tables.

(For more resources on this subject, see here.)

## How to align text in columns in LaTeX

Remember the time of the typewriter and early word processing software? When we needed to line up some text in columns, we could use tab stops. LaTeX provides a similar way to easily align text in columns, namely, the tabbing environment.

### Time for action – lining up information using the tabbing environment

We would like to present a quick overview regarding LaTeX. We shall present one point on each line, aligned at words and double colons:

1. Begin a new document and open a tabbing environment:

documentclass{article}
begin{document}
begin{tabbing}

2. Write the text, set tab stops by =, and end the line by \:

emph{Info:} = Software = : = LaTeX \

3. Add further lines, move to the next tab stop by >, and again end lines by \:

> Author > : > Leslie Lamport \
> Website > : > `www.latex-project.org`

4. Close the tabbing environment and end the document:

end{tabbing}
end{document}

5. Typeset to get the output:

### What just happened?

The tabbing environment that we used begins a new line. We used three simple tags for markup:

• = sets a tab stop. We could put several tab stops on a line. If we use = later, the next awaited tab stop would be reset to this position.
• \ ends a row.
• > goes to the next tab stop. This could also mean to go backwards.

This way, we can quickly produce columns containing left-aligned text. If the rows of the tabbing environment would reach the end of a page, it could continue on the next page. What if a column is too long, running over the tab stop? Let’s see how to solve that.

### Time for action – lining up font commands

Now we shall create a table:

1. Begin a new document, like the one in step 1 of our previous example, but define a command for setting the font of our header:

documentclass{article}
begin{document}
begin{tabbing}

2. Write the first row set tab stops by = and use > to move to the tab stops. Use the command verb…|| to typeset the LaTeX commands:

begin{tabbing}
Family = verb|textrm{…}| = head{Declaration} = kill
Family > verb|textrm{…}| > verb|rmfamily|
> rmfamily Example text\
> verb|textsf{…}| > verb|sffamily|
> sffamily Example text\
> verb|texttt{…}| > verb|ttfamily|
> ttfamily Example text
end{tabbing}

3. Typeset and examine:

4. As we can see, the tab stops are too narrow. We shall correct it. Create a new head row containing the tab stops; this time, we will mark the line by kill to hide that line. Use filler text to specify the width between the tab stops. Complete it with further font commands:

begin{tabbing}
Family = verb|textrm{…}| = head{Declaration} = kill
Family > verb|textrm{…}| > verb|rmfamily|
> rmfamily Example text\
> verb|textsf{…}| > verb|sffamily|
> sffamily Example text\
> verb|texttt{…}| > verb|ttfamily|
> ttfamily Example text
end{tabbing}

5. Typeset to get the result:

## What just happened?

After we noticed that our tab stops have been set too narrow, we constructed a new first row containing the tab stops. It consists of words representing the widest entries of each column. To hide this auxiliary row, we used the command kill right at the end of the line; kill at the end of a line causes this line to have no output.

Like in this example, the command verb|code| typesets code “as it is”, without interpreting commands within. Instead of |, any character may be chosen as the delimiter. verb cannot be used in arguments of commands including section and footnote, and not in table heads.
For longer, verbatim text, use the environment with the same name: verbatim.

There are further useful commands:

• + at the end of a line causes each subsequent line to start at the first tab. Use it twice ++ to start at the second tab and so on.
• cancels a preceding +; also using multiply has cumulative effect.
• at the beginning of a line cancels the effect of one previous + command for that line.

The mentioned commands already allow a good use of the tabbing environment. Even more commands can be found in the reference manual: http://texblog.net/help/latex/ tabbing.html.

Inside tabbing environments, declarations are local to the current item. A following =, >, \, or kill command would stop the effect.
Tabbing environments cannot be nested.

## Subscribe to the weekly Packt Hub newsletter. We'll send you the results of our AI Now Survey, featuring data and insights from across the tech landscape.

* indicates required