Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 9 down vote accepted

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.)

share|improve this answer
    
What would I have to change to make this work with subsections as well? –  Per Enström Feb 11 '11 at 18:37
1  
@InfiniteSquirrel: I believe just change \titleformat{\section} to \titleformat{\subsection}, then adjust the formatting in the three lines following to typeset the subsection how you like. For me, this involved changing \Large to \large and \thesection to \thesubsection, both in the first line following the \titleformat command. –  Tim Nov 4 '11 at 13:57

You can define such a command yourself. For example:

\newcommand\teacher[1]{\begin{flushright}\small\textit{#1}\end{flushright}}

This can be used as

\section{TeX}
\teacher{Prof.~Knuth}
share|improve this answer
2  
Should be \teacher{Prof.~Knuth}, shouldn't it? To get the correct spacing I mean. (My German nature tells me to also add the Dr.~, while I'm not sure if the full title is necessary for class notes.) –  Martin Scharrer Feb 1 '11 at 17:44
    
@Martin: Well, I agree it's a good manner to use ~. However, ~ does not modify the spacing, but only mean "nonbreak space". There's no different here (it's very short). –  Leo Liu Feb 1 '11 at 17:57
4  
@Leo Liu: There is normally no change in spacing inside normal text if ~ is used, BUT TeX adds an extra wide space after the . because it thinks its the end of a sentence. Using a ~ or \ fixes that. The ~ has the added benefit of being non-breakable as you pointed already out. I would therefore add a \frenchspacing in the flushright environment to directly disable the extra space after .. –  Martin Scharrer Feb 1 '11 at 18:11
    
@Martin: You are right. I forgot that. –  Leo Liu Feb 1 '11 at 18:23
    
Is there any way of eliminating the line spacing between the \section and the \teacher? –  Per Enström Feb 1 '11 at 20:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.