縮排練習

縮排練習

我正在輸入作業問題,我想要一個非常具體的格式,但我不知道從哪裡開始。我希望練習編號排成一列,然後將問題和答案與另一個「列」左對齊。為了了解我的意思,這個簡單的程式碼有效:

\documentclass{article}

\begin{document}
\begin{tabular}{l l}
    5.  & This is the question          \\
        & This is where the answer goes \\

    11. & Another Questions             \\
        & Another Answer                
\end{tabular}
\end{document}

這看起來像我想要的,但是將我的整個作業放在表格環境中並擔心對齊字元等很煩人。我真正想要的是一個可以指定練習編號的環境,它將為問題和答案創建正確的佈局。這可能嗎?謝謝!

答案1

有很多方法可以做到這一點。僅使用enumerate環境的簡單方法

\begin{enumerate}
  \item[5] This is the question.
  \item[] This is where the answer goes
\end{enumerate}

或者也許您想要自己的環境;我在下面發布了一些不同的選項 - 您可以選擇,或者可以根據其中之一構建一個。

\documentclass{article}
\usepackage{calc}

\newcommand{\question}[1]{\item[#1]}
\newcommand{\answer}{\item[]}
\newenvironment{questionandanswer}[2]{\enumerate\setcounter{enumi}{#2-1}\item#1\item[]}{\endenumerate}
\newenvironment{anotherapproach}{\enumerate}{\endenumerate}


\begin{document}

\begin{questionandanswer}{This is the question.}{5}
  This is where the answer goes
\end{questionandanswer}

\begin{anotherapproach}
  \question{5} This is the question.
  \answer This is where the answer goes
\end{anotherapproach}

\begin{enumerate}
  \item[5] This is the question.
  \item[] This is where the answer goes
\end{enumerate}
\end{document}

如果你想改變環境的縮進enumerate,那麼enumitempackage 是最明智的方法:

\documentclass{article}
\usepackage{calc}
\usepackage{enumitem}
\setlist[enumerate]{leftmargin=*}

答案2

你可以使用一個enumerate環境;的可選參數\item可讓您指派所需的標籤:

\documentclass{article}
\usepackage[nopar]{lipsum}% just to generate text for the example

\begin{document}

\begin{enumerate}
\item This is the question.

And this is where the question goes. \lipsum[2]
\item[11.] This is another question.

And this is where the question goes. \lipsum[4]
\end{enumerate}

\end{document}

在此輸入影像描述

答案3

如果您特別注重標籤之間的間距,那麼從 Gonzalo 的答案複製並進行適當修改的以下程式碼對我來說看起來不錯:

\documentclass{article}
\usepackage{enumitem}%provides the key labelsep

\begin{document}

\begin{enumerate}[labelsep=*]
\item[5.] This is the question.

And this is where the question goes. I use \texttt{labelsep}=*
\item[11.] This is another question.

And this is where the question goes. I use \texttt{labelsep}=*
\end{enumerate}

\begin{enumerate}
\item[5.] This is the question.

And this is where the question goes. No \texttt{labelsep}=*
\item[11.] This is another question.

And this is where the question goes. No \texttt{labelsep}=*
\end{enumerate}


\end{document}

輸出:

在此輸入影像描述

相關內容