难以正确识别影响列表内垂直位置的所有参数

难以正确识别影响列表内垂直位置的所有参数

我正在尝试将列表环境第一行的基线与框的基线对齐。之后以各种形式开展这项工作我以为我已经准备好解决这个问题了。我还以为我取得了很大的进展。但在各种情况下测试我的方法后,我发现我仍然缺少一些东西。

我有点不好意思再问一个关于长度和垂直对齐的问题。但在过去 24 小时里处理这个问题之后,我觉得我不知道下一步该做什么了。

我的 MWE 由三部分组成:

  1. 一个文件,newlist.tex它定义了一个新的环境,以便于将列表环境与框的基线对齐,
  2. 一个文件showandtell.tex,其中包含几个宏,旨在帮助显示所涉及的高度和值,
  3. 并将文件包裹在 MWE 周围。

文件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

文件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

包装文件:

\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}

这些产品:

在此处输入图片描述

从图中可以看出,一切似乎都运行良好,直到我将我的新环境埋入另外两个列表中。

我不明白为什么我没有考虑到所有的空间。我还发现很难找到有关如何在每个列表级别设置各种参数的文档。我在 中找不到任何有用的东西source2.pdf

相关内容