考慮
\documentclass{article}
\usepackage{titlesec}
\def\bl#1 #2 {#1\textsuperscript{#2}\,}
\titleformat{\section}[runin]{}{}{0pt}{}[. ]
%\titleformat{\section}[runin]{}{}{0pt}{\bl}[. ]
\begin{document}
\section{3 a 21}
main text.
\end{document}
註解掉該行的目的是產生等效的 ,而\section{\bl 3 a 21}
不必為每個部分鍵入 \bl ;但它產生了一個錯誤。可以做些什麼來達到預期的結果嗎?
答案1
答案2
您也可以在沒有任何軟體包的情況下完成此操作。技巧在於, 的參數會\section
作為大括號組傳遞到程式碼的最後部分,因此如果該部分以帶有參數的巨集結尾,它將看到節標題;但你首先需要取下牙套。請注意,使用三個參數定義內部宏,我們可以輕鬆新增最後一個句點。
\documentclass{article}
\usepackage{showframe}% just for the example
\makeatletter
\renewcommand{\section}{%
\@startsection{section}{1}{\z@}%
{-3.5ex \@plus -1ex \@minus -.2ex}%
{-1em}%
{\normalfont\process@section@title}%
}
\newcommand{\process@section@title}[1]{\process@section@title@aux#1\@nil}
\def\process@section@title@aux#1 #2 #3\@nil{%
#1\textsuperscript{#2} #3.%
}
\makeatother
\setcounter{secnumdepth}{0}
\begin{document}
\section{3 a 21}
Some text for the section.
\section{4 a 42}
Some text for the section.
\end{document}