LaTeX forum ⇒ 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

Postby charlax » Mon Apr 20, 2009 9:29 am

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:

  1. \chapterstyle{section}
  2. \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

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
Stefan Kottwitz
Site Admin
Posts: 7803
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Mon Apr 20, 2009 2:32 pm

Hi Charles,

welcome to the board!
Instead of redefining \afterchapnum you could redefine \thechapter:
  1. \renewcommand*\thechapter{\Alph{chapter}.}

Stefan
Site admin

Link:
BBcode:
HTML:
Hide post links
Show post links

charlax
Posts: 11
Joined: Mon Apr 20, 2009 9:16 am

Postby charlax » Mon Apr 20, 2009 3:17 pm

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

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
Stefan Kottwitz
Site Admin
Posts: 7803
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Mon Apr 20, 2009 3:39 pm

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
Site admin

Link:
BBcode:
HTML:
Hide post links
Show post links

charlax
Posts: 11
Joined: Mon Apr 20, 2009 9:16 am

Postby charlax » Mon Apr 20, 2009 3:45 pm

Here is my preamble :
  1. \documentclass[10pt,a4paper,extrafontsizes,twoside]{memoir}
  2.  
  3. \usepackage[english]{babel}
  4. \usepackage[utf8]{inputenc}
  5.  
  6. \usepackage{calayout}


Here is my calayout.sty:
  1. %% calayout.sty \copyright Charles-Axel Dein 2009
  2. %% Licensed under CC BY-SA
  3. \ProvidesPackage{calayout}[2009/04/20]
  4.  
  5. % PACKAGES
  6. \usepackage{cacommands}
  7. \usepackage{indentfirst} % ident on first line of par, even after headings
  8. \usepackage{url}
  9. \usepackage{hyperref} % create links in the document
  10. \usepackage{textcomp}
  11. \usepackage[T1]{fontenc}
  12. \usepackage{graphicx} % to insert images
  13.  
  14.  
  15. % LAYOUT
  16.  
  17. \settrimmedsize{297mm}{210mm}{*}
  18. \setlength{\trimtop}{0pt}
  19. \setlength{\trimedge}{\stockwidth}
  20. \addtolength{\trimedge}{-\paperwidth}
  21. \settypeblocksize{634pt}{448.13pt}{*}
  22. \setulmargins{4cm}{*}{*}
  23. \setlrmargins{*}{*}{1.5}
  24. \setmarginnotes{17pt}{51pt}{\onelineskip}
  25. \setheadfoot{\onelineskip}{2\onelineskip}
  26. \setheaderspaces{*}{2\onelineskip}{*}
  27. \checkandfixthelayout
  28.  
  29. \renewcommand{\rmdefault}{bch}
  30.  
  31. \setsecnumdepth{paragraph} % Numbering down to...
  32.  
  33. %%% HEADERS & FOOTERS
  34. \pagestyle{ruled} % try also: empty , plain , headings , ruled , Ruled , companion
  35.  
  36. \chapterstyle{section}
  37. \renewcommand*\thechapter{\Alph{chapter}.}
  38. \renewcommand{\thesection}{\Roman{section}}
  39. \renewcommand{\thesubsection}{\arabic{subsection}}
  40. \renewcommand{\thesubsubsection}{\arabic{subsection}.\arabic{subsubsection}}
  41. \renewcommand{\theparagraph}{\arabic{subsection}.\arabic{subsubsection}.\arabic{paragraph}}
  42.  
  43. % TOC
  44. \setcounter{tocdepth}{3} % TOC down to...
  45. \setlength{\cftbeforesectionskip}{5pt}
  46.  
  47. % Abstract
  48. \renewcommand{\abstractnamefont}{\chaptitlefont}
  49. \renewcommand{\abstractname}{Executive Summary}


