# Make a list with uniform spacing regardless of the characters and number of text lines, possibly with minipages or a table

I am trying to make a list with two columns, where I can used different font sizes and have single- or multi-row columns, while adhering to the page margins and aligning the text properly regardless of what letters are used and how many rows are in each cell. It looked straight-forward to me at first, but then I realized that I was not able to get all of it working at once.

## The following need to work:

• Top alignment when different font sizes are used in adjacent cells

• The page should fill the margins (as specified by the class, or, as in the example below, explicitly. This implies that small margins around the text in the minipages should not be added, or that it should be compensated for.

• The spacing around the minipages should not be different if only one line of text is present compared to when several lines are present.

• The spacing should not be different for the minipages at the top compared to all other minipages (this was the case before I added the outer minipage, in which both of the inner minipages are placed in the example below).

• It should be possible to right-align part of the text in the minipage (as is done with \hfill in the example below).

• All spacing at the top should be for the tallest character of the font used, regardless of the actual characters used. For example: If one minipage contains only the letter 'A', and the minipage next to it only the letter 'a', the 'a' of the second minipage should stay at the same height as it would have, if the page would have contained for example 'al' (the height of a tall letter should always define the top of a line, even if no tall letter was used). Thus, the top of the 'a' should be slightly below the top of the 'A'.

• All spacing at the bottom should be for the deepest character of the font used, regardless of the actual characters used. For example: If one minipage contains only the letter 'A', the minipage below it should be rendered at the same position as it would have, if the minipage above would also have contained a downwards-protruding letter, for example 'Ag'.

It may be that this is easier to achieve by using a table, but my attempts at getting the alignment correct regardless of whether only short or also tall letters are used and whether only non-downwards-protruding or also downwards-protruding letters are used has been unsuccessful. Please have a look at this previous question of mine (although I have accepted an answer, the alignment later turned out to not handle all of the described situations correctly): Top-aligned table cells with different font sizes and controlled spacing. It is not important to me how this is achieved (minipages, parboxes, tabular, tabu, tabularx, longtable, ...) -- any solution that can get the alignment right is welcome.

Ideally, I would also prefer to get rid of all extra space of the minipage, so that I can get the margins to be exactly what they are specified as (the minipages seem to have some extra space added to them, and I have been unable to remove all of it). That is why I cannot simply put two minipages of width 0.5\textwidth, but have to use -15.73111p to compensate for the extra space when I define the second (right-hand side) minipage of each pair (I arrived at that value from compiling and then looking at the warning for the bad box, which specified the amount of oversize).

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

\newcommand{\entry}[8]{ % #1 Heading/time #2 #3 alignment #4 #5 width #6 horisontal separation #7 vertical separation #8 description
\noindent\hangindent=0em\hangafter=0 % Indentation
\begin{minipage}[#3]{\dimexpr(#4+#5)} %
\begin{minipage}[#2]{\dimexpr(#4)} %
\vspace{0pt} %
#1 %
\par\vspace{0pt} %
\end{minipage} %
\hspace{#6} %
\begin{minipage}[#3]{\dimexpr#5-15.73111pt} %
\vspace{0pt} %
#8 %
\par\vspace{0pt} %
\end{minipage} %
\par\vspace{0pt} %
\end{minipage} %
\vspace{#7} %
} %

\newlength{\lwidth}
\newlength{\rwidth}
\newlength{\hsep}
\newlength{\vsep}
\newlength{\spacebox}
\settowidth{\spacebox}{88}
\newlength{\topm}
\newlength{\footm}
\newlength{\rightm}
\newlength{\leftm}

\setlength{\parskip}{0cm}
\setlength{\hsep}{1em}
\setlength{\vsep}{2ex}
\setlength{\topm}{20mm}
\setlength{\footm}{\dimexpr(\topm)}
\setlength{\rightm}{\dimexpr(3\topm/2*\paperwidth/\paperheight)}
\setlength{\leftm}{\rightm}
\newgeometry{top=\topm,bottom=\footm,right=\rightm,left=\leftm}
\setlength{\lwidth}{2.8cm}
\setlength{\rwidth}{\dimexpr(\textwidth-\lwidth-\hsep)}

\begin{document}
\entry{\Huge\textbf{{BIG}}}{t}{t}{\lwidth}{\rwidth}{\hsep}{\vsep}{Some text here.\hfill Text flush with the right margin.\\Another row\\Another\\Another}

\entry{Two\\Lines}{t}{t}{\lwidth}{\rwidth}{\hsep}{\vsep}{A longer text here, so that there will be several rows, gives the proper spacing below it. There must also be downwards-protruding letters (like 'p' and 'g').}

\entry{One Line}{t}{t}{\lwidth}{\rwidth}{\hsep}{\vsep}{This one-line entry has unwanted extra space under it.}

\entry{Below One Line}{t}{t}{\lwidth}{\rwidth}{\hsep}{\vsep}{This entry is slightly lower than it should, due to the added extra space below the single line.}

\entry{Not deep}{t}{t}{\lwidth}{\rwidth}{\hsep}{\vsep}{This entry contains no letters that protrude downwards in the second line. Just letters that are above the base line.}

\entry{Below Not deep}{t}{t}{\lwidth}{\rwidth}{\hsep}{\vsep}{This entry ends up to close to the line above, since the line above contains no letters that protrude downwards.}
\end{document}


-

You might need to play with the spacing a bit but I'd start with a much simpler markup, something like

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

\newlength{\lwidth}
\newlength{\rwidth}
\newlength{\hsep}
\newlength{\vsep}
\newlength{\spacebox}
\settowidth{\spacebox}{88}
\newlength{\topm}
\newlength{\footm}
\newlength{\rightm}
\newlength{\leftm}

\setlength{\parskip}{0cm}
\setlength{\hsep}{1em}
\setlength{\vsep}{2ex}
\setlength{\topm}{20mm}
\setlength{\footm}{\dimexpr(\topm)}
\setlength{\rightm}{\dimexpr(3\topm/2*\paperwidth/\paperheight)}
\setlength{\leftm}{\rightm}
\newgeometry{top=\topm,bottom=\footm,right=\rightm,left=\leftm}
\setlength{\lwidth}{2.8cm}
\setlength{\rwidth}{\dimexpr(\textwidth-\lwidth-\hsep)}

\def\entr#1{%
\raisebox{\dimexpr\ht\strutbox-\height\relax}{\begin{tabular}[t]{@{}l@{}}#1\strut\end{tabular}}}
\usepackage{tabularx}
\begin{document}

\noindent\begin{tabularx}{\textwidth}{
@{}
l
>{\let\\\newline}X@{}}
\entr{\Huge\textbf{BIG}}& Some text here.\hfill Text flush with the right margin.\\Another row\\Another\\Another\tabularnewline

\entr{Two\\Lines}&A longer text here, so that there will be several rows, gives the proper spacing below it. There must also be downwards-protruding letters (like 'p' and 'g').\tabularnewline

\entr{One Line}&This one-line entry has unwanted extra space under it.\tabularnewline

\entr{Below One Line}&This entry is slightly lower than it should, due to the added extra space below the single line.\tabularnewline

\entr{Not deep}&This entry contains no letters that protrude downwards in the second line. Just letters that are above the base line.\tabularnewline

\entr{Below Not deep}&This entry ends up to close to the line above, since the line above contains no letters that protrude downwards.
\end{tabularx}
\end{document}

-
Simple is always preferable, and I think that your approach is better than my minipages. Looking at the result, everything seems to work, with the minor quirk that the top of BIG is not perfectly aligned with the top of the text in the right-hand column. Even applying the \entr command to the right-hand column did not help (and also prevented \hfill from working). It is especially noticeable if the font of the first line of the right-hand column is made bigger. Although your example is definitely better than what I had, is there a way to improve the top alignment? –  hjb981 Mar 25 '13 at 15:46
@hjb981 I added a \strut which basically covers the height of a paren and will be a bit bigger than a B as you said that you didn't want the position to depend on the letters used. You could instead add a \vphantom{Q} if you never want anything bigger than a capital letter or deeper descender than Q... –  David Carlisle Mar 25 '13 at 16:34
Have I understood it correctly that the height of the strutbox \ht\strutbox minus another height \height (what is this) is used as a value for how much to shift the position, and an invisible character \strut (or \vphantom{Q}) is placed next to the text to be typeset, to make sure that the box around the typeset text has the same (minimum) height even if a short letter is used? Using \vphantom{Q} does not align it perfectly, but for the time being I have made a work-around by simply adding 1.5pt to the shift value (for the BIG entry only, the others now have a separate command). –  hjb981 Mar 25 '13 at 17:21
Why is it that if I increase the size of the right-hand column, the left-hand column (the one with the \entr command) does not follow in alignment, and why is it not possible to use \entr in both columns and thus align them? I do not follow exactly what happens when the columns are shifted as suggested in the answer, so please bear with me if I ask about things that might seem obvious. –  hjb981 Mar 25 '13 at 17:25
you could use entr in both columns but I thought you wanted the right column to be justified text but entr is a single column tabular with an l column so has no line breaking. The offset in entry adjusts its height to the height of a strut in the normal font size, if your text in the other column is bigger you'll want a bigger font, easiest would be to have another argument to \entr so you could pass in a font size so that \strut would be re-calculated before the adjustment. –  David Carlisle Mar 25 '13 at 17:32