[Tex/LaTex] Vertical alignment (top, center, bottom) of figure and two texts in tabular

tablesvertical alignment

Based on Tabular alignment of text and figure, my question is how can I get t, c, b alignment of all 3 elements that make part of tabular. The t and c works fine, but not the b.

\documentclass[10pt,a4paper]{scrartcl}

\usepackage[pass,showframe]{geometry}
\usepackage{graphicx}
\usepackage{array}

\usepackage{varwidth}

\newcommand*{\mtab}[2][]{\begin{tabular}[#1]{@{}l@{}} #2 \end{tabular}}
\newcommand*{\pbox}[2][c]{\mtab[#1]{\begin{varwidth}[#1]{\linewidth}#2\end{varwidth}}}

\newcommand*{\Logo}{\includegraphics[width=\linewidth]{example-image}}

\begin{document}

\begingroup
\noindent
\begin{tabular}{@{}p{0.15\textwidth}<{\hfill}>{\centering}p{0.5\textwidth}>{\hfill}p{\dimexpr 0.35\textwidth-4\tabcolsep\relax}@{}}
\pbox[b]{\raisebox{\dimexpr-\height+\ht\strutbox\relax}{\Logo}} & \pbox[b]{aaa\\ bbb\\ ccc\\ ddd} & \pbox[b]{eee\\ fff\\ hhh hhh hhh hhh hhh hhh}
\end{tabular}
\endgroup

\end{document}

Best Answer

You've got so many nested boxes; it's very hard to tell what purpose you're expecting them all to serve. I'm also not sure why you need a tabular environment for any of this. Perhaps, if you could make that need a bit more clear, I could give you a better answer.

Also, it seems that you are under the impression that the alignment commands of the boxes and tabular environments are relative to each other. They're not. The alignment commands are relative to the baseline that each box sits on. In the MWE I'm posting, I construct a red line to show where the baseline is and how everything else is being aligned with respect to it.

Here's an example which hugely cuts down on the number of boxes. I then illustrate different ways of aligning the various elements: either through the alignment argument to tabular or through using \raisebox and its ability to access the dimensions of the box its working on.

\documentclass{article}
%..%
\usepackage[showframe]{geometry}
\usepackage{graphicx}
\usepackage{xcolor}
\pagestyle{empty}
%..%
\setlength{\fboxsep}{0pt}
\setlength{\parindent}{0pt}
%..%
\newcommand{\showbaseline}{\makebox[0pt][l]{\color{red!60}\hspace*{-1cm}\rule[-0.1pt]{\dimexpr\linewidth+2cm}{0.1pt}}}
\begin{document}


There are way too many boxes:

\noindent
\showbaseline%
\begin{minipage}[t]{0.15\textwidth}
    \raisebox{-0.5\height}%
    {\includegraphics[width=\linewidth]{example-image}}
\end{minipage}%
\hspace*{\fill}%
\raisebox{0pt}{%
    \begin{minipage}[t]{0.5\textwidth}
        \hspace*{\fill}
        \fbox{\begin{tabular}[b]{@{}l@{}} 
                aqaa\\ bbb\\ cycc\\ dydd
        \end{tabular}}
        \hspace*{\fill}
    \end{minipage}}%
\hspace*{\fill}%
    \begin{minipage}[t]{\dimexpr 0.35\textwidth}
        \hspace*{\fill}
        \fbox{\begin{tabular}[b]{@{}l@{}}  
            fff\\ hhh
        \end{tabular}}
    \end{minipage}%


\vspace{\fill}

%-@-(1)---------------------------------------------------------------------
Similar, but with far fewer boxes:  I say \emph{similar} because I'm using
\verb-\hspace*{\stretch{...}}- to achieve part of the effect of your box widths.

\noindent
\showbaseline%
    \raisebox{-0.5\height}%
    {\includegraphics[width=0.15\linewidth]{example-image}}
\hspace*{\stretch{1}}%
    \fbox{\begin{tabular}[b]{@{}l@{}} 
            aqaa\\ bbb\\ cycc\\ dydd
    \end{tabular}}
\hspace*{\stretch{2.45}}%
    \fbox{\begin{tabular}[c]{@{}l@{}}  
        fff\\ hhh
    \end{tabular}}


\vspace{\fill}

%-@-(2)---------------------------------------------------------------------
A different alignment.

\noindent
\showbaseline%
    \raisebox{-\height}%
    {\includegraphics[width=0.15\linewidth]{example-image}}
\hspace*{\stretch{1}}%
    \fbox{\begin{tabular}[t]{@{}l@{}} 
            aqaa\\ bbb\\ cycc\\ dydd
    \end{tabular}}
\hspace*{\stretch{2.45}}%
    \fbox{\begin{tabular}[b]{@{}l@{}}  
        fff\\ hhh
    \end{tabular}}


\vspace{\fill}

%-@-(3)---------------------------------------------------------------------
Another alignment:  notice the added \verb-\raisebox- to get the first
\verb-tabular- to completely sit on the baseline and the last
\verb-tabular- environment below the baseline.  This is because
\verb-\raisebox-  has access to the dimensions of the boxes it's working on.

\noindent
\showbaseline%
    % not raising the graphics%\raisebox{-\height}%
    {\includegraphics[width=0.15\linewidth]{example-image}}
\hspace*{\stretch{1}}%
    \raisebox{\depth}{%
    \fbox{\begin{tabular}[c]{@{}l@{}} 
            aqaa\\ bbb\\ cycc\\ dydd
    \end{tabular}}}
\hspace*{\stretch{2.45}}%
    \raisebox{-\height}{%
    \fbox{\begin{tabular}[t]{@{}l@{}}  
        fff\\ hhh
    \end{tabular}}}

\end{document}

enter image description here

Certainly, by nesting boxes, you can achieve various effects in terms of alignment. But, you can also make things unexpectedly more complicated because you're essentially creating multiple baselines: the main baseline of your text and the baselines within each box you're working with. This can work against you. And, I believe this is what's leading to your frustration.