1.6.12

Insert code before chapter title


If you use a documentclass of KOMA you can use the command \setchatperpreamble In the following example you can see the using. You can combine \setchapterpreamble with the command \dictum which is also provided by KOMA.
\documentclass{scrreprt}
\usepackage{lipsum}
\begin{document}
\setchapterpreamble[o]{Text}
\chapter{foo}
\lipsum
\end{document}
For more information please see the documentation.
By using the package titlesec you can define you own toptitle command. One suggestion is seen below
\documentclass{book}
\usepackage{titlesec}
%\titleformat{command}
%            [shape]
%            {format}
%            {label}
%            {sep}
%            {before-code}
%            [after-code]
\makeatletter
\newcommand\toptitle[1]{%
   \def\@toptitle{#1}}
\toptitle{}
\newcommand*\outputtoptitle[1][\linewidth]{%
    \ifx\@toptitle\@empty
      no Toptitle\else
      \parbox{\linewidth}{\@toptitle}\par\kern12pt\fi
}
\titleformat{\chapter}%
            {\outputtoptitle\huge\bfseries}%
            {\thechapter}%
            {12pt}%
            {}
\makeatother \usepackage{lipsum}
\begin{document}
\toptitle{\lipsum[1]}
\chapter{foo}
\lipsum
\end{document}

Without using titlesec, you can redefine the \@makechapterhead command (defined inbook.cls) which actually typesets the chapter title; you could do something along these lines:
\documentclass{book}
\usepackage{lipsum}
\newcommand\toptitle{}
\makeatletter
\def\@makechapterhead#1{%
  \vspace*{50\p@}%
  {\parindent \z@ \raggedright \normalfont
    \ifnum \c@secnumdepth >\m@ne
      \if@mainmatter
        \toptitle\par
        \huge\bfseries \@chapapp\space \thechapter
        \par\nobreak
        \vskip 20\p@
      \fi
    \fi
    \interlinepenalty\@M
    \Huge \bfseries #1\par\nobreak
    \vskip 40\p@
  }}
\makeatother
\begin{document}
\renewcommand\toptitle{{\itshape Quantum Mechanics\hfill 15.10.2011}}
\chapter{Test chapter}
\lipsum
\end{document}
enter image description here
Using the etoolbox package, the above redefinition can be done in a shorter way:
\documentclass{book}
\usepackage{etoolbox}
\usepackage{lipsum}
\newcommand\toptitle{}
\makeatletter
\patchcmd{\@makechapterhead}{\if@mainmatter}{\if@mainmatter\toptitle\par}{}{}
\makeatother
\begin{document}
\renewcommand\toptitle{{\itshape Quantum Mechanics\hfill 15.10.2011}}
\chapter{Test chapter}
\lipsum
\end{document}

No hay comentarios:

Publicar un comentario