Here is my cacommands.sty:
  1. %% cacommands.sty copyright Charles-Axel Dein 2009
  2. %% Licensed under CC BY-SA
  3. \ProvidesPackage{cacommands}[2009/04/20]
  4.  
  5. \usepackage{hyperref}
  6.  
  7. \newcommand{\email}[1]{\href{mailto:#1}{\nolinkurl{#1}}}
  8.  
  9. % Une commande sembleble à \rlap ou \llap, mais centrant son argument
  10. \def\clap#1{\hbox to 0pt{\hss #1\hss}}%
  11. % Une commande centrant son contenu (à utiliser en mode vertical)
  12. \def\ligne#1{%
  13. \hbox to \hsize{%
  14. \vbox{\centering #1}}}%
  15. % Une comande qui met son premier argument à gauche, le second au
  16. % milieu et le dernier à droite, la première ligne ce chacune de ces
  17. % trois boites coïncidant
  18. \def\haut#1#2#3{%
  19. \hbox to \hsize{%
  20. \rlap{\vtop{\raggedright #1}}%
  21. \hss
  22. \clap{\vtop{\centering #2}}%
  23. \hss
  24. \llap{\vtop{\raggedleft #3}}}}%
  25. % Idem, mais cette fois-ci, c'est la dernière ligne
  26. \def\bas#1#2#3{%
  27. \hbox to \hsize{%
  28. \rlap{\vbox{\raggedright #1}}%
  29. \hss
  30. \clap{\vbox{\centering #2}}%
  31. \hss
  32. \llap{\vbox{\raggedleft #3}}}}%
  33. % La commande \maketitle
  34. \def\maketitlememoire{%
  35.  
  36. \calccentering{\unitlength}
  37. \begin{adjustwidth*}{\unitlength}{-\unitlength}
  38. %\thispagestyle{empty}\vbox to \vsize{%
  39. \haut{}{\@blurb}{}
  40. \vfill
  41. \ligne{\Huge \@title}
  42. \vspace{10mm}
  43. \ligne{\Large \@author}
  44. \vspace{1mm}\ligne{\small \email{\@emailaddress}}
  45. \vspace{1cm}
  46. \vfill
  47. \vfill
  48. \bas{}{\@location, \@date}{}
  49. % }%
  50. \end{adjustwidth*}
  51.  
  52. \cleardoublepage
  53. }
  54. % Les commandes permettant de définir la date, le lieu, etc.
  55. \def\date#1{\def\@date{#1}}
  56. \def\author#1{\def\@author{#1}}
  57. \def\title#1{\def\@title{#1}}
  58. \def\location#1{\def\@location{#1}}
  59. \def\blurb#1{\def\@blurb{#1}}
  60. \def\emailaddress#1{\def\@emailaddress{#1}}
  61. % Valeurs par défaut
  62. \date{\today}
  63. \author{}
  64. \title{}
  65. \location{}
  66. \blurb{}
  67. \emailaddress{no email address}


I'm looking at what could change the default behaviour...

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
Stefan Kottwitz
Site Admin
Posts: 7803
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Mon Apr 20, 2009 3:51 pm

With this minimal example I'm getting the period correctly without changes:
  1. \documentclass[10pt,a4paper,extrafontsizes,twoside]{memoir}
  2. \usepackage[english]{babel}
  3. \usepackage[utf8]{inputenc}
  4.  
  5. \usepackage{calayout}
  6.  
  7. \begin{document}
  8. \tableofcontents
  9. \chapter{Test}
  10. text
  11. \end{document}

Perhaps you don't need to change anything, because it's done in those style files?

Stefan
Site admin

Link:
BBcode:
HTML:
Hide post links
Show post links

charlax
Posts: 11
Joined: Mon Apr 20, 2009 9:16 am

Postby charlax » Mon Apr 20, 2009 4:02 pm

Yes, but then when you begin a new odd page:
  1. \documentclass[10pt,a4paper,extrafontsizes,twoside]{memoir}
  2. \usepackage[english]{babel}
  3. \usepackage[utf8]{inputenc}
  4.  
  5. \usepackage{calayout}
  6.  
  7. \begin{document}
  8. \tableofcontents
  9. \chapter{Test}
  10. text
  11. \clearpage
  12.  
  13. Test
  14. \end{document}


You get an extra period in the header.

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
Stefan Kottwitz
Site Admin
Posts: 7803
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Mon Apr 20, 2009 4:19 pm

Ah, ok, in that case let's redefine the \chaptermark macro:
  1. \makeatletter
  2. \renewcommand*\chaptermark[1]{%
  3. \markboth{%
  4. \ifnum \c@secnumdepth >\m@ne
  5. \if@mainmatter
  6. \thechapter\ %
  7. \fi
  8. \fi
  9. #1}{}%
  10. }
  11. \makeatother

The original \chaptermark has a period after \thechapter inside its definition.

Stefan
Site admin

Link:
BBcode:
HTML:
Hide post links
Show post links

charlax
Posts: 11
Joined: Mon Apr 20, 2009 9:16 am

Postby charlax » Mon Apr 20, 2009 4:33 pm

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:
  1. \renewcommand*\chaptermark[1]{%
  2. \markboth{%
  3. \ifnum \c@secnumdepth >\m@ne
  4. \if@mainmatter
  5. \thechapter\ %
  6. \fi
  7. \fi
  8. #1}{}%
  9. }
  10. %%% THE SAME FOR SECTION
  11. \renewcommand*\sectionmark[1]{%
  12. \markboth{%
  13. \ifnum \c@secnumdepth >\m@ne
  14. \if@mainmatter
  15. \thesection\ %
  16. \fi
  17. \fi
  18. #1}{}%
  19. }

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
Stefan Kottwitz
Site Admin
Posts: 7803
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Mon Apr 20, 2009 4:43 pm

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
  1. \def\sectionmark##1{\markright{##1}}

and you could redefine it in your document this way:
  1. \renewcommand*\sectionmark[1]{\markright{\thesection\ #1}}


Stefan
Site admin

Link:
BBcode:
HTML:
Hide post links
Show post links


Return to “Document Classes”

Who is online

Users browsing this forum: Google [Bot] and 2 guests