1

I'd like to make a list environment (very similar to enumerate) such that the labels are positioned above their respective content, rather than to the left. For example:

- i First item ii Second item

and so on. I've had a look at packages which allow you to customise lists but none of them seem to offer anything like this. I am open to the idea of making a new environment for this purpose from scratch, but I don't know how list environments are defined at the basic level.

  • 1
    Do you intend to nest this with other lists? I ask because most of the work involves nested lists. What you want can be implemented with a counter and \makebox. – John Kormylo Jul 1 '18 at 14:54
  • @JohnKormylo I do not intend to nest them. I can see easily how the counter would work but I don't know how list environments control each \item text. (to be clear, it sounds like you know what I want - could you elaborate?) – preferred_anon Jul 1 '18 at 15:08
  • The environment sets \leftskip (computed based on \leftmargin) and moves the label to the left using \llap (or equivalent). \item also does a \par and adds \itemsep vspace. The text simply follows. – John Kormylo Jul 1 '18 at 15:15
  • @JohnKormylo Thank you - I'm not sure how to explain this, I understand the logic completely (I could write an algorithm for what I'm trying to do in another programming language), but I don't know how to actually write that in latex. – preferred_anon Jul 1 '18 at 15:23
2

You can change label and locally redefine \item to add a linebreak.

\documentclass{article}
\usepackage{enumitem}

\usepackage{showframe} % just for the example

\newenvironment{bizarrelist}
 {\enumerate[
    align=left,
    leftmargin=0pt,
    labelwidth=0pt,
    label={\makebox[3em][r]{\roman*}},
    ref=\roman*,
    before=\changeitem,
 ]}
 {\endenumerate}
\newcommand{\changeitem}{\let\saveditem\item\def\item{\saveditem\mbox{}\\*}}

\begin{document}

\begin{bizarrelist}
\item First item
\item Second item
\end{bizarrelist}

\end{document}

enter image description here

  • Exactly what I need, thank you! (and I agree, it is a little bizarre) – preferred_anon Jul 1 '18 at 15:42
1

To complete what I started...

The code could have been simplified by setting \parksip=0pt, but since one might have a multi-paragraph \item, I went ahead and subtracted it out each time.

\documentclass{article}
\newcounter{mycounter}
\renewcommand{\themycounter}{\roman{mycounter}}

\newenvironment{mylist}{\setcounter{mycounter}{0}%
  \par\vskip-\parskip\smallskip% or whatever distance you want
  \vskip-\itemsep% remove gap for first \item
  \def\item{\par\vskip-\parskip\vskip\itemsep\noindent
  \refstepcounter{mycounter}\makebox[1cm][r]{\themycounter}\newline}}%
{\par\vskip-\parskip\smallskip}

\begin{document}
Text before.
\begin{mylist}
\item First item
\item Second item
\end{mylist}
Text after.

\end{document}
  • I understand! Thank you, I have already implemented egreg's solution but at least I now know what you were describing. – preferred_anon Jul 1 '18 at 22:05
1

Is it this you want?

\documentclass{article}
\usepackage{enumitem}
\usepackage[showframe]{geometry} 

\begin{document}

\begin{enumerate}[label=\textendash\qquad \roman*, wide=0.5em, ref=\roman*, labelwidth=\linewidth]%
\item A first item
\item A second item
\end{enumerate}

\end{document} 

enter image description here

For a centred label above the item body, you can use this code:

\begin{enumerate}[label={\makebox[\textwidth]{-- \roman* --}}, wide=0pt, ref=\roman*]%
\item A first item
\item A second item
\end{enumerate}

enter image description here

  • I was intending to have the label centered in the page (I have modified egreg's example to make this happen). This is interesting - why does the line break between the label and the text? – preferred_anon Jul 1 '18 at 22:04
  • @DanielLittlewood: I've added a simple solution for this case. – Bernard Jul 1 '18 at 22:17

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.