Enter your email address:

Delivered by FeedBurner

Creating Tables with LaTeX


StumbleUpon Toolbar

It is normal the need to add tables into documents, If you are using LaTeX to write your documents this goal can also be achieved in a very simple way.

We will have to use the tabular environment.

the format for this is:

\begin{tabular}[pos]{table spec}

Where:

pos
Can be eiter:

  • b = bottom
  • c = center
  • t = top
table spec
Can either:
  • l = left-justified column
  • c = centered column
  • r = right-justified column
  • p{width} = paragraph column with text vertically aligned at the top
  • m{width} = paragraph column with text vertically aligned in the middle (requires array package)
  • b{width} = paragraph column with text vertically aligned at the bottom (requires array package)
  • | = vertical line
  • || = double vertical line

With these tools we can start making tables:

\begin{center}
\begin{tabular}{||p{2.5cm}|p{2.5cm}|p{2.5cm}|p{2.5cm}|p{2.5cm}|p{2.5cm}||}
\hline
\textbf{Column 1} & \textbf{Column 2} & \textbf{Column 3} & \textbf{Column 4} & \textbf{Column 5} & \textbf{Column 6} \\ \hline
Linux & is  & a  & great & operating & system \\ \hline
xx & xx & xx & xx & xx & xx \\ \hline
\end{tabular}
\end{center}

This will create a table like this one:

Latex Table with Linux screen shot

Now explain it a little, first the \begin{center} is centering the table in the document, then we start with the table itself, we declare the environment with \begin{tabular} and the specify the columns we are using p{2.5cm} to specify a column 1 inch wide (2.5 cm), as you can also see we are using double || lines at the left and right and only one | in as columns separators, to draw the horizontal lines we use \hline where we need them.

Note that is you do not use p{width} and make a table like this:

\begin{center}
\begin{tabular}{||l|c|c|c|c|r||}
\hline
\textbf{Column 1} & \textbf{Column 2} & \textbf{Column 3} & \textbf{Column 4} & \textbf{Column 5} & \textbf{Column 6} \\ \hline
Linux & is  & a  & great & operating & system \\ \hline
xx & xx & this sentence will never be wrapped and will continue to grow no matter if it extent beyond the paper margins & xx & xx & xx \\ \hline
\end{tabular}
\end{center}

This will be the result:

Latex Table with Linux screen shot 2

As you can see the text is never wrapped, therefore it exceeds the paper width.

LaTeX tutorial

Trackback URL for this post:

http://www.go2linux.org/trackback/367
StumbleUpon Toolbar

 If you like this article, subscribe to our full rss

If this article was somehow useful for you, you can leave something in the tip's jar

Please post your question in our forum and use comments only to leave your comments about the article, thanks.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

Captcha
This question is for testing whether you are a human visitor and to prevent automated spam submissions.

This site is proudly hosted at Bluefur Hosting