2

I have a problem regarding the 'part'counter. I have an MWE (i dont know if its satisfactory):

\documentclass{memoir}

\usepackage[a4paper, total={6.5in, 9in}]{geometry}
\usepackage[danish]{babel}
\usepackage{colortbl}
\usepackage{appendix}
\usepackage{titlesec}

    \addto\captionsdanish{
        \renewcommand*\appendixname{Bilag}
        \renewcommand\contentsname{Indholdsfortegnelse}
        \renewcommand\partname{Fase}
        \renewcommand\appendixpagename{Bilag}
        \renewcommand\appendixtocname{Bilag}
        \renewcommand\cftchaptername{Kapitel~}
        \renewcommand\cftappendixname{\appendixname~}
    }


    \renewcommand{\thepart}{Fase \arabic{part}}
    \titleformat{\part}
        [display]

    {\centering\fontfamily{pbk}\fontseries{m}\fontshape{n}\selectfont\Huge}
        {\MakeUppercase{\thepart}}
        {1pc}
        {\titlerule[2pt]\vspace{1pc}\huge\MakeUppercase}

    \makeatletter
    \@addtoreset{chapter}{part}
    \makeatother

    \definecolor{numbercolor}{gray}{0.7}
    \newif\ifchapternonum

    \makechapterstyle{jenor}{
        \renewcommand\beforechapskip{0pt}
        \renewcommand\printchaptername{}
        \renewcommand\printchapternum{}
        \renewcommand\printchapternonum{\chapternonumtrue}
        \renewcommand\chaptitlefont{
            \fontfamily{pbk}
            \fontseries{db}
            \fontshape{n}
            \fontsize{25}{35}
            \selectfont
            \raggedright
        }

        \renewcommand\chapnumfont{
            \fontfamily{pbk}
            \fontseries{m}
            \fontshape{n}
            \fontsize{1in}{0in}
            \selectfont\color{numbercolor}
        }
        \renewcommand\printchaptertitle[1]{%
            \noindent
        \ifchapternonum
            \begin{tabularx}{\textwidth}{X}
                {\let\\\newline\chaptitlefont ##1\par}
            \end{tabularx}
            \par\vskip-2.5mm\hrule
        \else
            \begin{tabularx}{\textwidth}{Xl}
                {\parbox[b]{\linewidth}{\chaptitlefont ##1}} & 
        \raisebox{-15pt}{\chapnumfont \arabic{part}.\thechapter}
        \end{tabularx}
        \par\vskip2mm\hrule
        \fi
    \vspace{-20pt}
    }

}

\chapterstyle{jenor}    

\begin{document}

\part{first part}
\chapter{first chapter in first part}
\chapter{second chapter in first part}


\part{second part}
\chapter{first chapter in second part}
\chapter{second chapter in second part}

\appendix
\chapter{first appendix}
\chapter{second appendix}
\chapter{third appendix}

\end{document}

This is how it looks now:

Part 1 First part

Chapter 1.1 First chapter of first part

Chapter 1.2 Second chapter of first part

Part 2 Second part

Chapter 2.1 First chapter of second part

Chapter 2.2 Second chapter of second part

Appendix 2.A First appendix

Appendix 2.B second appendix

Appendix 2.C third appendix

Now, what I wanted it to do is to not number the 'part' when the Appendix start, so it looks like this:

Part 1 First part

Chapter 1.1 First chapter of first part

Chapter 1.2 Second chapter of first part

Part 2 Second part

Chapter 2.1 First chapter of second part

Chapter 2.2 Second chapter of second part

Appendix A First appendix

Appendix B second appendix

Appendix C third appendix

I have tried resetting the counter, but that just replaces the 2 with a 0

I know that the obvious solution is to not have the \arabic{part} in the if/else argument in the chapter definition, but all the other chapters have to have the part-counter included.

  • Redefine \thechapter to be \arabic{part}.\arabic{chapter}, and use \thechapter in your definition. Then you can redefine it again before the appendix. – Ulrike Fischer Nov 8 at 9:59
3

Here is a way:

\documentclass{memoir}

\usepackage[a4paper, total={6.5in, 9in}]{geometry}
\usepackage[danish]{babel}
\usepackage{colortbl}
\usepackage{appendix}
\usepackage{titlesec}


    \addto\captionsdanish{
        \renewcommand*\appendixname{Bilag}
        \renewcommand\contentsname{Indholdsfortegnelse}
        \renewcommand\partname{Fase}
        \renewcommand\appendixpagename{Bilag}
        \renewcommand\appendixtocname{Bilag}
        \renewcommand\cftchaptername{Kapitel~}
        \renewcommand\cftappendixname{\appendixname~}
    }


    \renewcommand{\thepart}{Fase \arabic{part}}
    \titleformat{\part}
        [display]
    {\centering\fontfamily{pbk}\fontseries{m}\fontshape{n}\selectfont\Huge}
        {\MakeUppercase{\thepart}}
        {1pc}
        {\titlerule[2pt]\vspace{1pc}\huge\MakeUppercase}

    \makeatletter
    \@addtoreset{chapter}{part}
    \makeatother

    \definecolor{numbercolor}{gray}{0.7}
    \newif\ifchapternonum

    \makechapterstyle{jenor}{
        \renewcommand\beforechapskip{0pt}
        \renewcommand\printchaptername{}
        \renewcommand\printchapternum{}
        \renewcommand\printchapternonum{\chapternonumtrue}
        \renewcommand\chaptitlefont{
            \fontfamily{pbk}
            \fontseries{db}
            \fontshape{n}
            \fontsize{25}{35}
            \selectfont
            \raggedright
        }

        \renewcommand\chapnumfont{
            \fontfamily{pbk}
            \fontseries{m}
            \fontshape{n}
            \fontsize{1in}{0in}
            \selectfont\color{numbercolor}
        }
        \renewcommand\printchaptertitle[1]{%
            \noindent
        \ifchapternonum
            \begin{tabularx}{\textwidth}{X}
                {\let\\\newline\chaptitlefont ##1\par}
            \end{tabularx}
            \par\vskip-2.5mm\hrule
        \else
            \begin{tabularx}{\textwidth}{Xl}
                {\parbox[b]{\linewidth}{\chaptitlefont ##1}} & 
        \raisebox{-15pt}{\chapnumfont \mychapter}
        \end{tabularx}
        \par\vskip2mm\hrule
        \fi
    \vspace{-20pt}
    }

}

\newcommand{\mychapter}{\arabic{part}.\thechapter}

\let\oldappendix\appendix

\def\appendix{\renewcommand{\mychapter}{\thechapter}\oldappendix}

\chapterstyle{jenor}    

\begin{document}

\tableofcontents

\part{first part}
\chapter{first chapter in first part}
\chapter{second chapter in first part}


\part{second part}
\chapter{first chapter in second part}
\chapter{second chapter in second part}

\appendix
\chapter{first appendix}
\chapter{second appendix}
\chapter{third appendix}

\end{document}

Actually is very close to @UlrikeFischer's suggestion, but somehow automated.

Explanation:

  1. The line: \newcommand{\mychapter}{\arabic{part}.\thechapter} is just a newcommand that will be used to appear the chapter in the desired format in any case... Initially it is exactly like your definition in your MWE.

  2. The lines:

    \let\oldappendix\appendix

    \def\appendix{\renewcommand{\mychapter}{\thechapter}\oldappendix}

    just adding to the definition of \appendix command the REdefinition of the command \mychapter to include just \thechapter (getting rid of \arabic{part} of its previous definition)... So, every new \chapter command after appendix will show only \thechapter (but from the old definition of \appendix command -already used in our new definition of it- \thechapter is already redefined to \Aplh{chapter} and this is enough for your requirements).

  • 1
    This works! I'm interested in what the different codes do, can you maybe explain the 3 lines you added? – L. Nielsen Nov 8 at 10:23
  • @L.Nielsen ... Added some explanation in the answer ... Feel free to ask whatever you don't understand. – koleygr Nov 8 at 10:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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