如何消除自定义环境中第一个列表项前的垂直空间

如何消除自定义环境中第一个列表项前的垂直空间

我在自定义列表环境中使用 \rule 来下推文本,但这样做似乎会在前后添加垂直空间。您可以判断出存在垂直空间,因为第一项与列分隔符不对齐。我该如何消除前面的空间?

\documentclass[10pt]{article}
\usepackage[inner=1.1in,outer=.7in,top=.9in,bottom=1in,paperwidth=8.5in,paperheight=11in,twoside]{geometry}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{multicol}
\usepackage{enumitem}
\usepackage{tikz}

\setlength{\columnsep}{1cm}
\setlength{\columnseprule}{0.3pt}

\newlist{qenum}{enumerate}{2}
\setlist[qenum,1]{
  leftmargin=12pt,
  labelsep=10pt,
  label={\protect\begin{tikzpicture}[]
    \protect\node[overlay,text width={\linewidth + 8mm},fill=lightgray,anchor=west,inner sep=0pt,minimum height=1.1em] (bg) {};
    \protect\node[overlay,anchor=west,minimum height=1.1em,inner sep=0pt,fill=black,align=center,text width=1.9em,text=white] at (bg.west) {\arabic*};
    \protect\node {\rule[3em]{0pt}{15pt}}; % this is part of the issue
    \protect\end{tikzpicture}}
  }
\setlist[qenum,2]{label=\Alph*),topsep=0pt,leftmargin=22pt,labelsep=7pt,itemsep=-2pt}

\begin{document}

\begin{multicols*}{2}
\raggedcolumns\raggedright
\begin{qenum}

\item For ${i = \sqrt{-1}}$, which of the following is equivalent to $(5 - 3i) - (-2 + 5i)$? % C
\begin{qenum}
\item 
\item 
\item 
\item 
\end{qenum}

\item Which of the following is equal to ${(5 + 2i)(5 - 2i)}$? (Note: $i = \sqrt{-1}$) % B
\begin{qenum}
\item 
\item 
\item 
\item 
\end{qenum}
\end{qenum}
\end{multicols*}

\end{document}

在此处输入图片描述

答案1

该规则不起作用,因为它占用的空间比您想要的多。如果您不想使用 David 的解决方案,您可以使用 baseline-key 更改 tikzpicture 的基线:

\documentclass[10pt]{article}
\usepackage[inner=1.1in,outer=.7in,top=.9in,bottom=1in,paperwidth=8.5in,paperheight=11in,twoside]{geometry}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{multicol}
\usepackage{enumitem}
\usepackage{tikz}

\setlength{\columnsep}{1cm}
\setlength{\columnseprule}{0.3pt}

\newlist{qenum}{enumerate}{2}
\setlist[qenum,1]{
  leftmargin=12pt,
  labelsep=0pt,
  align=left,
  label={\protect\begin{tikzpicture}[baseline=-2em]
    \protect\node[minimum height=1.1em]{};% force minimum height
    \protect\node[overlay,text width={\linewidth + 8mm},fill=lightgray,anchor=west,inner sep=0pt,minimum height=1.1em] (bg) {};
    \protect\node[overlay,anchor=west,minimum height=1.1em,inner sep=0pt,fill=black,align=center,text width=1.9em,text=white] at (bg.west) {\arabic*};
    \protect\end{tikzpicture}}
  }
\setlist[qenum,2]{label=\Alph*),topsep=0pt,leftmargin=22pt,labelsep=7pt,itemsep=-2pt}

\begin{document}

\begin{multicols*}{2}
\raggedcolumns\raggedright
\begin{qenum}

\item For ${i = \sqrt{-1}}$, which of the following is equivalent to $(5 - 3i) - (-2 + 5i)$? % C
\begin{qenum}
\item
\item
\item
\item
\end{qenum}

\item Which of the following is equal to ${(5 + 2i)(5 - 2i)}$? (Note: $i = \sqrt{-1}$) % B
\begin{qenum}
\item
\item
\item
\item
\end{qenum}
\end{qenum}
\end{multicols*}

\end{document}

答案2

不要使灰色框没有空间,而要让它具有自然大小,然后列表会自动调整:

在此处输入图片描述

\documentclass[10pt]{article}
\usepackage[inner=1.1in,outer=.7in,top=.9in,bottom=1in,paperwidth=8.5in,paperheight=11in,twoside]{geometry}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{multicol}
\usepackage{enumitem}
\usepackage{tikz}

\setlength{\columnsep}{1cm}
\setlength{\columnseprule}{0.3pt}

\newlist{qenum}{enumerate}{2}
\setlist[qenum,1]{
  leftmargin=12pt,
  labelsep=10pt,
  itemsep=15pt,
 align=left,
  label={\protect\begin{tikzpicture}[]
    \protect\node[text width={\linewidth + 8mm},fill=lightgray,anchor=west,inner sep=0pt,minimum height=1.1em] (bg) {};
    \protect\node[anchor=west,minimum height=1.1em,inner sep=0pt,fill=black,align=center,text width=1.9em,text=white] at (bg.west) {\arabic*};
 %   \protect\node {\rule[20pt]{1pt}{5pt}}; % this is part of the issue
    \protect\end{tikzpicture}}
  }
\setlist[qenum,2]{label=\Alph*),topsep=0pt,leftmargin=22pt,labelsep=7pt,itemsep=-2pt}

\begin{document}

\begin{multicols*}{2}
\raggedcolumns\raggedright
\begin{qenum}

\item For ${i = \sqrt{-1}}$, which of the following is equivalent to $(5 - 3i) - (-2 + 5i)$? % C
\begin{qenum}
\item 
\item 
\item 
\item 
\end{qenum}

\item Which of the following is equal to ${(5 + 2i)(5 - 2i)}$? (Note: $i = \sqrt{-1}$) % B
\begin{qenum}
\item 
\item 
\item 
\item 
\end{qenum}
\end{qenum}
\end{multicols*}

\end{document}

相关内容