7

I have a document with many \description environments. All of them are defined like this:

\begin{description}[leftmargin=2.5cm,style=sameline]
    \item[\texttt{foo}] bar 
    \item[\hspace{7mm}\texttt{sub}] inner
\end{description}

How can I use \renewcommand (or something similar) to not always have to write [leftmargin=2.5cm,style=sameline] and also have the argument of \item automatically be in \texttt and optionally be preceded by some space \hspace{7mm}?

Other solutions are also greatly appreciated.

2 Answers 2

9

You can use newlist from the enumitem package to define your custom styles.

enter image description here

Code:

\documentclass{article}
\usepackage{enumitem}

\newlist{MyDescription}{description}{1}
\setlist[MyDescription]{leftmargin=2.5cm,style=sameline, font=\texttt}

\newcommand*{\IndentedItem}[1][]{\item[\hspace{7mm}#1]}%

\begin{document}\noindent
Manually specified:
\begin{description}[leftmargin=2.5cm,style=sameline]
    \item[\texttt{foo}] bar 
    \item[\hspace{7mm}\texttt{sub}] inner
\end{description}

\noindent
Using \verb|MyDescription|:
\begin{MyDescription}
    \item[foo] bar 
    \IndentedItem[sub] inner
\end{MyDescription}
\end{document}
2
  • This looks awesome! Going to use it - Thank You! One more question, I don't know if it's possible: I would like to replace \item[\hspace{7mm}sub] inner with something like \item2[sub] inner and have the same result. Is it possible? Thank You for your superfast help!
    – jlordo
    Dec 4, 2012 at 20:12
  • @jlordo: Not recommended to have numbers in the macro names, btu can be done. Have updated solution to define a \IndentedItem macro. Dec 4, 2012 at 20:18
2

You can define a new environment:

\newenvironment{mydescription}{\begin{description}[leftmargin=2.5cm,style=sameline]} 
                              {\end{description}
2
  • This looks like it solves the first part of my problem. Thank You! Do You also have a hint for the default formatting of my \item items?
    – jlordo
    Dec 4, 2012 at 20:06
  • I'd go with peter grill's solution.
    – A.Ellett
    Dec 4, 2012 at 20:11

You must log in to answer this question.

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