我有一个包含多个标签的文档\maketitle
。我想要一些宏,让我可以用一个命令重新定义标题。虽然下面的代码产生了我想要的输出,
\documentclass{article}
\usepackage{titling}
\begin{document}
\makeatletter
\def\maketitle{%
\par\textbf{\@title}%
\par{\@author}%
\par}
\makeatother
\title{First title}
\maketitle
\makeatletter
\def\maketitle{%
\par\textit{\@title}%
\par{\@author}%
\par}
\makeatother
\title{Second title}
\maketitle
\end{document}
我确实需要有封装重新定义的宏\maketitle
。我希望这样的事情能够工作:
\documentclass{article}
\usepackage{titling}
\newcommand{\mytitleOne}{\makeatletter
\def\maketitle{%
\par\textbf{\@title}%
\par{\@author}%
\par}
\makeatother}
\newcommand{\mytitleTwo}{\makeatletter
\def\maketitle{%
\par\textit{\@title}%
\par{\@author}%
\par}
\makeatother}
\begin{document}
\mytitleOne
\title{First title}
\maketitle
\mytitleTwo
\title{Second title}
\maketitle
\end{document}
答案1
\documentclass{article}
\usepackage{titling}
\makeatletter
\newcommand\settitlebf{%
\def\maketitle{%
\par\textbf{\@title}%
\par\@author%
\par}
}
\newcommand\settitleit{%
\def\maketitle{%
\par\textit{\@title}%
\par\@author%
\par}
}
\makeatother
\begin{document}
\settitlebf
\title{Title One}
\maketitle
\settitleit
\title{Title Two}
\maketitle
\end{document}