Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

\frontmatter may include

  • Table of Contents
  • List of Figures
  • List of Tables
  • Preference
  • and other parts

Now, I want to set up the pagestyle of pages range from the tag \frontmatter to the tag \mainmatter be plain. that is said all of \tableofcontents,\listoffigures,\listoftables,preference parts should not contain page number, page head, page foot. I dont want to set them one by one with \thispagestyle. the \pagestyle of all pages in \mainmatterpart should be fancy.

I think if I can deal with \frontmatter, I also can apply the method to \mainmatter to \backmatter.

Am I right?

share|improve this question
    
This is not clear (to me). Do you want to change the pagestyle so that different pagestyles are used in \frontmatter, \mainmatter, and \backmatter? If so, why can't you define three different page styles? –  jon May 2 '12 at 15:47
    
@jon I want to set all pages[\frontmatter, \mainmatter] no page number, no page head,no page foot –  pythonee May 2 '12 at 15:49
1  
Why don't you put pagestyle{empty} in your preamble? Also you have to redefine page style plain to be empty to have similar effect on chapter pages too. –  Harish Kumar May 2 '12 at 16:13
    
pythonee -- @HarishKumar has the right idea. (Sorry, I misunderstood your goals.) –  jon May 2 '12 at 16:24
2  
Your acceptance rate is very low. Please consider accepting answers to your previous questions by using the green check mark –  cmhughes May 2 '12 at 17:24

2 Answers 2

up vote 2 down vote accepted

According to the revised version of the question, you (may) want:

\documentclass{book}                                                        
\usepackage{lipsum, fancyhdr}                                               

\begin{document}                                                            

\pagestyle{empty}                                                           
% pagestyle{plain}                                                          
\frontmatter                                                                

\lipsum[1]                                                                  

\mainmatter                                                                 
\pagestyle{fancy}                                                           

\chapter{1}                                                                 
\section{1}                                                                 
\lipsum                                                                     


\backmatter                                                                 
\pagestyle{empty}                                                           
%\pagestyle{plain}                                                          

\lipsum[1]                                                                  

\end{document} 

Edit: If you want to wrap these changes into a .sty file, you could do this:

\NeedsTeXFormat{LaTeX2e}[1994/06/01]                                        
\ProvidesPackage{myfile}                                                    
  [2012/05/02 v0.01 modifications to the *matter commands]                  


\RequirePackage{etoolbox}                                                   
\appto\frontmatter{\pagestyle{empty}}                                       
\appto\mainmatter{\pagestyle{fancy}}                                        
\appto\backmatter{\pagestyle{empty}}                                        


\endinput

Name this file myfile.sty and load it in the preamble of your document with the usual \usepackage{myfile}. Note that the name of this file is arbitrary, and the first three lines as well as the last line are not strictly needed.

However, I do not really see the advantage of hard-wiring such changes into the \*matter commands, even if I agree with the idea that generic formatting changes are often better put into a .sty file for complex documents.

share|improve this answer
    
How can I define this on style file? –  pythonee May 3 '12 at 2:14
    
You could, I suppose, patch the \*matter commands, but you still need to use the actual \*matter commands in your document: how would TeX know otherwise that it is entering a new part of the document? –  jon May 3 '12 at 2:19
    
thank you for your reply and patience. But I'm a beginner of tex. I dont know how to patch the *matter in style file. Can you give me more details or document may help. –  pythonee May 3 '12 at 2:36
    
@pythonee -- see the revised answer. –  jon May 3 '12 at 3:45
    
Is there any way to do this without the etoolbox? I'm using KOMA-Script –  Mario S. E. Aug 3 at 2:23

Following will make the changes in the document as your question demands.

\documentclass[twoside,openany]{book}
\usepackage{lipsum}
\usepackage{fancyhdr}

%%-define header and footer for main matter
\fancypagestyle{headings}{%
  \fancyhf{}   % Clear all headers and footers first
  %% Right headers on odd pages
  \fancyhead[RO,LE]{My right heading}%you can use \leftmark or right mark as per need.
  \fancyhead[LO,RE]{My left heading}%you can use \leftmark or right mark as per need.
  \fancyhead[C]{Center} 
  \fancyfoot[RO,LE]{\thepage}
  \fancyfoot[LO,RE]{Me}
  \renewcommand{\headrulewidth}{0pt}
  \renewcommand{\footrulewidth}{0pt}
}

%% -------define pagestyle {plain} to be {empty} (without using fancyhdr)
 \makeatletter
 \let\ps@plain\ps@empty
 \makeatother
%----------------------------------------------
\title{My title}
\author{Me}
%----------------------------------------------
\begin{document}
\maketitle
%----------------------------------------------
\pagestyle{empty} % declare all pages to have empty header and footer.
%----------------------------------------------
\frontmatter

\tableofcontents
\listoffigures
\listoftables

\cleardoublepage
%----------------------------------------------
\fancypagestyle{plain}{%
  %% Clear all headers and footers
  \fancyhf{}
  \fancyfoot[C]{\thepage}
  \renewcommand{\headrulewidth}{0pt}
  \renewcommand{\footrulewidth}{0pt}
}
%----------------------------------------------
\pagestyle{headings}

\mainmatter


\part{Hello World}
\clearpage
\chapter{Test one}
\lipsum[1-5]
\section{My section one}
\lipsum[1]
\part{Goodbye World}
\chapter{Test two}
\lipsum[1]
\section{My section two}
\lipsum[1]
%----------------------------------------------
\backmatter

%%---Redefine plain page style now using fancyhdr for a change
\fancypagestyle{plain}{%
  %% Clear all headers and footers
  \fancyhf{}
  \fancyfoot[C]{\thepage}
  \renewcommand{\headrulewidth}{0pt}
  \renewcommand{\footrulewidth}{0pt}
}
%  \makeatletter
%  \let\ps@plain\ps@empty
%  \makeatother
\pagestyle{empty}
%----------------------------------------------
\chapter{Test one}
\lipsum[1]
%----------------------------------------------
\end{document}
share|improve this answer
    
I'd add a section for \backmatter just to be complete. –  jon May 2 '12 at 23:06
    
@jon: Added, but the answer is, I think, still to be modified as I have lot of confusions remaining. –  Harish Kumar May 2 '12 at 23:10
    
No doubt! The question still needs to be clarified. –  jon May 2 '12 at 23:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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