Posts Tagged ‘table’
May 7, 2008
One of my last posts was on how to define the width of a column in a table (see here).
The parbox (p), which is used by Latex when you define the column width, will by default align its content on the left. This can be changed, but is a bit tricky.
The keyword is:
\raggedleft, \centering or \raggedright
Raggedleft will align text on the right-hand side, leaving whatever white space remains (ragged) on the left.
For a better understanding, let’s define right alignment of the text as a new column type, which can than be used in the very same way as pre-defined column types.
Defining a new column type needs the following package:
\usepackage{array}
\newcolumntype{x}[1]{%
>{\raggedleft\hspace{0pt}}p{#1}}%
The argument is the width of the column.
Now simply use “x{2cm}” instead of “p{2cm}”, for columns which align text on the right. By changing \raggedleft to \centering, you can align text in the centre.
Example:
\begin{table}\centering
\begin{tabular}{|l|x{4.5cm}|x{4.5cm}|}\hline
Nb. & Advantage & Disadvantage\tabularnewline\hline
1 & a & b \tabularnewline\hline
2 & b & a \tabularnewline\hline
\end{tabular}
\end{table}
Note:
An important last thing to mention, you cannot end lines with “\\”, as you defined your own column type. Therefore, I am using \tabularnewline in the example. If you want to save time, you might define your own command as follows:
\newcommand{\tn}{\tabularnewline}
Or even:
\newcommand{\tnhl}{\tabularnewline\hline}
Tags:centering, LaTex, raggedright, table, tabular, tabular raggedleft
Posted in Figure & table, LaTex, Tips & tricks | 7 Comments »
May 4, 2008
I am sure you know the situation where you have several columns in a tabular which all are of the same type:
\begin{tabular}{|r|c|c|c|c|c|}
Now this can be simplified as follows using the *(star) symbol:
\begin{tabular}{|r*{5}{|c}|}
The advantages are obvious, the table can be easily extended, you don’t have to count the numerous c’s, l’s or r’s and it saves you time.
Tags:LaTex, table, tabular
Posted in Figure & table, LaTex, Tips & tricks | 1 Comment »
May 4, 2008
Latex will automatically adjust the width of a cell in a table. If you wish to have a table where each cell in a row has the same width, you would use the p option instead of l, c or r for left, centre or right alignment.
Example:
\begin{table}[ht]
\centering
\begin{tabular}{|p{1cm}|p{1cm}|}
\hline
a&bbb\\
\hline
a&bbb\\
a&bbb\\
\hline
\end{tabular}
\end{table}
Tags:LaTex, table, tabular
Posted in Figure & table, LaTex, Tips & tricks | 7 Comments »
February 4, 2008
Pictures do not necessarily have to be placed inside the figure environment, but can perfectly be included inside table cells.
The advantage is, you can without any effort arrange a series of images in a matrix and individually scale them.
And here is how you would do it: You first need the graphicx package to include graphics:
\usepackage{graphicx}
Now you can directly start with your table environment and add graphics:
\begin{table}[ht]
\caption{A table arranging images}
\centering
\begin{tabular}{cc}
\includegraphics[scale=1]{graphic1}&\includegraphics[scale=1]{graphic2}\\
\newline
\includegraphics[scale=1]{graphic3}&\includegraphics[scale=1]{graphic4}\\
\end{tabular}
\label{tab:gt}
\end{table}%
Note: In order to have visual borders, you would have \hline instead of \newline and use horizontal bars in the column definition of the tabular environment (“|c|c|” instead of “cc”).
The downside of this technique is obvious, you do not have access to features provided by the figure environment like a label or caption. Nevertheless, it might still come in handy in certain situations.
Note: The figures will not appear in the \listoffigures index, for the reason mentioned above.
Tags:caption, figure, hline, label, LaTex, table, tabular
Posted in Figure & table, LaTex, Tips & tricks | 5 Comments »
October 15, 2007
Usually figures are placed wherever there is enough space, e.g. for “begin{figure}[ht]” at the beginning of the next page. What if you want to place the figure within the text, because you have other figures which you do not want to place only at the beginning of the second next page…
(more…)
Tags:article, book, figure, LaTex, report, table
Posted in Figure & table, LaTex, Tips & tricks | 2 Comments »
August 20, 2007
I recently had the following problem, I was using a label to reference a table where I placed the “tabular”- environment into the “small”- environment to decrease its size. The number indicated by the reference was not the table index, but rather the number of the section/subsection within which I placed the table. The problems seems to exist in both, Miktex and MacTex…
(more…)
Tags:article, book, label, LaTex, report, table, tabular
Posted in Figure & table, LaTex, Tips & tricks | 9 Comments »
August 7, 2007
I was asked to give an introduction to tables in Latex. Even though there are plenty of tutorials and pieces of Latex-code out there in the internet, it might still be useful to somebody who just started using Latex or has never publish a table before… (more…)
Tags:table, tabular
Posted in Figure & table, Introduction, LaTex | 4 Comments »
August 1, 2007
Including images in a report is very common. Structuring your work nicely is probably the most obvious reason why you want to put two figures/tables side-by-side. Another reason might be to save space, wherever a smaller size of an image is sufficient. The following code can be used to place two figures side-by-side by creating a minipage…
(more…)
Tags:article, book, code, figure, LaTex, minipage, report, table, tabular
Posted in Figure & table, LaTex, Tips & tricks | 39 Comments »