# Passing shape argument to titleformat as a command

I aim at using to types of chapter headings in my document: for preambule and appendix, simple underlined upper case, while for the main chapters, I want to have a full page with "chapter n / Title" on two different lines…

I (almost) managed to do it by defining a new environment "chapterpage" and by passing arguments to \titleformat (from titlesec package) as macros (that are not defined in the same way in global and chapterpage environments.

However, I do not manage to pass the first optional argument to \titleformat following this way :( I need this as I want to use a hang shape in the former layout and a display one in the latter. I suspect it may be solved using the appropriate \protect commands, but I did not manage to fix it!

Here is a minimal example. If it worked, "Chapter 2" and "Bar" should be printed on different lines. Thank you for your help.

\documentclass[11pt]{scrreprt}

\usepackage{lipsum}
\usepackage{titlesec}
\usepackage{setspace}

\newcommand{\mychapterShape}{hang} % hang is for aligning the number with the title
\newcommand{\mychapterFormat}{\relax}
\newcommand{\mychapterBefore}{\raggedright}
\newcommand{\mychapterAfter}{\normalsize\vspace*{.8\baselineskip}\titlerule}
\newcommand{\mychapterLabel}{\thechapter} %{\relax}

\newenvironment{chapterpage}
{
\renewcommand{\mychapterShape}{display}
\renewcommand{\mychapterFormat}{
\vspace{\stretch{7}}\normalfont\onehalfspacing\centering\large
}
\renewcommand{\mychapterBefore}{
\thispagestyle{empty}%
\vspace{0.5em}%
}
\renewcommand{\mychapterAfter}{
\vspace{\stretch{10}}\cleardoublepage\thispagestyle{empty}\singlespacing
}
\renewcommand{\mychapterLabel}{\chaptertitlename~\thechapter}
}
{} % end chapterpage envt

\titleformat{\chapter}[\mychapterShape]%
{\mychapterFormat}{\mychapterLabel}{1em}%
{\mychapterBefore}[\mychapterAfter]%

\begin{document}

\chapter{Foo}
\lipsum[1-3]

\begin{chapterpage}
\chapter{Bar}
\end{chapterpage}
\lipsum[1-3]

\end{document}

-

I would define two chapter styles

\documentclass[11pt]{scrreprt}

\usepackage{lipsum}
\usepackage{titlesec}

\newcommand{\mainchapterstyle}{%
\titleformat{\chapter}[display]
{\vspace{\stretch{7}}\normalfont\onehalfspacing\centering\large}
{\chaptertitlename~\thechapter}
{1em}
{\thispagestyle{empty}\vspace{0.5em}}
[\vspace{\stretch{10}}\cleardoublepage
\thispagestyle{empty}\singlespacing]}

\newcommand{\appchapterstyle}{%
\titleformat{\chapter}[hang]
{}
{\thechapter}
{1em}
{\raggedright}
[\normalsize\vspace*{.8\baselineskip}\titlerule]}

\begin{document}

\mainchapterstyle
\chapter{Bar}
\lipsum[1-3]

\appendix
\appchapterstyle
\chapter{Foo}
\lipsum[1-3]

\end{document}

-
That works… thanks! –  Thomas Julou Apr 24 '11 at 21:00
@Thomas: it's common to mark the answer as accepted, or, if you want to wait for possible other answers, to at least mark it as useful. –  egreg Apr 24 '11 at 21:06
Done! Please accept my newbie apologizes :) –  Thomas Julou Apr 25 '11 at 8:56