Graphics, Figures & TablesHow do I control vertical spacing in a tabular environment?

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
craigim
Posts: 28
Joined: Sun Jan 14, 2007 6:19 pm

How do I control vertical spacing in a tabular environment?

Post by craigim »

I've got a table with pictures in them, a generic version of which is below. When I compile this, whether I use longtable or tabular, the text entries are aligned at the bottoms of their respective cells, with the baseline of the figures. I would like for them to be centered vertically. On the last lines, where there are two figures, but only one label, the names are properly centered vertically in their multirow cells. I tried doing \multirow{1}{*}{name4}, but to no avail.

Code: Select all

\begin{longtable}{cll}
\caption[Caption]{Long Caption}
\label{tab:table}\\
A & B & C \\
\includegraphics{Figures1}  & name1 & abbrv1 \\
\includegraphics{Figures2}  & name2 & abbrv2 \\
\includegraphics{Figures3}  & name3 & abbrv3 \\
\includegraphics{Figures4a} & \multirow{2}{*}{name4} & \multirow{2}{*}{abbrv4}\\
\includegraphics{Figures4b}
\end{longtable}
Any suggestions would be greatly appreciated...

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

How do I control vertical spacing in a tabular environment?

Post by gmedina »

Hi,

loading the array package, allows you to use m{<length>} in the declaration for the format table; refer to the package documentation for further information. Take a look at the following simple example:

Code: Select all

\documentclass{book}
\usepackage{longtable}
\usepackage{array}
\usepackage[demo]{graphicx}

\begin{document}

\begin{longtable}{>{\centering\arraybackslash}m{7cm}m{3cm}m{3cm}}
  \caption[Caption]{Long Caption}
  \label{tab:table}\\
  A & B & C \\
  \includegraphics{Figures1}  & name1 & abbrv1 \\
  \includegraphics{Figures2}  & name2 & abbrv2 \\
  \includegraphics{Figures3}  & name3 & abbrv3 \\
  \includegraphics{Figures4a} & name4 & abbrv4\\
  \includegraphics{Figures4b}
\end{longtable}

\end{document}
Remark: I used the demo option for the graphicx package to make the example compilable for everyone. Don't forget to not include that option in your actual document.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
craigim
Posts: 28
Joined: Sun Jan 14, 2007 6:19 pm

Re: How do I control vertical spacing in a tabular environment?

Post by craigim »

Almost perfect! However, the code above fixes the column widths, whereas before the widths were calculated on the fly. Is there a way for the widths to be variable, or do I just need to mess with it until they're right?
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

How do I control vertical spacing in a tabular environment?

Post by gmedina »

The tabulary package calculates column widths based on the contents; however, since you want vertical alignment inside cells, as far as I know, you have to use the m{..} declaration and determine the widths manually .
1,1,2,3,5,8,13,21,34,55,89,144,233,...
craigim
Posts: 28
Joined: Sun Jan 14, 2007 6:19 pm

Re: How do I control vertical spacing in a tabular environment?

Post by craigim »

I guess it's a fair trade, and with a few minutes of tweaking, my table looks much better now.

Thanks for your help!
yoyoimut
Posts: 120
Joined: Mon Oct 19, 2009 6:58 am

How do I control vertical spacing in a tabular environment?

Post by yoyoimut »

Hi,

I tried GMedina's code with a bit simplification.
Unfortunately, the contents in the cells are still not vertically aligned.
Please look at my screenshot below:

Image

And here is my code:

Code: Select all

\documentclass{book}
\usepackage{longtable}
\usepackage{array}
\usepackage[demo]{graphicx}

\begin{document}

\begin{longtable}{|>{\centering\arraybackslash}m{0.25\linewidth}|m{0.25\linewidth}|}\hline
  \includegraphics[width=\linewidth]{Figures1}  & name1  \\\hline
  \includegraphics[width=\linewidth]{Figures2}  & name2  \\\hline
\end{longtable}
\end{document}
I almost give up :D

Thank you in advance.
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

How do I control vertical spacing in a tabular environment?

Post by gmedina »

Hi,

you could try something like the following:

Code: Select all

\documentclass{article}
\usepackage{longtable}
\usepackage{array}
\usepackage[demo]{graphicx}

\begin{document}

\begin{longtable}{|>{\centering\arraybackslash}m{0.25\linewidth}|m{0.25\linewidth}|}\hline
  \vskip-5.5pt\includegraphics[width=\linewidth]{fibo} & name1  \\\hline
  \vskip-5.5pt\includegraphics[width=\linewidth]{fibo} & name2  \\\hline
\end{longtable}

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
yoyoimut
Posts: 120
Joined: Mon Oct 19, 2009 6:58 am

Re: How do I control vertical spacing in a tabular environment?

Post by yoyoimut »

Thanks for fast reply.

By the way, you get the number by trial and error?


Thank you.
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

How do I control vertical spacing in a tabular environment?

Post by gmedina »

yoyoimut wrote:Thanks for fast reply.

By the way, you get the number by trial and error?


Thank you.
You are welcome. And yes, it was trial and error. There must be a better solution, but right now I cannot think of it.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Post Reply