7

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}
7
  • The default vertical space between consecutive items is controlled by \itemsep+\parsep, so the following should work: \begin{tabular}{ll} \AddLinkToFile{e} & f \\[\dimexpr\itemsep+\parsep\relax] \AddLinkToFile{g} & h \\end{tabular} Commented Oct 8, 2012 at 2:55
  • Yes, but that stretches out the \href box. Also would like to figure out how to automate it, as I have many tables in my document following an itemize. Commented Oct 8, 2012 at 2:59
  • @cmhughes and Gonzalo: I found a manual solution by an accident during copy and past error (forgot to remove the \\ before pasting another one. The following works: \\ \\[-4pt]. The first \\ makes sure the \href box is the correct size, and the second \\[-4pt] controls the spacing. So, how do I automate this? Commented Oct 8, 2012 at 3:03
  • The 4pt is from \itemsep, so \\ \[-\itemsep] should also work. Arghhh! How do you write \\ using code tags in comments? Commented Oct 8, 2012 at 3:06
  • Ok that explains the 4pt. The only way I found to show a \\ is to leave a trailing space before the closing back tick. So, now just need to figure out how to automate it. Commented Oct 8, 2012 at 3:13

1 Answer 1

4

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}
1
  • Well that seems to fix the tabular issue, but creates an issue for itemize? Commented Oct 8, 2012 at 4:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .