如何将行的一部分缩进到一定量?

如何将行的一部分缩进到一定量?

如果这是一个基本问题,我很抱歉,但是我对 LaTeX 和排版还不熟悉,我不确定如何正确表达我的问题。

我有一份如下所示的文档:

\documentclass[12pt,letterpaper]{article}
    \usepackage[margin=0.7in]{geometry}
    \usepackage[parfill]{parskip}

    \newenvironment{question}[1]
    {\par\bfseries#1.\ignorespaces}
    {\par\ignorespacesafterend}

    \newenvironment{answer}
    {\par\leftskip=2.0em\ignorespaces}
    {\par\ignorespacesafterend}
\begin{document}

\begin{question}{1}
Testing testing testing testing testing testing testing testing testing 
Testing testing testing testing testing testing testing testing testing 
Testing testing testing testing testing testing testing testing testing 

Testing testing testing testing testing testing testing testing testing 
Testing testing testing testing testing testing testing testing testing 
\end{question}
\begin{answer}
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum

lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
\end{answer}

\begin{question}{3}
Test test
\end{question}
\begin{answer}
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
\end{answer}

\end{document}

破碎的

如何修改我的question环境,以便数字后的第一行缩进到与answer环境内的文本相同的级别?我不希望数字缩进,但我希望它后面的行(但不是后续行)缩进到与 lorem ipsum 文本相同的级别。

补充一下,我只能借助图片来描述我的问题。用文字解释它正确的方法是什么?

答案1

您可以将数字放在所需宽度的框内:

\documentclass[12pt,letterpaper]{article}
    \usepackage[margin=0.7in]{geometry}
    \usepackage[parfill]{parskip}

\newlength\ansindent
\setlength\ansindent{2em}

    \newenvironment{question}[1]
    {\par\bfseries\makebox[\ansindent][l]{#1.}\ignorespaces}
    {\par\ignorespacesafterend}

    \newenvironment{answer}
    {\par\leftskip=\ansindent}
    {\par\ignorespacesafterend}
\begin{document}

\begin{question}{1}
Testing testing testing testing testing testing testing testing testing 
Testing testing testing testing testing testing testing testing testing 
Testing testing testing testing testing testing testing testing testing 

Testing testing testing testing testing testing testing testing testing 
Testing testing testing testing testing testing testing testing testing 
\end{question}
\begin{answer}
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum

lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
\end{answer}

\begin{question}{3}
Test test
\end{question}
\begin{answer}
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
\end{answer}

\end{document}

在此处输入图片描述

相关内容