2

Imagine you have an enumerate environment and one of the items spans many lines. Normally, the numbering (e.g., 1., 2., 3., ...) is aligned with the top of the item, i.e., the first line. How can I have it vertically aligned in the center?

Example:

\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
  • put the text in a minipage or parbox {\linewidth} theyarevertically centred by default May 22 at 18:50

2 Answers 2

2

I suggest you encase the multi-line items in parboxes of width \linewidth.

enter image description here

\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}
5
  • Thanks, that works. May 22 at 20:42
  • 1
    The vertical spacings are not uniform, though.
    – egreg
    May 22 at 21:31
  • @egreg - Switching from minipage to \parbox brings some relief.
    – Mico
    May 22 at 21:54
  • @Mico I don't think so, as both use the same internals. Also, why subtracting \leftmargin?
    – egreg
    May 22 at 22:10
  • @egreg - "Why subtract \leftmargin?" Ah, that was a left-over from the earlier version (the one that used a minipage). Fixed now. Oh, and I've upvoted your answer...
    – Mico
    May 23 at 1:46
3

The following assumes that the text in the items is equally vertically spaced (no too high or deep line) and is a single paragraph.

The idea is to count the number of lines in the paragraph and raise the \parbox accordingly.

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

As usual, showframe and lipsum are just for the example.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.