Document ClassesAdd a period after a heading's numbering in the memoir class

Information and discussion about specific document classes and how to create your own document classes.
charlax
Posts: 11
Joined: Mon Apr 20, 2009 9:16 am

Add a period after a heading's numbering in the memoir class

Post by charlax »

Hi everybody,

I am using the memoir class, I don't know if this is right so I can change if your solution requires it. I want to add a period after a heading's numbering. Instead of:

A Chapter one

I would like to get:

A. Chapter one

I tried:

Code: Select all

\chapterstyle{section}
\renewcommand{\afterchapternum}{.\space}
But I get an extra space after the heading numbering:

A . Chapter one

Do you have an idea?

In the mean time, I would the same appearance in the TOC. Even with my modification, I still get the following line in the TOC:

A Chapter one........................................... 1

Thank you very much,

Charles

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Stefan Kottwitz
Site Admin
Posts: 10323
Joined: Mon Mar 10, 2008 9:44 pm

Add a period after a heading's numbering in the memoir class

Post by Stefan Kottwitz »

Hi Charles,

welcome to the board!
Instead of redefining \afterchapnum you could redefine \thechapter:

Code: Select all

\renewcommand*\thechapter{\Alph{chapter}.}
Stefan
LaTeX.org admin
charlax
Posts: 11
Joined: Mon Apr 20, 2009 9:16 am

Add a period after a heading's numbering in the memoir class

Post by charlax »

Hi Stefan,

Thank you for your answer, but now I get this in the header:

A.. Chapter one

Isn't there way to set the period after the number only in headings (and TOC)?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10323
Joined: Mon Mar 10, 2008 9:44 pm

Add a period after a heading's numbering in the memoir class

Post by Stefan Kottwitz »

charlax wrote: Isn't there way to set the period after the number only in headings (and TOC)?
For sure there is, but because there are many possible settings with the memoir class just show us your settings (preamble or minimal working example), the behavior above is not default.

Stefan
LaTeX.org admin
charlax
Posts: 11
Joined: Mon Apr 20, 2009 9:16 am

Add a period after a heading's numbering in the memoir class

Post by charlax »

Here is my preamble :

Code: Select all

\documentclass[10pt,a4paper,extrafontsizes,twoside]{memoir} 

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}

\usepackage{calayout}
Here is my calayout.sty:

Code: Select all

%% calayout.sty 	\copyright Charles-Axel Dein 2009
%% Licensed under CC BY-SA
\ProvidesPackage{calayout}[2009/04/20]

% PACKAGES
\usepackage{cacommands}
\usepackage{indentfirst} % ident on first line of par, even after headings
\usepackage{url}
\usepackage{hyperref} % create links in the document
\usepackage{textcomp}
\usepackage[T1]{fontenc}
\usepackage{graphicx} % to insert images


% LAYOUT

\settrimmedsize{297mm}{210mm}{*} 
\setlength{\trimtop}{0pt} 
\setlength{\trimedge}{\stockwidth} 
\addtolength{\trimedge}{-\paperwidth} 
\settypeblocksize{634pt}{448.13pt}{*} 
\setulmargins{4cm}{*}{*} 
\setlrmargins{*}{*}{1.5} 
\setmarginnotes{17pt}{51pt}{\onelineskip} 
\setheadfoot{\onelineskip}{2\onelineskip} 
\setheaderspaces{*}{2\onelineskip}{*} 
\checkandfixthelayout 

\renewcommand{\rmdefault}{bch}

\setsecnumdepth{paragraph} % Numbering down to...

%%% HEADERS & FOOTERS
\pagestyle{ruled} % try also: empty , plain , headings , ruled , Ruled , companion

\chapterstyle{section}
\renewcommand*\thechapter{\Alph{chapter}.}
\renewcommand{\thesection}{\Roman{section}}
\renewcommand{\thesubsection}{\arabic{subsection}}
\renewcommand{\thesubsubsection}{\arabic{subsection}.\arabic{subsubsection}}
\renewcommand{\theparagraph}{\arabic{subsection}.\arabic{subsubsection}.\arabic{paragraph}}

% TOC
\setcounter{tocdepth}{3} % TOC down to...
\setlength{\cftbeforesectionskip}{5pt}

% Abstract
\renewcommand{\abstractnamefont}{\chaptitlefont}
\renewcommand{\abstractname}{Executive Summary}
Here is my cacommands.sty:

Code: Select all

%% cacommands.sty 	copyright Charles-Axel Dein 2009
%% Licensed under CC BY-SA
\ProvidesPackage{cacommands}[2009/04/20]

\usepackage{hyperref}

