在描述环境中缩进项目

在描述环境中缩进项目

我有 Q & A 命令可以缩进句子的开头,但是使用描述环境会破坏缩进。我该如何缩进描述环境?

在此处输入图片描述

这是源代码。

\documentclass{article}
\newcounter{question}
\setcounter{question}{0}

\newcommand{\HRule}{\rule{\linewidth}{0.5mm}}
\newcommand{\Hrule}{\rule{\linewidth}{0.3mm}}

\makeatletter% since there's an at-sign (@) in the command name
\renewcommand{\@maketitle}{%
  \parindent=0pt% don't indent paragraphs in the title block
  \centering
  {\Large \bfseries\textsc{\@title}}
  \HRule\par%
  \textit{\@author \hfill \@date}
  \par
}
\makeatother% resets the meaning of the at-sign (@)

\newcommand\Que[1]{%
   \leavevmode\par
   \stepcounter{question}
   \noindent
   Q\thequestion: \textit{#1}\par}

\newcommand\Ans[2][]{%
    \leavevmode\par\noindent
   {\leftskip10pt
    A: \textbf{#1} #2\par}}

\title{Title}
\author{A and B}

\begin{document}
\maketitle

%\section{MapReduce}
\Que{Q}
\Ans{
A
\begin{description}
\item[X] Y
\end{description}
}

\end{document} 

答案1

我没有使用宏\leftskip中的方法\Ans,而是使用\hspace后跟\parbox减小宽度的方法。

\documentclass{article}
\usepackage{calc}
\newcounter{question}
\setcounter{question}{0}

\newcommand{\HRule}{\rule{\linewidth}{0.5mm}}
\newcommand{\Hrule}{\rule{\linewidth}{0.3mm}}

\makeatletter% since there's an at-sign (@) in the command name
\renewcommand{\@maketitle}{%
  \parindent=0pt% don't indent paragraphs in the title block
  \centering
  {\Large \bfseries\textsc{\@title}}
  \HRule\par%
  \textit{\@author \hfill \@date}
  \par
}
\makeatother% resets the meaning of the at-sign (@)

\newcommand\Que[1]{%
   \leavevmode\par
   \stepcounter{question}
   \noindent
   Q\thequestion: \textit{#1}\par}

\newcommand\Ans[2][]{%
    \leavevmode\par\noindent
   {\hspace*{10pt}\parbox{\linewidth-10pt}{
    A: \textbf{#1} #2\par}}}

\title{Title}
\author{A and B}

\begin{document}
\maketitle

%\section{MapReduce}
\Que{Q}
\Ans{
Answer that might be long enough to skip past the end of a line
Answer that might be long enough to skip past the end of a line
Answer that might be long enough to skip past the end of a line
\begin{description}
\item[X] Y
\end{description}
}

\end{document} 

答案2

我会使用惯用的方式:使用列表

\newcommand\Ans[2][]{%
    \leavevmode\par\noindent
   {\begin{list}{}{\setlength{\leftmargin}{10pt}}%
    \item[]%
    A: %
    \textbf{#1} #2\par%
    \end{list}%
    }}

这样,对于每个\Ans以单个项目(无标签)开始的列表,您可以调整每个边距(参见例如)。

我应该提到,与parbox此处使用的解决方案不同,的内容\Ans可以跨越多页,并且不被视为牢不可破的块。

相关内容