缩进段落

缩进段落

我想显示一个缩进的段落,其中缩进意味着获取了顶级条件(假设是 if then else 结构),显示我需要的副本
缩进结构

我使用以下代码实现了该示例:

\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}

但坦率地说,这对我来说看起来很奇怪。我们有更好的方法吗?我们是否有一个包,其中描绘了一些垂直线,以显示哪个项目位于另一个项目下方?(这种事情在编程环境中非常常见。绘制一些细线来显示块的结束位置)

编辑本节包含有关评论的材料,它不是主要问题的一部分。

\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}

我得到了这个输出: 替代文本

答案1

\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}

替代文本

相关内容