[Tex/LaTex] Subtitle for a section

sectioningsections-paragraphs

I'm using XeLaTeX to take notes in class, and I am using a new section for each lecture. Since the lectures have different teachers, I'd like a small italic subtitle for each \section.

I'm using the article class.

How would I go about doing that?

Best Answer

One problem with simply adding some formatted "teacher name" text after \section is that nothing prevents a page break immediately after the teacher name. (By default, LaTeX ensures that a section heading is followed by at least two lines of text.) Therefore I would use the titlesec package and its ability to execute additional code after the section title has been typeset (but still within \section).

\documentclass{article}

\newcommand*{\sectionpostamble}{}
\newcommand*{\teacher}[1]{%
  \def\sectionpostamble{#1}%
}

\usepackage{titlesec}
\titleformat{\section}
  {\normalfont\Large\bfseries}{\thesection}{1em}{}
  [\normalfont\small\itshape\raggedleft\sectionpostamble
  \global\let\sectionpostamble\relax]

\usepackage{blindtext}

\begin{document}

\teacher{Donald~E. Knuth}
\section{foo}

\blindtext

\section{bar}

\blindtext

\end{document}

(The blindtext package is only used to add some dummy text to the example.)

Related Question