Based on the answer to this other question, here is a solution that preserves even distance between baselines.
\makeatletter
\let\tightset@fontsize\set@fontsize
\patchcmd\tightset@fontsize{#3}{#2}{}{}
\newcommand{\tighten}{\let\set@fontsize\tightset@fontsize
\fontsize{\f@size}{\f@baselineskip}\selectfont}
\makeatother
Then the list can be input as
\begin{enumerate}[parsep=0pt]
\item List 1
\begin{enumerate}[label=\Alph*.,before*=\tighten,noitemsep,topsep=0pt]
\item Item Aabcg
\item Item Bagcb
\item Item Cabcg
\item Item Dagcb
\end{enumerate}
\end{enumerate}
Minimal example:
\documentclass[a4paper]{article}
\usepackage{etoolbox,enumitem}
\makeatletter
\let\tightset@fontsize\set@fontsize
\patchcmd\tightset@fontsize{#3}{#2}{}{}
\newcommand{\tighten}{\let\set@fontsize\tightset@fontsize
\fontsize{\f@size}{\f@baselineskip}\selectfont}
\makeatother
\begin{document}
\begin{enumerate}[parsep=0pt]
\item List 1
\begin{enumerate}[label=\Alph*.,before*=\tighten,nolistsep,topsep=0pt]
\item Item A
\item Item B
\item Item C
\item Item D
\end{enumerate}
\end{enumerate}
\end{document}
Checking the output with \showbox
proves that the spacing is the same: between the "List 1" line and the "Item A" line, TeX inserts 3.16669pt glue, exactly the same as the glue inserted between the "Item A" and the "Item B" lines (and the others as well), which is right, since those lines have no descenders. The height of the "Item A" line is 6.83331pt, which added to 3.16669pt gives 10pt.
There might be a slight difference in a real document if \topsep
in the inner list is not set to zero (the nolistsep
key sets it to 0pt plus 0.1pt
), but not with the article class which does \raggedbottom
.
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.
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:
(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}
Best Answer
While
\offinterlineskip\lineskip1pt
might seem to give the desired result, lines will be irregularly spaced, because the distance between base lines will depend on the presence of ascenders (letters like "d") or descenders (letters like "y"). Moreover not all descenders and ascenders are equal.Tight typesetting can be obtained by calling, say,
\fontsize{10}{10}
for ten point size. One can get cheaply such a setting by modifying the internal function\set@fontsize
:Only etoolbox is required, of course. The patch will substitute the call of the third argument to
\set@fontsize
with the second; the third parameter is indeed the baselineskip and the second is the font size.Note that this will affect all text at all sizes.
If only some paragraphs are to be "tightly typeset", then the environment
tight
defined as follows will do the job. The\addvspace
commands have been used on the assumption that the code is used for examples. Variations on the theme are possible.If tight typesetting is needed for captions, it's simpler. With the caption package define the font used by saying something like