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 would like to be able to control the nesting level of an item (so that I can align the text with text that is at a deeper level of nesting.) I have been able to read the value of \@itemdepth counter. I was not able to change it. Is it possible to change the value of \@itemdepth from my file and if so, how would I do it? Or is there a better way to do what I want to do? Thanks for any help you can provide.

A sample of the code I would like to get working. I am new to LaTeX and the code likely has several errors in it. Any help would be appreciated.

\documentclass{article}
\usepackage{amssymb, amsmath} 
\usepackage{ifthen} 

\makeatletter   % needed to access \@itemdepth
\newcounter{hangparsindentedlevel}

\newenvironment{hangpars}[1][0]{%
   \begin{list}{}{%
      \setcounter {hangparsindentedlevel}{\@itemdepth}%
      \ifthenelse {#1 > 0} { %
         \setcounter {\@itemdepth}{#1}%
         }%
         {%
         \relax%
         }%
      \setlength{\itemindent}{-\leftmargin}%
      \setlength{\listparindent}{-\leftmargin}%
      \setlength{\partopsep}{0in} \setlength{\parskip}{0in} \setlength{\topsep}{0in}%
      }%
      \item{}%
   }%
   {\end{list}}%
\makeatother

\begin{document}

\begin{hangpars}[0]
test text 1.  test text 1. test text 1.  test text 1. test text 1.  test text 1. test text 1.  test text 1. test text 1.  test text 1. 

\begin{hangpars}[2]
test text 2.  test text 2. test text 2.  test text 2. test text 2.  test text 2. test text 2.  test text 2. test text 2.  test text 2. 
\end{hangpars}

test text 3.  test text 3. test text 3.  test text 3. test text 3.  test text 3. test text 3.  test text 3. test text 3.  test text 3. 

\end{hangpars}

\end{document}

The output I was hoping for would have the firt line of the paragraph with test text 1 starting at the left most edge and all subsequent lines of the paragraph would be indented one level.
The first line of the paragraph with test text 2 (with the hangpars[2]) would start indented two levels from the left edge and all subsequent lines of the paragraph would be indented three levels. The last paragraph would be formated as the first paragraph was.

test text 1.  test text 1. test text 1.  test text 1. test text 1.  
      test text 1. test text 1.  test text 1. test text 1.
      test text 1.
            test text 2.  test text 2. test text 2.  test text 2. 
                  test text 2.  test text 2. test text 2.  test 
                  text 2. test text 2.
test text 3.  test text 3. test text 3.  test text 3. test text 3.
      test text 3. test text 3.  test text 3. test text 3.
      test text 3.
share|improve this question
    
Can you post in the question, what the output should look like? –  Peter Grill Sep 14 '11 at 19:13
    
Peter thanks again for helping me on this. When I tried to enter the output using spaces or tabs this space was removed and you could not see what I wanted it to look like. I added a description that I hope is clear. Please let me know if it is confusing. Thanks again. Mark –  Mark Banghart Sep 14 '11 at 22:36

1 Answer 1

If that is all you want to do it is easiest just to use a list environment, such as the enumitem package.

There is a lot more flexibility that is already built into this environment, so unless there really is a good reason to build your own, I would try to see if you can accomplish what you want with an existing package. Here I have defined a new hangpars list for you and specified some settings to be used at each level of the list. Adjust these as you wish. The code below produces:

enter image description here

\documentclass{article}
\usepackage{enumitem}

\newlist{hangpars}{itemize}{5}%
\setlist[hangpars]{label={}}% no labels for all levels
\setlist[hangpars,1]{leftmargin=0cm,itemindent=-0.7cm}%
\setlist[hangpars,2]{leftmargin=2cm,itemindent=-0.7cm}%
\setlist[hangpars,3]{leftmargin=4cm,itemindent=-0.7cm}%
\setlist[hangpars,4]{leftmargin=5cm,itemindent=-0.7cm}%

\begin{document}
\begin{hangpars}
\item test text 1.  test text 1. test text 1.  test text 1. test text 1.  
test text 1. test text 1.  test text 1. test text 1.
test text 1.
\begin{hangpars}
\item test text 2.  test text 2. test text 2.  test text 2. 
test text 2.  test text 2. test text 2.  test 
text 2. test text 2.
\end{hangpars}
\end{hangpars}
\begin{hangpars}
\item test text 3.  test text 3. test text 3.  test text 3. test text 3.
test text 3. test text 3.  test text 3. test text 3.
test text 3.
\end{hangpars}
\end{document}
share|improve this answer
    
Peter, Thanks for the suggestion. I will be doing this numerous times in my paper. And the text is not the test text that I was using here. Also, when I tried your code it only indented the test text paragraph once. I was trying to build this on top of the generalized item package because it did not require label. I just need a way to tell it to use the \@itemdepth given. Is there a way to do this or something like it? –  Mark Banghart Sep 15 '11 at 0:06
    
See updated answer. Defined a hangpars list environment similar to what you want. –  Peter Grill Sep 15 '11 at 2:00

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.