セクションの見出しを再フォーマットしてテキストを含める

セクションの見出しを再フォーマットしてテキストを含める

簡単な答えがあるはずですが、\renew コマンドでさまざまなことを試してみて、イライラしてしまいました。

すべてのセクションの見出しを再フォーマットして、自動番号付けで「質問」というテキストを含めたいと思います。現在、次のようになっています。

\section{Question 1}
\section{Question 2}
\section{Question 3}

期待通りの結果です。セクションの見出しを次のように表示したいのですが、

\section{}
\section{}
\section{}

テキストは次のように表示されます

Question 1
Question 2
Question 3

これは可能ですか? もし可能であれば、誰かヒントを持っていますか? どうもありがとうございます、CC。

答え1

あなたはこんなことで満足しますか?

\documentclass{article}

\newcounter{qnumber}
\setcounter{qnumber}{0}

\newcommand{\newquestion}{\addtocounter{qnumber}{1}\section*{Question \theqnumber}}

\begin{document}

\newquestion

abc

\newquestion

cdf

\end{document}

ここに画像の説明を入力してください

答え2

samcarter のソリューションに似ていますが、次のものを使用します\section(引数は不要)。

ここに画像の説明を入力してください

\documentclass{article}

\let\oldsection\section% Store \section in \oldsection
\renewcommand{\section}{% Update \section
  \refstepcounter{section}% Step section counter
  \oldsection*{Question~\thesection}}% Write a \section* with a specific header

\begin{document}

\section

Some content.

\section

Some more content.

\end{document}

関連情報