Graphics, Figures & TablesVertically aligning text because of figures inside a table

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Dan Golding
Posts: 2
Joined: Tue Jan 25, 2011 7:54 pm

Vertically aligning text because of figures inside a table

Post by Dan Golding »

Hi, I have a table with 3 columns of text and a fourth with images. This is my code so far:

Code: Select all

\begin{center}
        \begin{longtable}{llp{2cm}l}
            
            \caption{Data Set\label{tab:data}}\\

            \hline
            {\textbf{Bundle Name}} & {\textbf{File Name}} & {\textbf{Number of Fibres}} & {\textbf{Image}}\endfirsthead

            \caption*{Table~\ref{tab:data} continued: Data Set}\\
            \hline
            {\textbf{Bundle Name}} & {\textbf{File Name}} & {\textbf{Number of Fibres}} & {\textbf{Image}}\\ \hline\hline\\ \endhead
            
            \caption*{Table continues on next page}\endfoot
            
            \endlastfoot
            
            \hline
            \hline
            \\[-10pt]
            {Arcuate Fasciculus} & {arc1.fib} & {1} & {\includegraphics[scale = 0.08]{figs/Data/arc1_2.jpg}}\\
            \hline\\[-10pt]
            {\scriptsize Arcuate Fasciculus} & {\scriptsize arc1.fib} & {\scriptsize 2} & {\includegraphics[scale = 0.08]{figs/Data/arc1_2.jpg}}\\
            \hline\\[-10pt]
            {\scriptsize Arcuate Fasciculus} & {\scriptsize arc1.fib} & {\scriptsize 3} & {\includegraphics[scale = 0.08]{figs/Data/arc1_2.jpg}}\\
            \hline\\[-10pt]
            {\scriptsize Arcuate Fasciculus} & {\scriptsize arc1.fib} & {\scriptsize 4} & {\includegraphics[scale = 0.08]{figs/Data/arc1_2.jpg}}\\
            \hline\\[-10pt]
            {\scriptsize Arcuate Fasciculus} & {\scriptsize arc1.fib} & {\scriptsize 5} & {\includegraphics[scale = 0.08]{figs/Data/arc1_2.jpg}}\\
            \hline\\[-10pt]
            {\scriptsize Arcuate Fasciculus} & {\scriptsize arc1.fib} & {\scriptsize 6} & {\includegraphics[scale = 0.08]{figs/Data/arc1_2.jpg}}\\
            \hline\\[-10pt]
            {\scriptsize Arcuate Fasciculus} & {\scriptsize arc1.fib} & {\scriptsize 7} & {\includegraphics[scale = 0.08]{figs/Data/arc1_2.jpg}}\\
            \hline\\[-10pt]
        \end{longtable}
    \end{center}
It does pretty much everything I need except I can't get the text to be vertically centered. I tried replacing the {llp{2cm}l} with m{} but this only effects the headings, I think m{} only vertically centers a row if that row is extended due to text wrapping.

How can I get the text in the body of the table to be vertically centered? I would prefer if the headings were not affected but I can live with it if that makes it much more complicated.

Also I'm no expert at LaTeX so please if you do know how to do this, put an explanation along with any code so I can follow.

Thanks
Dan
Last edited by Dan Golding on Wed Jan 26, 2011 12:58 am, edited 1 time in total.

Recommended reading 2024:

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

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

frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Vertically aligning text because of figures inside a table

Post by frabjous »

This is really hard to answer without a proper minimal working example; in particular, without having access to your image, we cannot compile your code, and don't even know how big it is, which makes all the difference here.

Assuming it's the image here that is larger than everything else, the important thing should be that its column be given an m-specifier so that its middle lines up with the other lines of text. I.e., I'd try changing:

Code: Select all

\begin{longtable}{llp{2cm}l}
to

Code: Select all

\begin{longtable}{llp{2cm}m{3cm}}
Change the 3cm to whatever it needs to be to fit your image.

I don't know whether or not that would work, because I cannot test it. (See the Post on Avoidable Mistakes.)
Dan Golding
Posts: 2
Joined: Tue Jan 25, 2011 7:54 pm

Re: Vertically aligning text because of figures inside a tab

Post by Dan Golding »

Hi, thanks that worked perfectly! It's actually kind of obvious, I feel silly now.

The image size is 345x275 pixles and I'm scaling by 0.25. Coincidentally 3cm turns out to be exactly right too.

Thanks for the help!
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Vertically aligning text because of figures inside a table

Post by localghost »

Dan Golding wrote:Hi, thanks that worked perfectly! […]
Then please mark the topic accordingly as written in Section 3 of the Board Rules (to be read before posting).


Best regards and welcome to the board
Thorsten
Post Reply