Creating Tables with LaTeX
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:

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:

As you can see the text is never wrapped, therefore it exceeds the paper width.
Trackback URL for this post:
If you like this article, subscribe to our full rss
Please post your question in our forum and use comments only to leave your comments about the article, thanks.













Post new comment