9

Based on Alan's answer here, I would like to be able to create nicely formatted "inline" enumerated lists.

The issue I have is that the space between items on a line is always fixed, which does not look nice. I'm looking for a way to level out the spacing across lines. Any suggestion and help how to achieve something good looking would be appreaciated. Maybe I should not be using a enumeration environment? The lists in question are either just bullet points or a)-d).

\documentclass[12pt]{article}
\usepackage[inline]{enumitem}
\makeatletter
% This command ignores the optional argument for itemize and enumerate lists
\newcommand{\inlineitem}[1][]{%
\ifnum\enit@type=\tw@
    {\descriptionlabel{#1}}
  \hspace{\labelsep}
\else
  \ifnum\enit@type=\z@
       \refstepcounter{\@listctr}\fi
    \quad\@itemlabel\hspace{\labelsep}
\fi}
\makeatother

\begin{document}

% Combined inline list
\noindent This is a combined inline enumerated list.
\begin{itemize}
\item Less than 5 years \inlineitem Between 5 and 10 years
\item More than 10 years \inlineitem Do not know
\end{itemize}

\bigskip

\noindent Another list.
\begin{itemize}
\item £850
\inlineitem £1,000
\inlineitem £1,150
\inlineitem £1,500
\inlineitem Do not know
\end{itemize}

\bigskip

\noindent And the final one
\begin{enumerate}[label=(\alph*)]
\item Agree strongly \inlineitem Tend to agree \inlineitem Neither agree nor disagree
\item Tend to disagree \inlineitem Disagree strongly \inlineitem Don't know
\end{enumerate}

\end{document}

enter image description here

3
  • If you're willing to predict the number of items that will fit on a line you could align them vertically in a tabular environment. Feb 19, 2013 at 20:13
  • Related Question: Add second enumeration item on the same line?. Or is this a duplicate? Feb 20, 2013 at 2:54
  • 1
    @PeterGrill I have already linked one answer to that question in my question above. This is not a duplicate - my question is about alignment of items in several rows.
    – Jörg
    Feb 20, 2013 at 9:14

4 Answers 4

5

Here's a possible solution if you know how many items you want on each line. Your MWE does suggest that's OK.

\documentclass{article}

\newcounter{myitemcounter}

\newcommand{\myitemlabel}{$\bullet$\ }

\newcommand{\myitem}{%
\stepcounter{myitemcounter}
\myitemlabel
}

\newcommand{\anitem}[1]{%
\myitem #1 &
}

\newcommand{\lastitem}[1]{%
\myitem #1 \\
}

\newenvironment{inlineitemize}
{\setcounter{myitemcounter}{0}
\begin{tabular}{llllllllll} % you won't want more columns
}
{\end{tabular}}

\newenvironment{inlineenumerate}
{\setcounter{myitemcounter}{0}
\renewcommand{\myitemlabel}{(\alph{myitemcounter})\ }
\begin{tabular}{lllllllllll}
}
{\end{tabular}}

\begin{document}

\begin{inlineenumerate}
 \anitem{Agree strongly}
 \anitem{Tend to agree}
 \lastitem{Neither agree nor disagree}
 \anitem {Tend to disagree}
 \anitem{Disagree strongly}
 \lastitem{Don't know}
\end{inlineenumerate}

\begin{inlineitemize}
\anitem{Less than 5 years} \lastitem{Between 5 and 10 years} 
\anitem{More than 10 years} \lastitem{Do not know}
\end{inlineitemize}

\end{document}

enter image description here

With a little more work you could pass an integer argument to the new environments to specify the number of columns in order to automate the time to invoke lastitem instead of anitem. You can also set the interline spacing in the tabular environments to match your MWE.

3
  • I think that's quite a nice answer (and quite an improvement to your first version!) I guess just making a table with an automatic counter is the easiest way to achieve what I want.
    – Jörg
    Feb 21, 2013 at 15:01
  • @Jorg If you do implement the automatic counter please edit to incorporate your update or post your own answer for others to see. Feb 21, 2013 at 15:53
  • I actually meant the alphabetic counter in your answer.
    – Jörg
    Feb 21, 2013 at 22:35
4

It's not clear exactly what space you wish to change. You have some missing % at ends of lines causing additional space in the output. The following fixes that and replaces the fixed \labelsep space by glue that can shrink 20% or extend 50% of that value. It doesn't make that much difference on these examples though.

\newcommand{\inlineitem}[1][]{%
\ifnum\enit@type=\tw@
    {\descriptionlabel{#1}}%
  \hspace{1\labelsep\@plus .5\labelsep  \@minus .2\labelsep}%
\else
  \ifnum\enit@type=\z@
       \refstepcounter{\@listctr}\fi
    \quad \@itemlabel\hspace{1\labelsep\@plus .5\labelsep  \@minus .2\labelsep }%
\fi}
2
  • Sorry, I think I was unclear in my description. The easiest way to see what I mean is the last example: the (b) and (e) should be aligned as well as the (c) and (f) if there is enough space.
    – Jörg
    Feb 19, 2013 at 19:06
  • I think you have a choice you either make each item text the same length padding as required then alignment is automatic, or you don't in which case alignment isn't really possible. It's only because the list is two lines that you even see any visual connection between b and e, imagine if it was several lines the item letters would just be scattered and there would be no association of one with any one the lines above and below. Feb 19, 2013 at 20:03
3

As solution using the shortlst package, which is a development of an answer for a similar problem I gave in Inline arrangement using "enumitem". An optional argument is the number of columns in which the list will be organized (3 by default). Moreover, if an item is too long to fit in a column, it automatically takes two (or more) columns:

\documentclass[a11pt, a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern} 
\usepackage[textwidth=15cm, noheadfoot, nomarginpar]{geometry}
\geometry{showframe}

 \usepackage{shortlst}
 \newenvironment{tabenumerate}[1][3]{%
 \settowidth{\labelwidth}{\labelenumi}%
 \setlength{\leftmargini}{\dimexpr\parindent + \labelwidth + \labelsep\relax}%
 \setlength{\shortitemwidth}{\dimexpr\linewidth/#1-\labelwidth-2\labelsep\relax}%
 \begin{shortenumerate}}%
 {\end{shortenumerate}}%

 \newenvironment{tabitemize}[1][3]{%
 \settowidth{\labelwidth}{\labelitemi}%
 \setlength{\leftmargini}{\dimexpr\parindent + \labelwidth + \labelsep\relax}%
 \setlength{\shortitemwidth}{\dimexpr\linewidth/#1-\labelwidth-2\labelsep\relax}%
 \begin{shortitemize}}%
 {\end{shortitemize}}%

 \renewcommand{\labelenumi}{(\arabic{enumi})}
 \parindent = 0pt

 \begin{document}

 This is an inline itemized list.

 \begin{tabitemize}[2]
    \item Less than 5 years \item Between 5 and 10 years
    \item More than 10 years \item Do not know
 \end{tabitemize}
 Or 
 \begin{tabitemize}
    \item Less than 5 years \item Between 5 and 10 years \item[]
    \item More than 10 years \item Do not know
 \end{tabitemize}


 Another list.
 \begin{tabitemize}[6]
    \item £850
    \item £1,000
    \item £1,150
    \item £1,500
    \item Do not know
 \end{tabitemize}

 \bigskip

 And the final one: 
 \begin{tabenumerate}
     \item Agree strongly \item Tend to agree \item Neither agree nor disagree
     \item Tend to disagree \item Disagree strongly \item Don't know
 \end{tabenumerate}

 \end{document}

Result:

2

I try to do this with a newenvironment hlist with an optional number of columns. Default is 2. Unfortunately braces around each item are required. \hitem{xyz.} replaces \item xyz. It uses parbox inside minipages. Far from perfect.

\documentclass{article}

\newcounter{hitem}
\newenvironment{hlist}[2][2]{\def\hcol{#1}%
\begin{trivlist}\setcounter{hitem}{0}\item #2
}{\end{trivlist}}

\newcommand{\hitem}[1]{%
\raggedright\begin{minipage}[t]{\dimexpr\linewidth/\hcol-1em}
\refstepcounter{hitem}\renewcommand{\thehitem}{\alph{hitem}}%
\leavevmode\kern2.5em\llap{({\thehitem})\ }~\parbox[t]{\dimexpr\linewidth-3em}%
{\raggedright#1\vskip0.5\baselineskip\relax}%
\end{minipage}\hskip1em}

\begin{document}

%\hrulefill

\begin{hlist}
 \hitem{Frere,}
 \hitem {Jacques}
 \hitem{Dormez}
 \hitem {vous}
 \hitem{Sonnez}
 \hitem{les}
 \hitem{matines!}
 \hitem {Din,}
 \hitem {dan, dong.}
\end{hlist}

\begin{hlist}[4]
 \hitem{Frere Jacques, Frere Jacques}
 \hitem {Dormez vous? dormez vous?}
 \hitem{Sonnez les matines! Sonnez les matines!}
 \hitem {Din, dan, dong. Din, dan, dong.}
 \hitem{Frere Jacques, Frere Jacques}
 \hitem {Dormez vous? dormez vous?}
 \hitem{Sonnez les matines! Sonnez les matines!}
 \hitem {Din, dan, dong. Din, dan, dong.}
 \hitem{Frere Jacques, Frere Jacques}
 \hitem {Dormez vous? dormez vous?}
\end{hlist}


\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .