Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 8 down vote accepted

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}
share|improve this answer
    
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 '12 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. –  Peter Grill Dec 4 '12 at 20:18
    
Works like a charm! Thank You! –  jlordo Dec 4 '12 at 20:20
add comment

You can define a new environment:

\newenvironment{mydescription}{\begin{description}[leftmargin=2.5cm,style=sameline]} 
                              {\end{description}
share|improve this answer
    
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 '12 at 20:06
    
I'd go with peter grill's solution. –  A.Ellett Dec 4 '12 at 20:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.