3

I'm trying to align the baseline of the first line of a list environment with the baseline of a box. After working on this in various forms, I thought I was ready to tackle this issue. I also thought I was making good progress. But testing my approach in various situations has revealed that I'm still missing something.

I'm feeling a bit sheepish about asking yet another question about lengths and vertical alignment. But after working on this over the past 24 hours, I feel I'm out of ideas of what to do next.

My MWE consists of three parts:

  1. A file, newlist.tex, which defines a new environment to facilitate aligning a listing environment with a box's baseline,
  2. A file, showandtell.tex, which contains several macros designed to help show the heights and values involved,
  3. And the file to wrap around the MWE.

The file newlist.tex

\makeatletter
%%  A box to line up against                                                
\newsavebox{\aeQuickBox}
\def\aeQuick{\savebox{\aeQuickBox}{Tq \rule[-2ex]{0.1pt}{3ex}jay}%%'
             \usebox{\aeQuickBox}%%'
             \setlength{\dp\aeQuickBox}{\dp\aeQuickBox}}
%% THE STRUT                                                                
\newlength{\ae@strut@ht}
\setlength{\ae@strut@ht}{0.7\baselineskip}
\newcommand{\aestrut}{\makebox[0pt][r]{\rule{2pt}{\ae@strut@ht}}}
%% MY LIST                                                                  
%% new lengths created for access outside of environment                    
\newlength{\ae@enum@topsep}
\newlength{\ae@enum@partopsep}
\newlength{\ae@enum@parsep}
\newlength{\ae@enum@parskip}
\newenvironment{alignedenum}
  {\begingroup
     \begin{list}
       {\bfseries\textbullet}
       {%% horizontal dimensions                                            
        \setlength{\labelwidth}{1.5em}%%'
        \setlength{\labelsep}{0.5em}%%'
        \setlength{\itemindent}{0em}%%'
        \setlength{\leftmargin}{\dimexpr              
                                  \wd\aeQuickBox + 0.5em
                                  +\labelwidth +\labelsep -\itemindent
                                \relax}%%'
        %% vertical dimensions                                              
        %% test whether `\partopsep` has been added
        \ifvmode
          \global\setlength{\ae@enum@partopsep}{\partopsep}%%'
        \else
          \global\setlength{\ae@enum@partopsep}{0pt}%%'
        \fi
        %% next is true only if this environment is within another list
        \ifnum\@listdepth>1\relax
          \global\setlength{\ae@enum@topsep}{\topsep}%%'
        \else
          \global\setlength{\ae@enum@topsep}{0pt}
        \fi
       \global\setlength{\ae@enum@parsep}{\parsep}%%'
       }%%'
       %% set \ae@enum@parskip here because wrong value of `\parskip` is 
       %% called within arguments to `list` environment.
       \global\setlength{\ae@enum@parskip}{\parskip}%%"
       %% avoid `\lineskip` if being aligned with a very deep box
       \nointerlineskip
       \myremovevspace
  }
  {\end{list}\endgroup}

%% VERTICAL SPACE REMOVAL                                                   
\newcommand{\myremovevspace}
  {%%\par\nointerlineskip 
   \vspace{%%'
     -\dimexpr         
         \ae@strut@ht
        +\ae@enum@topsep
        +\ae@enum@partopsep
        +\ae@enum@parsep
        +\ae@enum@parskip
        +\dp\aeQuickBox
   \relax}}

\makeatother

The file showandtell.tex

