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 want to show an indented paragraph in which indentation means the the top level condition is acquired (suppose a if then else structure) a copy of what I need is shown
Indented Structure

I have implemented this sample using the following code:

\documentclass{article}

\begin{document}

\newenvironment{myindentpar}[1]%
{\begin{list}{}
         {\setlength{\leftmargin}{#1}}
         \item[]
}
{\end{list}}

\begin{myindentpar}{1em}
\textbf{HelloMsg} 
\end{myindentpar}

\begin{myindentpar}{2em}
This is a text to fill the line.

\textbf{HelloMsg.Hello}
\end{myindentpar}

\begin{myindentpar}{3em}
 The Hello Message description goes here

 \textbf{HelloMsg.Hello.Ack}
\end{myindentpar}

\end{document}

But frankly speaking it looks so odd to me. Do we have any better way of doing this? Do we have a package that depicts some vertical lines that shows which item is underneath of the other? (such a thing is so common in programming environments. Some slim lines are drawn to show where a block ends)

Edit This section contains materials regarding the comments, it is not part of the main question.

\documentclass{article}

\begin{document}

this is the default indentation!!!

\noindent this is without indentation

\newenvironment{myindentpar}[1]%
{\begin{list}{}
         {\setlength{\leftmargin}{#1}}
         \item[]
}
{\end{list}}

\begin{myindentpar}{1em}
\textbf{HelloMsg (indented 1em)} 
\end{myindentpar}

\begin{myindentpar}{2em}

\textbf{HelloMsg.Hello (indented 2em)}
\end{myindentpar}

\begin{myindentpar}{3em}

 \textbf{HelloMsg.Hello.Ack (indented 3em)}
\end{myindentpar}

this is source of critic!

\newenvironment{herbertIndentPar}%
{\begin{list}{}
  {\addtolength\leftmargin{1em}}
   \item[]}
{\end{list}}

\begin{herbertIndentPar}
\textbf{Hello Herbert (I'm shifted 3em to the right! but my parameter says it must be shifted 2em one for the start of the paragraph and plus one for the passed 1em)} 

\begin{herbertIndentPar}

\textbf{HelloMsg.Hello}

\begin{herbertIndentPar}

 \textbf{HelloMsg.Hello.Ack}
\end{herbertIndentPar}
another line
\end{herbertIndentPar}
another line
\end{herbertIndentPar}

this is the source of critic (back to 1em indent)!

\end{document}

I am geting this output: alt text

share|improve this question
    
if this is for code the algorithms package cano it. –  Yiannis Lazarides Jan 5 '11 at 14:03
    
I am aware of algorithm package, but this is not for code. See my previous post: tex.stackexchange.com/questions/6415/… –  Yasser Sobhdel Jan 5 '11 at 14:10
add comment

1 Answer 1

up vote 2 down vote accepted
\documentclass{article}
\usepackage[showframe]{geometry}

\newlength\myLeftmargin

\newenvironment{herbertIndentPar}
  {\begin{list}{}%
    {\global\addtolength\myLeftmargin{\parindent}%
     \setlength\leftmargin{\myLeftmargin}%
     \listparindent=0pt
    }%
     \item\relax}
  {\end{list}\global\addtolength\myLeftmargin{-\parindent}}

\begin{document}



\begin{herbertIndentPar}
\textbf{Hello Herbert (I'm shifted 3em to the right! but my 
parameter says it must be shifted 2em one for the start of the 
paragraph and plus one for the passed 1em)} 

\begin{herbertIndentPar}
\textbf{HelloMsg.Hello}

\begin{herbertIndentPar}
\textbf{HelloMsg.Hello.Ack}
\end{herbertIndentPar}

another line
\end{herbertIndentPar}

another line
\end{herbertIndentPar}

this is the source of critic (back to 1em indent)!

\end{document}

alt text

share|improve this answer
6  
@Herbert: Looks like a good answer. If you have time for that, you could improve the answer (and other answers) by adding one or two sentences of explanation. –  Hendrik Vogt Jan 5 '11 at 15:01
    
@Herbert: Thanks! That is it. Can you please tell me why in my code after the last \end{myindentpar} the next paragraph (or ordinary text) is still shifted to the right as wide as the first parameter passed to the first \begin{myindentpar}. let me rephrase with a sample: copy my code to a file and just before \end{document} add a "Text". It will be indented for 1em, why is it so? (I have to use \noindent before it to suppres the indent, but your code works fine :D) –  Yasser Sobhdel Jan 5 '11 at 16:04
    
@Yasser: it is only indented, as usual. Compare it with \noindent Text after the last environemnt. Use \parindent=0pt in your preamble if you do not like it. If I do not understand your problem, then please create a small example –  Herbert Jan 5 '11 at 16:20
    
@Herbert: let me clarify, use your code and place a text just before the \end{document}. It will not be indented. Now use my code, it will be indented but it is out of my new environment but keeps the indentation. why? –  Yasser Sobhdel Jan 5 '11 at 16:40
    
@Yasser: maybe that I am blinded my the light, but I cannot see any difference. I uploded the two screenshots above. –  Herbert Jan 5 '11 at 17:02
show 4 more comments

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.