如果没有图片的话我的问题就很难解释,所以这里有一张图片。
从图中可以看出,我想创建一个环境,打印出字母 Q 和问题编号,然后跳过,最后打印问题。在这个例子中,只有 Q3 看起来像我想要的那样。
我仍然没有找到一种方法来使问题的第一个单词的首字母始终与下一行的缩进对齐,这里有人有解决办法吗?
这是我用来生成图片中文本的代码,我知道这是一个很蹩脚的工作。
\newenvironment{que}[1][]{\medskip
\large\noindent
\bfseries
\makebox[mmm][l]{Q\thequestion\enskip}
\hangafter=1 \setlength{\hangindent}{\widthof{mmm}}
\stepcounter{question} }
我对此代码的另一个问题是,我希望它自动在末尾添加 \medskip,但如果我出于某种原因这样做, \hangafter 不会添加我想要的缩进。
答案1
\documentclass[12pt]{article}
\usepackage{enumitem}
\newenvironment{que}{%
\large\bfseries
\begin{enumerate}[label=Q\arabic*]}
{\end{enumerate}\ignorespacesafterend}
\begin{document}
\section{zzz}
zz zzz zzz
\begin{que}
\item one two three one two three one two three one two three one two three
\item Apples one two three one two three one two three one two three one two three
\item Supercalifragilisticexpialidocious one two three one two three one two three one two three one two three one two three one two three one two three one two three one two three one two three one two three one two three one two three
\item one two three
\item one two three
\item one two three
\end{que}
\end{document}