Text FormattingDecreased Font Size and small Capitals in Header

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
kgolod
Posts: 4
Joined: Tue Sep 20, 2011 2:52 am

Decreased Font Size and small Capitals in Header

Post by kgolod »

Hello everyone,

I was wondering if anyone could help me with a chapter heading formatting problem.

I have the following code which inserts the name of the chapter at the header of every page:

Code: Select all

\def\ps@headings{\let\@mkboth\markboth
\def\@oddfoot{}\def\@evenfoot{}%     No footer.
\def\@oddhead{{\slshape \rightmark}\hfil \rmfamily\thepage}%   The Header.
\def\chaptermark##1{\markright {\textsc{\small \ifnum \c@secnumdepth >\m@ne
  \@chapapp\ \thechapter. \ \fi ##1}}}}
I would like to reduce the font size of the header. When I try adding \small before or after \textsc, very odd numbers are displayed along with the title in the header.

For example, before code modification the header displays:

Chapter 6. Investigation of Deposited Samples

while after the modification, it displays:

.9513.6Chapter 6. Investigation of Thermally Poled Multilayered Structures

I would appreciate any advice!

Thank you,
K
Last edited by kgolod on Thu Sep 22, 2011 12:54 pm, edited 1 time in total.

Recommended reading 2024:

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

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

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Decreased Font Size and small Capitals in Header

Post by localghost »

It seems that you never heard of packages like fancyhdr or titlesec. So you don't have to think so complicated. These packages make life easier when it comes to setting up page styles.

The fancyhdr example.

Code: Select all

\documentclass[11pt,twoside,english]{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{fancyhdr}
\usepackage{blindtext}

\fancyhf{}
\fancyhead[RE]{\small\scshape\nouppercase{\leftmark}}
\fancyhead[LO]{\small\scshape\nouppercase{\rightmark}}
\fancyhead[LE,RO]{\small\thepage}
\pagestyle{fancy}

\begin{document}
  \blinddocument
\end{document}
The titlesec example.

Code: Select all

\documentclass[11pt,twoside,english]{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[pagestyles,raggedright]{titlesec}
\usepackage{blindtext}

\newpagestyle{main}[\small\scshape]{%
  \headrule
  \sethead[\thepage][][\chaptertitlename\enspace\thechapter.\quad\chaptertitle]{\thesection.\quad\sectiontitle}{}{\thepage}
}
\pagestyle{main}

\begin{document}
  \blinddocument
\end{document}
The final choice is up to you. Note that the titlesec package has much more capabilities than fancyhdr, which is only for setting up page styles. For further details consult the manual of your preferred package.

Note that in both examples the blindtext package is only used to create dummy text, thus is not part of the solution. You might also drop the babel package and its global language option.


Best regards and welcome to the board
Thorsten
kgolod
Posts: 4
Joined: Tue Sep 20, 2011 2:52 am

Re: Decreased Font Size and small Capitals in Header

Post by kgolod »

Hello,

Thanks very much for your reply! I have worked with fancyhdr before, but in this case I just have to modify an existing document. I cannot use these packages since they also change the layout of the document, but it must remain the same...

The only think I want to change is to reduce the font of the chapter headings on every page (they must be displayed in small capitals, but some are too long).

Is there a reason why replacing \textsc with \small\textsc doesn't work, and instead gives the odd numbers the I've shown above? Where are the numbers coming from?

I would greatly appreciate any help!!

Thank you,
K
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Decreased Font Size and small Capitals in Header

Post by localghost »

kgolod wrote:[…] I cannot use these packages since they also change the layout of the document, but it must remain the same. […]
These packages do no modifications to the page dimensions. The layout of your document will be the same as without them. So it's not comprehensible to me why you refuse to use them.

Unfortunately you didn't say anything about the class you are using or your template is based on. So I worked out an example for the »report« class.

It works with a modified definition of the »headings« page style as you want it. The original definition is taken from the class. Put the code block between \makeatletter and \makeatother into your class template (without those two commands). If you do the redefinition in the preamble of your document, add it as shown in the below code.

Code: Select all

\documentclass[11pt,twoside,english]{report}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{blindtext}

\makeatletter
\if@twoside
  \def\ps@headings{%
      \let\@oddfoot\@empty\let\@evenfoot\@empty       % No footer
      \def\@evenhead{\small\thepage\hfil\leftmark}%   % Header on even pages small
      \def\@oddhead{\small\rightmark\hfil\thepage}%   % Header on  odd pages small
      \let\@mkboth\markboth
    \def\chaptermark##1{%
      \markboth{\scshape%                             % Chapters in Header capitalized
        \ifnum \c@secnumdepth >\m@ne
            \@chapapp\ \thechapter. \ %
        \fi
        ##1}{}}%
    \def\sectionmark##1{%
      \markright{\scshape%                            % Sections in Header capitalized
        \ifnum \c@secnumdepth >\z@
          \thesection. \ %
        \fi
        ##1}}}
\else
  \def\ps@headings{%
    \let\@oddfoot\@empty
    \def\@oddhead{\small\rightmark\hfil\thepage}%      % Header font small
    \let\@mkboth\markboth
    \def\chaptermark##1{%
      \markright{\scshape%                             % Chapters in Header capitalized
        \ifnum \c@secnumdepth >\m@ne
            \@chapapp\ \thechapter. \ %
        \fi
        ##1}}}
\fi
\makeatother
\pagestyle{headings}

\begin{document}
  \blinddocument
\end{document}
As you can see, you can have both a smaller font size and small capitals in the header. Therefore the font size of the complete heading was decreased (see comments in code). The capitalization for the chapters (and sections in a two-sided document) goes into the definition of the \chaptermark command or \sectionmark command, respectively (see comments in code).

The packages babel (with its global language option) and blindtext are not part of the solution. There were only used to create the dummy document.
kgolod
Posts: 4
Joined: Tue Sep 20, 2011 2:52 am

Re: Decreased Font Size and small Capitals in Header

Post by kgolod »

Thank you so much, localghost! The code worked beautifully!

And I have a quick follow up question, if I may...

Is there a way to add a horizontal line under the header? I tried doing it using \headrule in the titlesec package, as you've suggested, but I just cannot get both the header text and the line working together (only one of them...).

I am working with a custom document class for theses, and it is a modified version of the report document class.

Again, thank you so much for your help! I greatly appreciate it.

K
kgolod
Posts: 4
Joined: Tue Sep 20, 2011 2:52 am

Re: Decreased Font Size and small Capitals in Header

Post by kgolod »

Actually, I just figured it out. As per your original suggestion, it ended up to be very easy with the titlesec package.

Thank you again for your help!

K
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Decreased Font Size and small Capitals in Header

Post by localghost »

kgolod wrote:[…] Is there a way to add a horizontal line under the header? […]
Yes, indeed. My last example with an additional horizontal rule.

Code: Select all

\documentclass[11pt,twoside,english]{report}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{blindtext}

\makeatletter
\if@twoside
  \def\ps@headings{%
      \let\@oddfoot\@empty\let\@evenfoot\@empty
      \def\@evenhead{\small\thepage\hfil\leftmark\strut\vadjust{\vskip .1ex\hrule}}%
      \def\@oddhead{\small\rightmark\hfil\thepage\strut\vadjust{\vskip .1ex\hrule}}%
      \let\@mkboth\markboth
    \def\chaptermark##1{%
      \markboth{\scshape%
        \ifnum \c@secnumdepth >\m@ne
            \@chapapp\ \thechapter. \ %
        \fi
        ##1}{}}%
    \def\sectionmark##1{%
      \markright{\scshape%
        \ifnum \c@secnumdepth >\z@
          \thesection. \ %
        \fi
        ##1}}}
\else
  \def\ps@headings{%
    \let\@oddfoot\@empty
    \def\@oddhead{\small\rightmark\hfil\thepage\strut\vadjust{\vskip .1ex\hrule}}%
    \let\@mkboth\markboth
    \def\chaptermark##1{%
      \markright{\scshape%
        \ifnum \c@secnumdepth >\m@ne
            \@chapapp\ \thechapter. \ %
        \fi
        ##1}}}
\fi
\makeatother
\pagestyle{headings}

\begin{document}
  \blinddocument
\end{document}
But now that you got it working with one of the suggested packages, this is only for the gallery.
Post Reply