5

I'm trying to recreate a list in some work I'm doing and struggling to get all of the component parts to align.

Image of what I'm trying to get

The list in the middle there is what I'm trying to replicate.

Does anyone have any insight as to what commands I could use?

3
  • 1
    you could use align* or simply tabular
    – Rico
    Commented Feb 17, 2013 at 14:59
  • Thanks Rico, hadn't thought of using tabular. Obvious now!
    – hamchapman
    Commented Feb 17, 2013 at 15:13
  • Welcome to TeX.SX. Commented Feb 17, 2013 at 15:14

3 Answers 3

3

You can also use the tabbing environment with some code to wrap long lines

\documentclass[a4paper,10pt]{article}
\makeatletter

\newlength\tdima
\newcommand\tabfill[1]{%-- Parbox that fills up rest for the line
      \setlength\tdima{\linewidth}%
      \addtolength\tdima{\@totalleftmargin}%
      \addtolength\tdima{-\dimen\@curtab}%
      \parbox[t]{\tdima}{#1\ifhmode\strut\fi}}

\newcounter{numcntr}
\newcommand*\putnum{\stepcounter{numcntr}\alph{numcntr}.}

\makeatother
\begin{document}

\begin{tabbing}
a.\quad\=$J(m)[E1]$:~\=\kill

\putnum \>$P(n)$: \>\tabfill{add 1 to the number in register $n$, i.e.\ $\langle n'\rangle = \langle n\rangle+1$.}\\
\putnum \>$D(n)$: \>\tabfill{subtract 1 from the number in register $n$, i.e.\ $\langle n'\rangle = \langle n\rangle-1$.  $(\langle n\rangle \not= 0)$.}\\
\putnum \>$O(n)$: \>\tabfill{``clear'' register $n$, i.e.\ place 0 in it, i.e.\ $\langle n'\rangle=0$.}

\end{tabbing}

\end{document}

enter image description here

2

Using the hack from here Enumerated description list, which is ugly because it makes use of the fact that the commands in the font-key are executed right before the label is typeset, I put together the following MWE:

\documentclass{scrartcl}
\usepackage{enumitem}
\newcounter{descriptcount}
\begin{document}
\itshape
\begin{description}[
  leftmargin=2.5cm,
  style=nextline,
  before={\setcounter{descriptcount}{0}},
  font=\normalfont\itshape{\stepcounter{descriptcount}\alph{descriptcount}.)}~
]
  \item[$P(n)$:] add $1$ to the number in register $n$, i.e. $\langle n' \rangle = \langle n \rangle + 1$.
  \item[$D(n)$:] subtract $1$ from the number in register $n$, i.e. $\langle n' \rangle = \langle n \rangle - 1$. \quad ($\langle n \rangle \neq 0$)
  \item[long label bla bla bla] Content skips to next line.
\end{description}
\end{document}

Desired output

Note that this only works in documentclasses which have the description environment available.

More persistent solution

If you want to use the list over and over again in your document, consider defining a new list environment in your preamble:

\documentclass{scrartcl}
\usepackage{enumitem}
\newcounter{descriptcount}
\newlist{enum-descr}{description}{10} % 10 is the max-depth
\setlist[enum-descr]{
  leftmargin=2.5cm,
  style=nextline,
  before={\setcounter{descriptcount}{0}},
  font=\normalfont\itshape{\stepcounter{descriptcount}\alph{descriptcount}.)}~
}
\begin{document}
\itshape
\begin{enum-descr}
  \item[$P(n)$:] add $1$ to the number in register $n$, i.e. $\langle n' \rangle = \langle n \rangle + 1$.
  \item[$D(n)$:] subtract $1$ from the number in register $n$, i.e. $\langle n' \rangle = \langle n \rangle - 1$. \quad ($\langle n \rangle \neq 0$)
  \item[long label bla bla bla] Content skips to next line.
\end{enum-descr}
\end{document}

Note that every sub-list will have the a.),b.),c.) numbering again.

2