\newcommand{\email}[1]{\href{mailto:#1}{\nolinkurl{#1}}}

% Une commande sembleble à \rlap ou \llap, mais centrant son argument
\def\clap#1{\hbox to 0pt{\hss #1\hss}}%
% Une commande centrant son contenu (à utiliser en mode vertical)
\def\ligne#1{%
  \hbox to \hsize{%
    \vbox{\centering #1}}}%
% Une comande qui met son premier argument à gauche, le second au 
% milieu et le dernier à droite, la première ligne ce chacune de ces
% trois boites coïncidant
\def\haut#1#2#3{%
  \hbox to \hsize{%
    \rlap{\vtop{\raggedright #1}}%
    \hss
    \clap{\vtop{\centering #2}}%
    \hss
    \llap{\vtop{\raggedleft #3}}}}%
% Idem, mais cette fois-ci, c'est la dernière ligne
\def\bas#1#2#3{%
  \hbox to \hsize{%
    \rlap{\vbox{\raggedright #1}}%
    \hss
    \clap{\vbox{\centering #2}}%
    \hss
    \llap{\vbox{\raggedleft #3}}}}%
% La commande \maketitle
\def\maketitlememoire{%

\calccentering{\unitlength} 
\begin{adjustwidth*}{\unitlength}{-\unitlength} 
  %\thispagestyle{empty}\vbox to \vsize{%
    \haut{}{\@blurb}{}
    \vfill
    \ligne{\Huge \@title}
    \vspace{10mm}
    \ligne{\Large \@author}
    \vspace{1mm}\ligne{\small \email{\@emailaddress}}
    \vspace{1cm}
    \vfill
    \vfill
    \bas{}{\@location, \@date}{}
  %  }%
    \end{adjustwidth*} 

  \cleardoublepage
  }
% Les commandes permettant de définir la date, le lieu, etc.
\def\date#1{\def\@date{#1}}
\def\author#1{\def\@author{#1}}
\def\title#1{\def\@title{#1}}
\def\location#1{\def\@location{#1}}
\def\blurb#1{\def\@blurb{#1}}
\def\emailaddress#1{\def\@emailaddress{#1}}
% Valeurs par défaut
\date{\today}
\author{}
\title{}
\location{}
\blurb{}
\emailaddress{no email address}
I'm looking at what could change the default behaviour...
User avatar
Stefan Kottwitz
Site Admin
Posts: 10323
Joined: Mon Mar 10, 2008 9:44 pm

Add a period after a heading's numbering in the memoir class

Post by Stefan Kottwitz »

With this minimal example I'm getting the period correctly without changes:

Code: Select all

\documentclass[10pt,a4paper,extrafontsizes,twoside]{memoir}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}

\usepackage{calayout}

\begin{document}
\tableofcontents
\chapter{Test}
text
\end{document}
Perhaps you don't need to change anything, because it's done in those style files?

Stefan
LaTeX.org admin
charlax
Posts: 11
Joined: Mon Apr 20, 2009 9:16 am

Add a period after a heading's numbering in the memoir class

Post by charlax »

Yes, but then when you begin a new odd page:

Code: Select all

\documentclass[10pt,a4paper,extrafontsizes,twoside]{memoir}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}

\usepackage{calayout}

\begin{document}
\tableofcontents
\chapter{Test}
text
\clearpage

Test
\end{document}
You get an extra period in the header.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10323
Joined: Mon Mar 10, 2008 9:44 pm

Add a period after a heading's numbering in the memoir class

Post by Stefan Kottwitz »

Ah, ok, in that case let's redefine the \chaptermark macro:

Code: Select all

\makeatletter
\renewcommand*\chaptermark[1]{%
  \markboth{%
    \ifnum \c@secnumdepth >\m@ne
      \if@mainmatter
        \thechapter\ %
      \fi
    \fi
    #1}{}%
}
\makeatother
The original \chaptermark has a period after \thechapter inside its definition.

Stefan
LaTeX.org admin
charlax
Posts: 11
Joined: Mon Apr 20, 2009 9:16 am

Add a period after a heading's numbering in the memoir class

Post by charlax »

Thanks Stefan, it's working now. I'm a beginner, but could we consider this behaviour a bug in the memoir class? Wouldn't it be more logical to have the numbering definition (including the period) in only one place?

I'm now trying to have the same with section, I try to replicate your code but I get nothing in the header where the section title should appear...

Here is what I tried:

Code: Select all

\renewcommand*\chaptermark[1]{%
  \markboth{%
    \ifnum \c@secnumdepth >\m@ne
      \if@mainmatter
        \thechapter\ %
      \fi
    \fi
    #1}{}%
}
%%% THE SAME FOR SECTION
\renewcommand*\sectionmark[1]{%
  \markboth{%
    \ifnum \c@secnumdepth >\m@ne
      \if@mainmatter
        \thesection\ %
      \fi
    \fi
    #1}{}%
}
User avatar
Stefan Kottwitz
Site Admin
Posts: 10323
Joined: Mon Mar 10, 2008 9:44 pm

Add a period after a heading's numbering in the memoir class

Post by Stefan Kottwitz »

I'm considering the period inside \chaptermark as bad code too. Regarding \sectionmark, its original definition with ruled pagestyle (inside \@ruledmarks of memoir.cls) is

Code: Select all

\def\sectionmark##1{\markright{##1}}
and you could redefine it in your document this way:

Code: Select all

\renewcommand*\sectionmark[1]{\markright{\thesection\ #1}}
Stefan
LaTeX.org admin
Post Reply