如何在枚举环境中垂直居中对齐编号?

如何在枚举环境中垂直居中对齐编号?

假设您有一个枚举环境,其中一个项目跨越多行。通常,编号(例如 1.、2.、3.、...)与项目的顶部(即第一行)对齐。我怎样才能让它垂直对齐在中心?

例子:

\begin{enumerate}
\item this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that 
\item short line
\item short line
\item this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that 
\end{enumerate}

答案1

我建议您将多行项目括在parbox宽度为的 es中\linewidth

在此处输入图片描述

\documentclass{article}
\usepackage{calc} % allow simplified syntax for length calculations
\begin{document}

\begin{enumerate}
\item \parbox{\linewidth}{%
this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that}
\item short ling
\item short ling
\item \parbox{\linewidth}{%
this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that this is a ling that}
\end{enumerate}

\end{document}

答案2

以下假设项目中的文本垂直间距相等(没有太高或太深的线)并且是一个段落。

这个想法是计算段落中的行数并\parbox相应地提高。

\documentclass{article}

\usepackage{showframe,lipsum}

\newsavebox{\centeritembox}
\newcommand{\centeritem}[1]{%
  \par\prevdepth\maxdimen
  \sbox{\centeritembox}{%
    \parbox[t]{\linewidth}{%
      \strut#1\strut\par
      \xdef\centeritemboxlines{\the\prevgraf}%
    }%
  }%
  \item
  \raisebox{%
    \ifodd\centeritemboxlines
      \numexpr(\centeritemboxlines-1)/2\relax\baselineskip
    \else
      \dimexpr(\ht\centeritembox+\dp\centeritembox-\baselineskip)/2\relax
    \fi
  }{\usebox{\centeritembox}}%
  \par\prevdepth\maxdimen
}

\begin{document}

\lipsum[34][1-4]

\begin{enumerate}

\centeritem{\lipsum[1][1-3]}

\centeritem{\lipsum[1][1-5]}

\centeritem{Short line}

\centeritem{\lipsum[1][1-5]}

\end{enumerate}

\lipsum[35][1-4]

\begin{enumerate}

\item \lipsum[1][1-3]

\item \lipsum[1][1-5]

\item Short line

\item \lipsum[1][1-5]

\end{enumerate}

\lipsum[36][1-4]

\end{document}

与往常一样,showframelipsum仅用于示例。

在此处输入图片描述

相关内容