[Tex/LaTex] Top-aligned table cells with different font sizes and controlled spacing

horizontal alignmentmarginsspacingtablesvertical alignment

I am trying to achieve a table where a few things have to work simultaneously. Several of these things have been discussed before, but I have been unable to make everything work at once (and some things at all).

I want to be able to use different font sizes in cells on the same row, and have them precisely aligned at the top. That has almost been achieved in the MWE below, but the letters of the smaller font are slightly below the letters of the larger font. (Previous discussion: Make different font sizes in a table align at top, not bottom, but the alignment is only close, not perfect.) Edit: The top alignment should be for the maximum height of the font used, so that an 'a' ends up at the same height whether it is written by itself or followed by a tall letter, such as an 'l' (or, if the small 'b' next to the big 'B' in the example below is changed for a small 'a', the 'a' should not jump up to the ceiling.

I also want to be able to insert several rows of text with forced line breaks within a cell of the table, and those rows need to have the same spacing between them as normal text has. That has been achieved by nesting another table in a cell in the MWE below.

In addition, I want to be able to use \hfill to put something out in the right margin from within the nested table, which works in the MWE.

Further, the margins on the top, bottom and sides of the table should be zero, so that only the page margins determine the amount of white space around the table (as it is now, there is even a difference between the right and left margins — although the margins were for some reason adjusted when I uploaded the pdf below, it is visible if you compile the code and look at the pdf directly).

Lastly, I would like to get rid of all automatic spacing between cells, and then define my own spacing. Preferably, I would like to be able to define the vertical spacing between cells in terms of line heights (for lines of the size that I specify for normal text, so 11pt in the example below), while the units of horizontal spacing would preferably be defined in terms of "the width of an 'm'", or something like that.

\documentclass[paper=a4,fontsize=11pt]{scrartcl} % KOMA-article class
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel} % English language/hyphenation
\usepackage{geometry}
\usepackage{tabu}
\usepackage{lipsum}

\pagestyle{empty} % No pagenumbers/headers/footers

\newcolumntype{V}{>{\vspace{0pt}}p}

\begin{document}
\begin{tabular} [t]{@{}V{0.2\columnwidth}V{0.8\columnwidth}} % @{} is used to remove the margins from cells
\Huge\textbf A & \begin{tabular}[t]{@{}p{0.8\columnwidth}}
Lorem ipsum \hfill right-aligned\\
sem.\\
Lorem\\
ipsum
\end{tabular} \\ 
\Huge\textbf B & b \\ 
\Huge\textbf C & \lipsum*[1] \\ 
\end{tabular}
\end{document}

enter image description here

Edit 2013-03-25: I tried a different approach (with minipages) and asked a question: Make a list with uniform spacing regardless of the characters and number of text lines, possibly with minipages or a table. As of writing this, I have one answer that is similar to the accepted answer below. It achieves correct spacing, but is limited to different sizes in the left column (if one wants to use \hfill in the right column), and the top alignment for the \Huge text is not perfect.

Edit 2013-03-25: I got an answer in the thread Make a list with uniform spacing regardless of the characters and number of text lines, possibly with minipages or a table where \strut was used to add space, and \vphantom{Qp} (adds the vertical space of what is written in the braces(Qp in this example)). That could most likely be used here to, to get the correct spacing between cells even if only short letters or letters that do not protrude downwards are used.

Best Answer

A cell always start with a strut, precisely \@arstrut, which is meant to help in alignment. The \Huge letters in the first column are higher than this strut, so they are set touching the upper margin. This doesn't happen for the second column cells. A trick can be to provide a fake first line and then backing up by its height, which we know precisely to be the height of the strut. Then we insert no interline glue.

However this won't work with a nested tabular.

\documentclass[paper=a4,fontsize=11pt]{scrartcl} % KOMA-article class

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel} % English language/hyphenation
\usepackage[showframe]{geometry}
\usepackage{array,tabularx}
\usepackage{lipsum}

\pagestyle{empty} % No pagenumbers/headers/footers

\makeatletter
\newcolumntype{A}[1]{>{\kern-\ht\@arstrutbox\hrule height 0pt}p{#1}}
\newcolumntype{V}{%
  >{\csname par\endcsname\kern-\ht\@arstrutbox\nointerlineskip\hrule height0pt
  \mbox{}\csname par\endcsname\kern-\ht\@arstrutbox\nointerlineskip
  \vrule height\fontcharht\font`A width0pt\relax}X}
\makeatother

\begin{document}
\noindent\begin{tabularx}{\textwidth}{
  @{}
  A{3em}
  V
  @{}} % @{} is used to remove the margins from cells
\Huge\bfseries A
& 
Lorem ipsum \hfill right-aligned\newline
sem.\newline
Lorem\newline
ipsum \\ 
\Huge\bfseries B & a \\ 
\Huge\bfseries C & \lipsum*[1] \\ 
\end{tabularx}
\end{document}

enter image description here

As far as the interrow spacing is concerned, I'm afraid that it's outside the tabular model of LaTeX.

Here's a different implementation, where the big letters are shifted down:

\documentclass[paper=a4,fontsize=11pt]{scrartcl} % KOMA-article class

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel} % English language/hyphenation
\usepackage[showframe]{geometry}
\usepackage{array,tabularx,adjustbox}
\usepackage{lipsum}

\pagestyle{empty} % No pagenumbers/headers/footers

\newcommand{\bigletter}[1]{%
  \raisebox{\dimexpr-\height+\fontcharht\font`A\relax}{\Huge\bfseries #1}%
}

\makeatletter
\makeatother

\begin{document}
\noindent\begin{tabularx}{\textwidth}{
  @{}
  p{3em}
  X
  @{}} % @{} is used to remove the margins from cells
\bigletter{A}
& 
Lorem ipsum \hfill right-aligned\newline
sem.\newline
Lorem\newline
ipsum \\ 
\bigletter{B} & a \\ 
\bigletter{C} & \lipsum*[1] \\ 
\end{tabularx}
\end{document}
Related Question