16

Consider the following minimal example:

\documentclass{article}

\setlength{\parindent}{0mm}

\usepackage{paralist}
\usepackage{tabto}

\begin{document}

\NumTabs{3}
\begin{inparaenum}
\item text
\tab\item text
\tab\item text
\tab\item text
\tab\item text
\tab\item text   
\end{inparaenum}

\end{document}

Which results in:

image

It does exactly what I want, but I was wondering whether it was possible to create an environment, say tabbedEnum so that we can eliminate the use of the \tab, in particular, that the first case doesn't need a tab but all others do. Something of the form:

\begin{tabbedEnum}[3]
\item text
\item text
\item text
\item text
\item text
\item text
\end{tabbedEnum}
rtzll
  • 5,531
Geoff
  • 2,637
  • If enumitem package is an option, then you can tweak the answer in http://tex.stackexchange.com/questions/46665/multiple-choices-questions-in-2-or-3-columns to your liking – hpesoj626 Jan 06 '13 at 14:14

2 Answers2

12

Just redefine \item to do what you want, but after the first use:

\documentclass{article}

\setlength{\parindent}{0mm}

\usepackage{paralist}
\usepackage{tabto}

\newenvironment{tabbedenum}[1]
 {\NumTabs{#1}\inparaenum\let\latexitem\item
  \def\item{\def\item{\tab\latexitem}\latexitem}}
 {\endinparaenum}

\begin{document}

\begin{tabbedenum}{3}
\item text
\item text
\item text
\item text
\item text
\item text
\end{tabbedenum}

\bigskip

\NumTabs{3}
\begin{inparaenum}
\item text
\tab\item text
\tab\item text
\tab\item text
\tab\item text
\tab\item text   
\end{inparaenum}

\end{document}

Since we are using the original \item command at the end, you can also use the optional argument after \item.

enter image description here

egreg
  • 1,121,712
9

Well, you can define your own environment that uses some \inner@tab that redefines itself on first use to call \tab and redefines \item to call \inner@tab before it issues the real \item:

\documentclass{article}

\usepackage{paralist}
\usepackage{tabto}
\usepackage{etoolbox}

\makeatletter
\newenvironment{tabbedEnum}[1][3]{%
  \ifblank{#1}{\NumTabs{3}}{\NumTabs{#1}}%
  \inparaenum
    \let\orig@item\item
    \def\inner@tab{\let\inner@tab\tab}%
    \renewcommand\item[1][]{%
      \inner@tab\ifblank{##1}{\orig@item}{\orig@item[##1]}}%
    \ignorespaces
}{%
  \endinparaenum
}
\makeatother

\usepackage{lipsum}

\begin{document}

\lipsum[1]

\noindent
\begin{tabbedEnum}
 \item text
 \item text
 \item text
 \item text
 \item text
 \item text
\end{tabbedEnum}

\lipsum[2]

\end{document}

enter image description here

As an alternative you could use exsheets' {tasks} environment. It does not look exactly the same, though. Anyway, here it is:

\documentclass{article}
\usepackage{exsheets}

% \NewTasks[options]{name}[separator](default number of columns)
% all arguments except {name} are optional
\NewTasks[label=tsk.]{tabbedEnum}[\item](3)

\usepackage{lipsum}% for dummy text

\begin{document}

\lipsum[1]

\begin{tabbedEnum}
 \item text
 \item text
 \item text
 \item text
 \item text
 \item text
\end{tabbedEnum}

\lipsum[2]

\end{document}

enter image description here

cgnieder
  • 66,645
  • I really like the tasks environment from exsheets! Note that it is now available as a standalone package, tasks. Thanks for pointing this out, it also solved an old problem of mine for formatting worksheets: http://tex.stackexchange.com/questions/133330/multicolumn-list-with-same-number-of-items-in-each-column – Chris Chudzicki Oct 22 '15 at 15:21
  • when I copy-paste your MWE for the second solution (using exsheets), I get an array, but it's not enumerated, it just says "tsktext tsktext tsktext" etc. Any ideas? Literal copy-paste, so I'm at a loss. – Rax Adaam Apr 10 '18 at 17:10