Graphics, Figures & TablesVertical alignment of text in cell next to table

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
dbmk
Posts: 5
Joined: Tue Dec 30, 2008 9:26 pm

Vertical alignment of text in cell next to table

Post by dbmk »

Hi guys and girls!

I have problem with alignment of text inside a longtable environment when a table is placed in the cell next to it.

Example in the following:

Code: Select all

\documentclass[a4paper,twoside]{report}

\usepackage{longtable}

\begin{document}

\begin{longtable}{@{}p{40mm}@{}p{110mm}}
 Blaa & \tabularnewline 
 \hline
 Blah Blah: & More blaa
\tabularnewline
Problem text: & 
\begin{tabular}{p{40mm}p{30mm}p{30mm}}
\hline
 \raggedright Type & \raggedright  & \raggedright Premie\newline denne periode
  \tabularnewline 
  \hline
  Blaa 1 &  Blaa 2  &  Blaa 3 \tabularnewline
  Blaa 1 &  Blaa 2  &  Blaa 3 \tabularnewline
  Blaa 1 &  Blaa 2  &  Blaa 3 \tabularnewline
  Blaa 1 &  Blaa 2  &  Blaa 3 \tabularnewline
  Blaa 1 &  Blaa 2  &  Blaa 3 \tabularnewline
  \cline{3-3}
 Superblaa &   &  some blaa   \tabularnewline 
 \cline{3-3}
\end{tabular} \tabularnewline
Last blas 1: & Last blaa 2 \newline Last blaa 2 \newline Last blaa 2 \tabularnewline
\end{longtable}

\end{document}
What I would like is for the "Problem text:" to be aligned to the top of the cell - basically aligning it with the top line of the table in the cell next to it. Like the texts in the last row basically. And having searched like crazy here and on the net in general I can't find a solution for it. But I figured there might be some sharp heads here that might be able to help.

What do I do?

Thanks in advance!

Recommended reading 2024:

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

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

Keta
Posts: 63
Joined: Tue Nov 25, 2008 1:00 pm

Vertical alignment of text in cell next to table

Post by Keta »

Not a final answer, as I don't know what really the problem is, but the following might work as an interim solution:

Code: Select all

\documentclass[a4paper,twoside]{report}

\usepackage{longtable}

\begin{document}

\begin{longtable}{@{}p{40mm}@{}p{110mm}}
Blaa & \tabularnewline
\hline
Blah Blah: & More blaa
\tabularnewline
Problem text: &
{\par\begin{tabular}{p{40mm}p{30mm}p{30mm}}
\hline
\raggedright Type & \raggedright  & \raggedright Premie\newline denne periode
  \tabularnewline
  \hline
  Blaa 1 &  Blaa 2  &  Blaa 3 \tabularnewline
  Blaa 1 &  Blaa 2  &  Blaa 3 \tabularnewline
  Blaa 1 &  Blaa 2  &  Blaa 3 \tabularnewline
  Blaa 1 &  Blaa 2  &  Blaa 3 \tabularnewline
  Blaa 1 &  Blaa 2  &  Blaa 3 \tabularnewline
  \cline{3-3}
Superblaa &   &  some blaa   \tabularnewline
\cline{3-3}
\end{tabular}} \tabularnewline
Last blas 1: & Last blaa 2 \newline Last blaa 2 \newline Last blaa 2 \tabularnewline
\end{longtable}

\end{document}
You can add some negative vertical space after the \par command to fine-tune the appearance, \vspace{-.8\baselineskip} looks more or less right.
dbmk
Posts: 5
Joined: Tue Dec 30, 2008 9:26 pm

Vertical alignment of text in cell next to table

Post by dbmk »

Does not quite work for me - but I appreciate the effort.

To be more clear, I would like the "Problem text" moved as indicated in the below picture:
Image

And to clarify; The red line is only to indicate the baseline I would like to see it on. Not something that should be part of the result. :)

Right now its centered vertically in relation to the table it seems. Which also messes with the row spacing when I try apply that.
daleif
Posts: 199
Joined: Wed Nov 19, 2008 12:46 am

Re: Vertical alignment of text in cell next to table

Post by daleif »

I do not understand why you use tables inside tables? You could do all of this in longtable alone.
daleif
Posts: 199
Joined: Wed Nov 19, 2008 12:46 am

Vertical alignment of text in cell next to table

Post by daleif »

Anywy this helps applied to the example from keta

Code: Select all

\cline{2-2}
Problem text: &
\begin{tabular}[t]{p{40mm}p{30mm}p{30mm}}
%\hline
it is the \hline at the top of the tabular that fcks things up, so we draw it in the outside table instead.

I would also recommend the booktabs package (or the memoir class) it provides better horisontal lines.
dbmk
Posts: 5
Joined: Tue Dec 30, 2008 9:26 pm

Vertical alignment of text in cell next to table

Post by dbmk »

daleif wrote:I do not understand why you use tables inside tables? You could do all of this in longtable alone.
Somewhat fair point as I have not laid out the way this comes about.

This is all created by a program and in its practical application has more content than is seen here. The content for each cell can vary - as much as longtable allows for at least.
Changing the "outside" table layout to incorporate this specific table as rows of the outside table, poses a host of other problems. There is the possibility that I might want other tables and table layouts in a cell - without having to change the surrounding table and cellspans for all the other cells each time.

And in general I am curios as how to control the vertical position in a cell. Can't find a solution for that anywhere. Maybe I am just bad at using the right search terms.

Should say that the length of my inner table can have different sizes depending on circumstances, so adding some space after the text to push it to the top can only work if it can be done in relation to the cell size, as far as I can tell. And I can't find a way to do that.

Ayways - appreciate that you took the time to ask. It was a good question and perhaps I should have anticipated it and made the circumstances clear in the original post.
dbmk
Posts: 5
Joined: Tue Dec 30, 2008 9:26 pm

Vertical alignment of text in cell next to table

Post by dbmk »

daleif wrote:Anywy this helps applied to the example from keta

Code: Select all

\cline{2-2}
Problem text: &
\begin{tabular}[t]{p{40mm}p{30mm}p{30mm}}
%\hline
it is the \hline at the top of the tabular that fcks things up, so we draw it in the outside table instead.

I would also recommend the booktabs package (or the memoir class) it provides better horisontal lines.
Ok, I just realised that I messed up in the picture I supplied. :oops:

Indicated the baseline in the wrong place. Corrected it.

I basically just want to align the text in the cell left of the table to the top of that cell, if that makes things clearer.
dbmk
Posts: 5
Joined: Tue Dec 30, 2008 9:26 pm

Vertical alignment of text in cell next to table

Post by dbmk »

daleif wrote:Anywy this helps applied to the example from keta

Code: Select all

\cline{2-2}
Problem text: &
\begin{tabular}[t]{p{40mm}p{30mm}p{30mm}}
%\hline
it is the \hline at the top of the tabular that fcks things up, so we draw it in the outside table instead.

I would also recommend the booktabs package (or the memoir class) it provides better horisontal lines.
You are right! I had tried with the [t] modifier - but it gave me the problem that the \hline was apparently responsible for. That it aligned to the bottom of the text on the left.

This I can work with, I think. Thanks a lot for you time and help.

I would still like to hear if there is a way to position the text vertically in the cell (top/center/bottom/somethinglikethat).

Thanks again!
Post Reply