\usepackage{xcolor}
\makeatletter
%% cumulative lengths for stacking and making lengths visible               
\newlength{\ae@tmp@dim@a}
\newlength{\ae@tmp@dim@b}
\newlength{\ae@tmp@dim@c}
\newlength{\ae@tmp@dim@d}
%% COLORS                                                                   
%%   orange = strut height                                                  
%%   blue   = topsep                                                        
%%   gray   = parskip + parsep                                              
%%   red    = aeQucikBox depth                                              
\newcommand{\aeStackLengths}
  {\bgroup
   %%'----------------------------------------------------------------------
   \setlength{\ae@tmp@dim@a}{0pt}%%%'
   \setlength{\ae@tmp@dim@b}{\dimexpr\ae@tmp@dim@a+\ae@strut@ht\relax}%%'
   \setlength{\ae@tmp@dim@c}{\dimexpr\ae@tmp@dim@b+\ae@enum@topsep}%%'
   \setlength{\ae@tmp@dim@d}{\dimexpr\ae@tmp@dim@c+\dimexpr\ae@enum@parskip+\ae@enum@parsep+\ae@enum@partopsep}%%'
   %%'----------------------------------------------------------------------
   \color{orange!80}%%'
   \raisebox{\ae@tmp@dim@a}[0pt][0pt]{\makebox[0pt][l]{\rule{3pt}{\ae@strut@ht}}}%%'
   \color{blue!70}%%'
   \raisebox{\ae@tmp@dim@b}[0pt][0pt]{\makebox[0pt][l]{\rule{3pt}{\ae@enum@topsep}}}%%'
   \color{gray!50}%%'
   \raisebox{\ae@tmp@dim@c}[0pt][0pt]{\makebox[0pt][l]{\rule{3pt}{\dimexpr\ae@enum@parskip+\ae@enum@parsep+\ae@enum@partopsep}}}%%'
   \color{red}%%'
   \raisebox{\ae@tmp@dim@d}[0pt][0pt]{\makebox[0pt][l]{\rule{3pt}{\dp\aeQuickBox}}}%%'
   \egroup
  }

%%--------------------------------------------------------------------------
%% VISUALLY REP FOR DIMS                                                    
%%--------------------------------------------------------------------------
%% show baseline                                                            
\newcommand{\aeshowbaseline}{\makebox[0pt][l]{\color{blue}\rule{0.1pt}{1ex}\rule{2in}{0.1pt}}}
%% show depth                                                               
\newcommand{\aeshowdepth}{\makebox[0pt][r]{%%'
  \color{red}%%'
  \rule[-\dp\aeQuickBox]{2.25in}{0.1pt}%%'
  \rule[-\dp\aeQuickBox]{0.1pt}{\dp\aeQuickBox}%%'
  \makebox[0pt][l]{\rule[-\dp\aeQuickBox]{1.5in}{0.1pt}}%%'
  }}

%%--------------------------------------------------------------------------
%% SHOW VALUES FOR DIMS                                                     
%%--------------------------------------------------------------------------
\usepackage{pgffor}
\newcommand\aeshowbox[1]
  {\begin{minipage}[t]{2in}\tiny\ttfamily
      \foreach \x in {#1}{ \makebox[1cm][r]{\x}  =  \the\csname \x\endcsname\\ }
  \end{minipage}}
\def\aeshowLengths{\aeshowbox{topsep,partopsep,parsep,parskip,%%'
                              ae@enum@topsep,ae@enum@partopsep,ae@enum@parsep,ae@enum@parskip}}
\makeatother

The wrapper file:

\documentclass{article}
\input{newlist}
\input{showandtell}
\usepackage{lipsum}
\begin{document}

\noindent
  \aeshowbaseline\aeQuick  \par
  \begin{alignedenum}
    \item \aestrut\aeStackLengths\aeshowbaseline\, My first line: \aeshowLengths
    \item second line
  \end{alignedenum}

\begin{enumerate}
  \item \aeshowbaseline\aeQuick
        \begin{alignedenum}
          \item \aestrut\aeStackLengths\aeshowbaseline\, My first line: \aeshowLengths
          \item second line
        \end{alignedenum}
\end{enumerate}

\begin{enumerate}
  \item  \verb=\par= inserted
         \begin{enumerate}
           \item \aeshowbaseline\aeQuick \par
                 \begin{alignedenum}
                   \item \aestrut\aeStackLengths\aeshowbaseline\, My first line: \aeshowLengths
                   \item second line
                 \end{alignedenum}
         \end{enumerate}
\end{enumerate}

\begin{enumerate}
  \item No \verb=\par= inserted
         \begin{enumerate}
           \item \aeshowbaseline\aeQuick 
                 \begin{alignedenum}
                   \item \aestrut\aeStackLengths\aeshowbaseline\, My first line: \aeshowLengths
                   \item second line
                 \end{alignedenum}
         \end{enumerate}
\end{enumerate}

\end{document}

These produce:

enter image description here

As seen from the image, everything seems to be working fine until I've buried my new environment within two other lists.

I don't understand how I've not taken into account all the space. I'm also finding it difficult to locate the documentation for how the various parameters are set at each list level. I can't find much of anything useful in source2.pdf.

0

You must log in to answer this question.

Browse other questions tagged .