迷你頁內部和外部的列表間距不同

迷你頁內部和外部的列表間距不同

我正在準備考試,我想要一個多項選擇題旁邊的插圖。通常出於這個目的,我將問題和/或選擇放在一個multicols環境中;然而,對於這個特定的問題,頁面寬度的五五十分割使multicols每個選項的文字換行,而圖像相當窄。

我以為我可以透過將選項放在 a 中來獲得我想要的東西minipage,但是迷你頁改變了選項之間的間距:

    \documentclass{article} %% 'exam' class not needed for MWE
    \begin{document}
    \begin{enumerate}

    \item
    This is a standard nested enumeration.
    \begin{enumerate}
      \item Spacing within wrapped text and between lines of the enumeration
        looks okay to me.
      \item adsflkj adsflkj 
      \item qeworui qeworui 
      \item zcx,vmn zcx,vmn 
      \item lkjasdf lkjasdf 
      \item mbnnert mbnnert 
    \end{enumerate}

    \item
    The possible answers to this question are in a minipage, 
    to accomodate an image to the right

    \begin{minipage}[t]{0.6\linewidth}
      \begin{enumerate}
        \item Spacing within wrapped text is the same, but the spacing
          between items is different.
        \item adsflkj adsflkj 
        \item qeworui qeworui 
        \item zcx,vmn zcx,vmn 
        \item lkjasdf lkjasdf 
        \item mbnnert mbnnert 
      \end{enumerate}
    \end{minipage}
    \hfill
    \fbox{Tikz image here}

    \end{enumerate}
    \end{document}

輸出

這種差異讓我很惱火。我該如何修復它?

(我可以或多或少地通過\addtolength{\itemsep}{-1ex}在小頁面中進行操作來破解它。但是\the\itemsep在不同的地方顯示表明這\itemsep實際上並不是正在秘密更改的長度。我寧願了解實際發生的情況。)

答案1

Aminipage確實明確重置了清單深度,請參閱latex.ltx這一點,在第 4886 行可以找到以下程式碼:

\let\@listdepth\@mplistdepth \@mplistdepth\z@

重要的是\@mplistdepth\z@,意味著零列表深度——內部enumerate環境的行為就像再次處於第一級別,在本例中使用\itemsep該級別的「適當」值4.0pt plus 2.0pt minus 1.0pt。 (對於 也同樣如此itemize)。然後使用其他間距,就像在枚舉/逐項環境的第一級一樣,這就是縮排等的原因,(a)從OP中的圖像可以看出。

有趣的是,枚舉計數器格式沒有重置,因為\@enumdepth此時仍然具有值 2(即第二級)。

然而, 一個廉價的技巧是手動將\@mplistdepth計數器明確設定為。1

\documentclass{article} %% 'exam' class not needed for MWE

\usepackage{enumitem}


\begin{document}


\begin{enumerate}

 \item  This is a standard nested enumeration.
 \begin{enumerate} 
 \item Spacing within wrapped text and between lines of the enumeration
   looks okay to me. 
   \item adsflkj adsflkj 
   \item qeworui qeworui 
   \item zcx,vmn zcx,vmn 
   \item lkjasdf lkjasdf 
   \item mbnnert mbnnert 
 \end{enumerate}

\item The possible answers to this question are in a minipage, 
to accomodate an image to the right   

 \begin{minipage}[t]{0.6\linewidth}
   % minipage does this thing here:       \let\@listdepth\@mplistdepth \@mplistdepth\z@
   \makeatletter
   \@mplistdepth=1
   \makeatother
   \begin{enumerate}
   \item Spacing within wrapped text is the same, but the spacing
     between items is different. 
   \item adsflkj adsflkj 
   \item qeworui qeworui 
   \item zcx,vmn zcx,vmn 
   \item lkjasdf lkjasdf 
   \item mbnnert mbnnert 
   \end{enumerate}
 \end{minipage}
 \hfill
 \fbox{Tikz image here}
\end{enumerate}

\end{document}

一種「更好」的方法是修補@iiiminipage(「環境」的最內層)minipage並使其意識到它應該保留清單深度,具體取決於條件:

說明\mpsavelistdepthtrue是否應啟用和\mpsavelistdepthfalse停用保留。

這僅適用於enumerate環境,因為\@enumdepth處理的是enumerate,而不是itemize(然後是相關的深度計數器\@itemdepth

\documentclass{article} %% 'exam' class not needed for MWE

\usepackage{enumitem}

\usepackage{xpatch}

\newif\ifmpsavelistdepth
\mpsavelistdepthtrue  % Enabling the list depth save for enumerate environments

\makeatletter


\xpatchcmd{\@iiiminipage}{%
  \let\@listdepth\@mplistdepth \@mplistdepth\z@
}{%
  \let\@listdepth\@mplistdepth
  \ifmpsavelistdepth
  \@mplistdepth\@enumdepth  % use the current depth (stored in \@enumdepth
  \fi
}{\typeout{Patching minipage succeeded}}{\typeout{Patching failed}}% End of patching

\makeatother


\begin{document}
\begin{enumerate}
\item  This is a standard nested enumeration.
  \begin{enumerate} 
  \item Spacing within wrapped text and between lines of the enumeration
    looks okay to me. 
  \item adsflkj adsflkj 
  \item qeworui qeworui 
  \item zcx,vmn zcx,vmn 
  \item lkjasdf lkjasdf 
  \item mbnnert mbnnert 
  \end{enumerate}

\item The possible answers to this question are in a minipage, 
  to accomodate an image to the right   

  \begin{minipage}[t]{0.6\linewidth}
    \begin{enumerate}
   \item Spacing within wrapped text is the same, but the spacing
     between items is different. 
   \item adsflkj adsflkj 
   \item qeworui qeworui 
   \item zcx,vmn zcx,vmn 
   \item lkjasdf lkjasdf 
   \item mbnnert mbnnert 
   \end{enumerate}
 \end{minipage}
 \hfill
 \fbox{Tikz image here}
\end{enumerate}

\end{document}

在此輸入影像描述

相關內容