我有 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
可以跨越多页,并且不被视为牢不可破的块。