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}