# How to align vertical lines of two back-to-back longtables?

The result of the following MWE

\documentclass[letter,10pt]{article}

\usepackage{makecell}
\renewcommand{\cellalign}{tl}
\usepackage{longtable}
\usepackage{fontspec}
\usepackage
[
left=1.5cm,
right=1.5cm,
top=1.5cm,
bottom=1.5cm,
]
{geometry}

\ExplSyntaxOn
\let\tl_length:n\tl_count:n
\ExplSyntaxOff
\setmainfont[Color=000000]{Arial}

\setlength{\LTpre}{7pt}
\setlength{\LTpost}{0pt}

\begin{document}
\begin{longtable}[l]{r|p{16cm}}
Mr. Professor & Introduction to Academic Hallucinations, 1890\\
\end{longtable}
\begin{longtable}[l]{r|p{16cm}}
\makecell{Mrs.\\ Professor} & \textit{Advanced Time Wasting''}, 1891\\
& \textit{Special Topics in Time Wasting''}, 1892\\
\end{longtable}
\end{document}


is

How can I align the vertical lines of the longtables (as the red arrow indicates)?

PS. (However, I do know that each post should have included just one question but as a follow-up one) How can I get rid of the empty second line of the lower longtable (just like what the blue arrow illustrates)?

Simple: for the alignment of vertical rules, make these two tables a single one, adding a \vskip between the two rows. For the second problem, use also a \makecell for the second column.

\documentclass[letter,10pt]{article}

\usepackage{makecell}
\renewcommand{\cellalign}{tl}
\usepackage{longtable}
\usepackage{fontspec}
\usepackage [margin=1.5cm] {geometry}

\ExplSyntaxOn
\let\tl_length:n\tl_count:n
\ExplSyntaxOff
\setmainfont[Color=000000]{Arial}

\setlength{\LTpre}{7pt}
\setlength{\LTpost}{0pt}

\begin{document}

\begin{longtable}[l]{r|p{16cm}}
Mr. Professor & Introduction to Academic Hallucinations, 1890\\
\noalign{\vskip2ex}
\makecell{Mrs.\\ Professor} &\makecell{\textit{Advanced Time Wasting''}, 1891\\
\textit{Special Topics in Time Wasting''}, 1892}\\
\end{longtable}

\end{document}


# Width of the first column

The easiest way would be to use a fixed-width column as declared with p{4cm}. However, this requires:

• either guessing a large-enough width, accepting the fact that it is most probably larger than necessary, and hoping it will stay large enough as the document evolves;

• or measuring all boxes and choosing the largest width, which is quite a pain to do manually without introducing redundancy.

But thanks to the eqparbox package, we can automatically find the minimal width that is large enough to hold the two boxes of interest, and keep an l, r or c specifier for the first column, with appropriately-prepared boxes inside.

In order to do this, you first need to choose a tag name—I creatively chose the name name in the example below. Then, as the eqparbox manual says:

All boxes produced using the same tag are typeset in a box wide enough to hold the widest of them.

Note that this process requires two compilation runs: the first one allows eqparbox to measure the material; in subsequent runs, LaTeX can typeset the material using the desired width for each managed box.

In this case, we have two boxes created with the tag name:

• a \makebox created with \eqmakebox[name]{Mr. Professor};

• a \parbox created with \eqparbox{name}{Mrs.\\ Professor}.

The eqparbox package, on the second and subsequent compilation runs, ensures that these two boxes have the same width (and a minimal one) since they share the same tag. Of course, if you have different “collections” of boxes to treat this way, you may use several tags (one per collection of same-width boxes).

\documentclass{article}
\usepackage[letterpaper, left=1.5cm, right=1.5cm, top=1.5cm,
bottom=1.5cm]{geometry}
\usepackage{eqparbox}
\usepackage{longtable}

\setlength{\LTpre}{7pt}
\setlength{\LTpost}{0pt}

\begin{document}

\begin{longtable}[l]{r|p{12cm}}
\eqmakebox[name]{Mr. Professor} & Introduction to Academic Hallucinations, 1890
\end{longtable}
%
\begin{longtable}[l]{r|p{12cm}}
\eqparbox{name}{Mrs.\\ Professor} & \textit{Advanced Time Wasting''}, 1891\\
& \textit{Special Topics in Time Wasting''}, 1892
\end{longtable}

\end{document}


# Unwanted vertical gap in your second column

Concerning what you showed with the blue arrow, this is due to the fact that \\ ends a line of the longtable, therefore \textit{Special Topics in Time Wasting''}, 1892 in the second table is on its own on the second line. If you want it closer to the \textit{Advanced Time Wasting''}, 1891, you can use \newline instead of \\, to start a new (text) line inside the same table cell in the column of type p:

\begin{longtable}[l]{r|p{12cm}}
\eqparbox{name}{Mrs.\\ Professor} &
\textit{Advanced Time Wasting''}, 1891\newline
\textit{Special Topics in Time Wasting''}, 1892
\end{longtable}


Yet another way would be to save the meaning \\ has outside the longtable environments by writing \let\nlORI\\ before one of the \begin{longtable} lines (or even in the document preamble) and use \nlORI instead of \newline.

# Fine tuning

You may still dislike the vertical alignment between the cells in column 1 and column 2 with the last piece of code from the previous section. This is due to the fact that \eqparbox, like \parbox, places the reference point of the created box on a horizontal line that splits the box in two halfs of same height by default; this reference point is then aligned with the baseline of the first line of the paragraph typeset in the p column. In order to vertically align the top line of the \eqparbox with the top line of the only cell in the column of type p, you can add a [t] specifier to the \eqparbox. Then, its reference point will lie on the baseline of its first line, providing a nicer alignment:

\begin{longtable}[l]{r|p{12cm}}
\eqparbox[t]{name}{Mrs.\\ Professor} &
\textit{Advanced Time Wasting''}, 1891\newline
\textit{Special Topics in Time Wasting''}, 1892
\end{longtable}


# Remarks on the question

• There was completely unused expl3 code in your example (\ExplSyntaxOn\let\tl_length:n\tl_count:n\ExplSyntaxOff);

• letter is not a recognized option of \documentclass, as opposed to a4paper (I passed letterpaper to geometry in order to achieve the desired effect);

• It is not useful to pass options that are irrelevant to your problem when preparing a minimal working example for a question. For instance, the font-related code here (\usepackage{fontspec}, \setmainfont[...]{Arial} and the 10pt option of \documentclass) have no relation to the problem you are asking about, they only clutter the code and prevent people from testing it with pdfTeX, whereas it can very well work with all engines if you simply remove this code. Therefore, it is better to remove it when asking a question here. You'll know for next time. :-)