[Tex/LaTex] Adjust vertical spacing in tabular containing \href

line-spacingtablestabu

I seem to be stumped by what seems like a basic tabular spacing issue (when an \href is used). The obvious solution of tweaking arraystretch does not seem to work.

What I want is that the output of the tabular to look like the output of itemize, in terms of vertical spacing between the lines. The first column below is the spacing that itemize produces and looks great. The next two columns are what tabular and tabu produce with default settings:

enter image description here

As you can see, the lines in tabular and tabu are too close vertically.

So I thought that increasing the \arraystretch in tabular, or setting \tabulinesep in tabu should work just fine. I wanted to avoid a manual solution of adding specifying the vertical space following a \\. But even that does not work!

enter image description here

The columns above are:

  1. the desired vertical spacing produced by itemize,
  2. tabular with \renewcommand*{\arraystretch}{2.4},
  3. tabu with \tabulinesep=0.5ex, and
  4. manually added \\[1.25ex] at the end of the line:

Basically, I do not want the \href box to stretch, but do want the lines further apart.

Notes:

  • In only put these in minipages to make it easier to compare. In my really application they are below each other. Plus this makes one nice wide image. So, am not trying to get the baseline's aligned here.
  • Now that I put this the two figures above it appears that the overlap does not change. That seems to be a clue, but not sure how I can use that info.

Code:

\documentclass{article} 
\usepackage{enumitem}
\usepackage{tabu}

\usepackage{hyperref}

\newcommand*{\AddLinkToFile}[1]{\href{run:#1.pdf}{\strut#1}}


\begin{document}
\begin{minipage}{2.0cm}
\begin{itemize}
    \item \AddLinkToFile{a} b 
    \item \AddLinkToFile{c} d
\end{itemize}
\end{minipage}
%
\begin{minipage}{2.0cm}
%\renewcommand*{\arraystretch}{2.4}
\begin{tabular}{ll}
    \AddLinkToFile{e} & f \\
    \AddLinkToFile{g} & h \\
\end{tabular}
\end{minipage}
%
\begin{minipage}{2.0cm}
%\tabulinesep=0.5ex
\begin{tabu}{ll}
    \AddLinkToFile{i} & j \\
    \AddLinkToFile{k} & l \\
\end{tabu}
\end{minipage}
%
\begin{minipage}{2.0cm}%            Manually adding space
\begin{tabular}{ll}
    \AddLinkToFile{l} & m \\[1.25ex]
    \AddLinkToFile{n} & o \\
\end{tabular}
\end{minipage}
\end{document}

Best Answer

Maybe this'll help you:

  • For the correct vertical spacing I will use listliketab
  • Amsmath's \smash is surprisingly helpful.

Introducing to \smash

If I'd use

\newcommand*{\AddLinkToFile}[1]{\smash{\href{run:#1.pdf}{\strut#1}}}

The href-box becomes now a very small box (1pt height, 1pt depth?). This is also true for not-tabularized material.
\smash{}

There are three optional argument to \smash

After playing around with [b] and [t] to see its effect I tried

\newcommand*{\AddLinkToFile}[1]{\smash[]{\href{run:#1.pdf}{\strut#1}}}

which does wonders:
\smash[]{…}

(The height and depth of the resulting box comes from \strut.)
Bug or feature? I don't know …

But every use of \strut ([t], [b], [] or no optional at all) breaks the \AddLinkToFile in a real itemize environment unless you add a \leavevmode in front of it.

So the final \AddLinkToFile command would be:

\newcommand*{\AddLinkToFile}[1]{\leavevmode\smash[]{\href{run:#1.pdf}{\strut#1}}}

Code

\documentclass{article} 
\usepackage{amsmath}
\usepackage{enumitem}
\usepackage{tabu}
\usepackage{listliketab}
\usepackage{hyperref}

\newcommand*{\AddLinkToFile}[1]{\leavevmode\smash[]{\href{run:#1.pdf}{\strut#1}}}
%\renewcommand*{\AddLinkToFile}[1]{#1} % for my own testing purposes
\storestyleof{itemize}

\begin{document}

\begin{itemize}
    \item \AddLinkToFile{a} b 
    \item \AddLinkToFile{c} d
\end{itemize}

\AddLinkToFile{A}

\begin{minipage}{2.0cm}
\begin{listliketab}
  \begin{tabular}{Ll}
    \textbullet & \AddLinkToFile{a} A \\
    \textbullet & \AddLinkToFile{c} d
  \end{tabular}
\end{listliketab}
\end{minipage}
%
\begin{minipage}{2.0cm}
\begin{listliketab}
\renewcommand*{\arraystretch}{2.4}
\begin{tabular}{ll}
    \AddLinkToFile{e} & f \\
    \AddLinkToFile{g} & h
\end{tabular}
\end{listliketab}
\end{minipage}
%
\begin{minipage}{2.0cm}
\begin{listliketab}
\tabulinesep=0.5ex
\begin{tabu}{ll}
    \AddLinkToFile{i} & j \\
    \AddLinkToFile{k} & l
\end{tabu}
\end{listliketab}
\end{minipage}
%
\begin{minipage}{2.0cm}
\begin{listliketab}
\begin{tabular}{ll}
    \AddLinkToFile{l} & m \\[1.25ex]
    \AddLinkToFile{n} & o
\end{tabular}
\end{listliketab}
\end{minipage}
\end{document}
Related Question