![如何对齐 \@hangfrom 段落?](https://linux22.com/image/239797/%E5%A6%82%E4%BD%95%E5%AF%B9%E9%BD%90%20%5C%40hangfrom%20%E6%AE%B5%E8%90%BD%EF%BC%9F.png)
我正在尝试编写一份带有编号问题的采访,看起来像这样:
Q1. What is your name?
A. My name is Sir Lancelot of Camelot.
Q2. What is your quest?
A. To seek the Holy Grail.
Q3. What is your favourite colour?
A. Blue.
到目前为止我一直在使用计数器和\@hangfrom
宏:
\newcounter{qanda}
\setcounter{qanda}{1}
\makeatletter
\newcommand*\question[1]{%
\@hangfrom{\bfseries Q\arabic{qanda}.\hspace{5mm}}{\bfseries #1\par}%
}
\newcommand*\answer[1]{%
\@hangfrom{\bfseries A.\hspace{5mm}}{#1\par}%
\addtocounter{qanda}{1}%
}
\makeatother
\question{What is your name?}
\answer{My name is Sir Lancelot of Camelot.}
问题在于,由于问题后面是数字,所以问题和答案的文本最终没有对齐。有没有办法对齐段落?\@hangfrom
这里使用的工具不对吗?
答案1
当物品融入enumerate
/itemize
环境中时,它们的排列看起来会更好。通过使用enumitem
包裹您可以操纵标签的格式和对齐方式。例如,考虑以下问题/答案设置的替代方案:
\documentclass{article}
\usepackage{enumitem}% http://ctan.org/pkg/enumitem
\newcounter{question}
\newcommand*{\question}{\stepcounter{question}\item[Q\thequestion.]}%
\newcommand*{\answer}{\item[A.]}%
\begin{document}
\begin{enumerate}[align=left]
\question What is your name?
\answer My name is Sir Lancelot of Camelot.
\question What is your quest?
\answer To seek the Holy Grail.
\question What is your favourite colour?
\answer Blue.
\end{enumerate}
\end{document}
两个宏允许问题\question
和答案\answer
。问题有一个关联的计数器,其表示形式为Q{#}.
,答案只是排版为。两个标签都将使用最新版本的s选项A.
左对齐。这些可以根据需要进行修改。v3.0
enumitem
align=left
附录:由于您可能有大量问题,并且可能会引用其中一些问题,因此您可以使用标签。这需要对现有代码进行轻微修改:\stepcounter
-> \refstepcounter
。现在您可以使用:
...\refstepcounter{question}...
...
\begin{enumerate}[align=left]
\question What is your name?
\answer My name is Sir Lancelot of Camelot.
\question What is your quest? \label{quest}
\answer To seek the Holy Grail.
\question What is your favourite colour?
\answer Blue.
\question Please elaborate on Q\ref{quest}.
\answer I'm a Monty Python enthusiast.
\end{enumerate}
答案2
\documentclass[oneside,11pt]{memoir}
\usepackage{tabularx}
\newcounter{qanda}
\newenvironment{QandA}
{\par\noindent\tabularx{\linewidth}{@{}>{\bfseries}p{6mm}>{\bfseries}X}}
{\endtabularx}
\newcommand\question[1]{\global\refstepcounter{qanda}%
Q\arabic{qanda} & #1\tabularnewline}
\newcommand\answer[1]{A & #1\tabularnewline}
\begin{document}
\begin{QandA}
\question{What is your name?}
\answer{My name is Sir Lancelot of Camelot.}
\question{What is your quest?}
\answer{To seek the Holy Grail.}
\question{What is your favourite colour?}
\answer{Blue.}
\end{QandA}
\end{document}