Here's a solution using tabularx

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{lipsum}
\newcounter{itemcounter}
\newcommand{\myitem}{\stepcounter{itemcounter}\alph{itemcounter}.}
\usepackage{tabularx}
\pagestyle{empty}
\newcommand{\nvalue}[1]{\langle{#1}\rangle}
\begin{document}

\begin{tabularx}{\linewidth}{cl>{\em}X}
\myitem &    $P(x):$     &   add $1$ to the number in register $n$, \emph{i.e.} $\nvalue{n\prime}  = \nvalue{n}  +1$.   \\
\myitem &    $D(n):$     &   subtract $1$ from the number in register $n$, \emph{i.e.} $\nvalue{n\prime}  = \nvalue{n} -1$. $(\nvalue{n}  \not= 0)$. \\
\myitem &    $O(n):$     &  ``clear'' register $n$, \emph{i.e.} lace $0$ in it, \emph{i.e.} $\nvalue{n\prime} =0$.
\end{tabularx}

\end{document}

tabularx allows you to specify the width of the table and gives you an X column which will format as a paragraph column whose width is the remainder of the designated space after building the other columns.

enter image description here

Of course, if you are going to have multiple such tables you may want to reset the counter (manually) or you can create a new environment.

Turns out making an environment using tabularx is not as straight-forward as one would think. Since this gave me a few headaches trying to figure out, I'll show you how (just in case you want to make an enviornment). The details of why it has to be done this way can be found at https://tex.stackexchange.com/a/25778/22413

Here's how to define the environment:

\newenvironment{mytablex}{\setcounter{itemcounter}{0}\tabularx{\linewidth}{clX}}
                         {\endtabularx}

Though the spacing will be a bit tight with this version.

Assuming the table will always stand alone and you want to think of it as it's own paragraph, you could add some vertical spacing to it (I've also put in a \noindent).

\newenvironment{mytablex}{\setcounter{itemcounter}{0}%
                          \par\vspace{2ex}%
                          \noindent\tabularx{\linewidth}{clX}}
                         {\endtabularx\par\vspace{2ex}}

Here's a new MWE:

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{lipsum}
\newcounter{itemcounter}
\newcommand{\myitem}{\stepcounter{itemcounter}\alph{itemcounter}.}
\usepackage{tabularx}
\pagestyle{empty}
\newcommand{\nvalue}[1]{\langle{#1}\rangle}
\newenvironment{mytablex}{\setcounter{itemcounter}{0}%
                          \par\vspace{2ex}%
                          \noindent\tabularx{\linewidth}{clX}}
                         {\endtabularx\par\vspace{2ex}}
\begin{document}

\begin{tabularx}{\linewidth}{cl>{\em}X}
\myitem &    $P(x):$     &   add $1$ to the number in register $n$, \emph{i.e.} $\nvalue{n\prime}  = \nvalue{n}  +1$.   \\
\myitem &    $D(n):$     &   subtract $1$ from the number in register $n$, \emph{i.e.} $\nvalue{n\prime}  = \nvalue{n} -1$. $(\nvalue{n}  \not= 0)$. \\
\myitem &    $O(n):$     &  ``clear'' register $n$, \emph{i.e.} lace $0$ in it, \emph{i.e.} $\nvalue{n\prime} =0$.
\end{tabularx}

Here's with the new environment.

\lipsum[1]

\begin{mytablex}
\myitem &    $P(x):$     &   add $1$ to the number in register $n$, \emph{i.e.} $\nvalue{n\prime}  = \nvalue{n}  +1$.   \\
\myitem &    $D(n):$     &   subtract $1$ from the number in register $n$, \emph{i.e.} $\nvalue{n\prime}  = \nvalue{n} -1$. $(\nvalue{n}  \not= 0)$. \\
\myitem &    $O(n):$     &  ``clear'' register $n$, \emph{i.e.} lace $0$ in it, \emph{i.e.} $\nvalue{n\prime} =0$.
\end{mytablex}

\lipsum[2]
\end{document}

And here are the results:

enter image description here

2
  • What about sub-lists? I think this is pretty nasty when using tabularxs. Commented Feb 17, 2013 at 15:42
  • 1
    @HenriMenke. True, using tabularx this way will make sublists hard to construct. But if the user doesn't need to go to that level, then this is as much structure as seems adequate.
    – A.Ellett
    Commented Feb 17, 2013 at 15:56

You must log in to answer this question.

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