# Tabular alignment of text and figure

For an exam paper I'm preparing, I want to properly build a top page header, with the university logo, and two block of text side-by-side (for course, department, etc.). I have already seen some possible solutions:

How to vertically-center the text of the cells?

How to vertically center text with an image in the same row of a table

but none provided me with a proper solution for my case. I want to be able to vertically align the two texts independently with t,c,b and also align the picture with the first text. The problem is in this latter alignment, because it should be flexible enough so that the figure and the first text can be aligned at t, c,b.

To be clear, possible outputs include:

• the picture and the first text center aligned, and the last text top aligned with the first text; or
• all aligned at top, bottom, center; or even
• the picture and the first text top aligned, and the last text bottom aligned with the first text.

\documentclass[10pt]{scrartcl}

\usepackage{lmodern}
\usepackage[a4paper,showframe]{geometry}
\usepackage{graphicx}
\DeclareGraphicsExtensions{.pdf}

\usepackage{array}

\usepackage{varwidth}
\usepackage{ragged2e}

\setlength{\fboxsep}{0pt}

\newcommand*{\mtab}[1]{\begin{tabular}[t]{@{}l@{}} #1 \end{tabular}}
\newcommand*{\lbox}[2][t]{\parbox[#1]{\linewidth}{\RaggedRight\fbox{\mtab{#2}}}}
\newcommand*{\rbox}[2][t]{\parbox[#1]{\linewidth}{\RaggedLeft\fbox{\mtab{#2}}}}
\newcommand*{\cbox}[2][t]{\parbox[#1]{\linewidth}{\Centering\fbox{\mtab{#2}}}}

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

\begin{document}

\begingroup
\noindent
\begin{tabular}{@{}p{0.15\textwidth}p{0.5\textwidth}p{\dimexpr 0.35\textwidth-4\tabcolsep\relax}@{}}
\lbox{\raisebox{-0.5\height}{\Logo}} & \cbox[t]{aaa\\ bbb\\ ccc\\ ddd} & \rbox[t]{fff\\ hhh}
\end{tabular}
\endgroup
\par\bigskip
\begingroup
\noindent
\begin{tabular}{@{}p{0.6\textwidth}@{}p{0.2\textwidth}@{}p{0.2\textwidth}@{}}
Name: & Num: & Class:
\end{tabular}
\endgroup
\par\bigskip

Normal text here!

\end{document}


## 1 Answer

I don't really understand your definitions. The parbox-definition are not needed

However to use \raisebox you have to take into account the height of \strutbox to justify the image.

\documentclass[10pt]{scrartcl}

\usepackage{lmodern}
\usepackage[a4paper,showframe]{geometry}
\usepackage{graphicx}
%\DeclareGraphicsExtensions{.pdf}

\usepackage{array}

\usepackage{varwidth}
\usepackage{ragged2e}

\setlength{\fboxsep}{0pt}

\newcommand*{\mtab}[1]{\begin{tabular}[t]{@{}l@{}} #1 \end{tabular}}
\newcommand*{\lbox}[2][t]{\parbox[#1]{\linewidth}{\RaggedRight\fbox{\mtab{#2}}}}
\newcommand*{\rbox}[2][t]{\parbox[#1]{\linewidth}{\RaggedLeft\fbox{\mtab{#2}}}}
\newcommand*{\cbox}[2][t]{\parbox[#1]{\linewidth}{\Centering\fbox{\mtab{#2}}}}

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

\begin{document}

\begingroup
\noindent
\begin{tabular}{@{}>{\RaggedRight}p{0.15\textwidth}>{\Centering}p{0.5\textwidth}>{\RaggedLeft}p{\dimexpr 0.35\textwidth-4\tabcolsep\relax}@{}}
\raisebox{\dimexpr-\height+\ht\strutbox+\fboxrule}{\Logo} &\fbox{\mtab{aaa\\ bbb\\ ccc\\ ddd}} & \fbox{\mtab{fff\\ hhh}}
\end{tabular}
\endgroup
\par\bigskip
\begingroup
\noindent
\begin{tabular}{@{}p{0.6\textwidth}@{}p{0.2\textwidth}@{}p{0.2\textwidth}@{}}
Name: & Num: & Class:
\end{tabular}
\endgroup
\par\bigskip

Normal text here!

\end{document}


• What you mean by "I don't understand your definitions?" I know about \strutbox, and it does work for the top and vertical centering alignment. However I couldn't put it to work in bottom alignment. In the code below I reused your code, I removed the RaggedLeft and RaggedRight because they were giving badness. But the problem width the bottom alignment remains. May 26 '13 at 14:20
• @cacamailg: The columntype p is a parbox. And you put a parbox in a parbox and inside the second parbox you put material in a fbox which is an hbox. May 26 '13 at 14:25
• You are right :). See below an update. May 26 '13 at 14:27
• @cacamailg: You should update your question and on the other hand please show us what do you want to achieve. May 26 '13 at 14:28
• I added an answer below. Is it better to copy it and put as question? May 26 '13 at 14:31