重新格式化章節標題以包含文本

重新格式化章節標題以包含文本

我確信有一個簡單的答案,但我已經到了使用 \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}

相關內容