Page LayoutLayout automation ?

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
lehibou
Posts: 4
Joined: Wed Sep 29, 2010 10:15 am

Layout automation ?

Post by lehibou »

Hello all,

I've been walking around a lot before posting. But didn't really find my path.
The purpose of the document is Business Plan.
It is a very strict document indeed with codes I have to respect.
I almost have what I want concerning the layout presentation. But :

  • Using makeatletter and makeatother, I can't have my foots and heads with a line. The command \renewcommand\{footrulewidth}{1pt} doesn't works anymore with it.
  • I would have a way to automate the layout for chapters and sections. Currently, I have to copy the code between makeatletter and makeatother + the clear command to make it working
Here is the preamble :

Code: Select all

\documentclass[12pt,a4paper,twoside]{book}
\usepackage[utf8x]{inputenc}
\usepackage{ucs}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{fancyhdr}
\title{The World is mine}
\author{kevin}
\date{\today}
\newcommand{\clearemptydoublepage}{% 
\newpage{\pagestyle{empty}\cleardoublepage}}
and there is the code I have to copy-paste :

Code: Select all

\makeatletter
\renewcommand{\ps@plain}{%
\renewcommand\@oddhead{}%
\renewcommand\@evenhead{}%
\renewcommand\@oddfoot{\hfil\normalsize\textrm{}\hfil}%
\renewcommand\@evenfoot{}%
}
\makeatother

\pagestyle{plain}%
\chapter{example}
%and now I have to apply this line before each layout change :
\clearpage%
Please note that i visited lots of forum, and for the moment, it's the only solution I found to fulfill my need (but there is no "xrulewidth" lines)

Thanks for your help,

LeHibou
Last edited by lehibou on Thu Sep 30, 2010 9:55 am, edited 2 times 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.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

meho_r
Posts: 823
Joined: Tue Aug 07, 2007 5:28 pm

Layout automation ?

Post by meho_r »

1. Use fancyhdr package for headers/footers, it's easier to set up.

2. What do you mean by "automate the layout for chapters and sections"?

If you provide a full working Minimal Working Example (MWE) which clearly shows the issue, and not snippets of code, you'll get the answer much faster.

In the meantime, take a look if this code helps:

Code: Select all

\documentclass[12pt,a4paper,twoside]{book}

\usepackage{fancyhdr}
\usepackage{lipsum}% For generating dummy text

\title{The World is mine}
\author{kevin}
\date{\today}

% The code for clean empty page after \cleardoublepage:
\makeatletter
\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
  \hbox{}
  \thispagestyle{empty}
  \newpage
  \if@twocolumn\hbox{}\newpage\fi\fi\fi}
\makeatother

% Settings headers/footers:
\fancyhf{} % clear all header and footer fields
\fancyhead[LE]{\leftmark}
\fancyhead[RO]{\rightmark}
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
\pagestyle{fancy}

% Redefining plain style:
\fancypagestyle{plain}{%
\fancyhf{} % clear all header and footer fields
\fancyfoot[C]{\thepage} % except the center
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}}


\begin{document}
\maketitle
\chapter{Test chapter}
\section{Test section}
\lipsum[1-9]
\chapter{Another chapter}
\section{Another section}
\lipsum[1-9]
\end{document}
lehibou
Posts: 4
Joined: Wed Sep 29, 2010 10:15 am

Re: Layout automation ?

Post by lehibou »

EDIT : please see my next thread ;)
Last edited by lehibou on Thu Sep 30, 2010 12:14 am, edited 2 times in total.
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Layout automation ?

Post by frabjous »

Please read Meho_r's post more carefully and take his advice.

Please provide a compiliable minimal working example and not just snippets. Even a snippet plus a preamble does not constitute a minimal working example. (See the Post on Avoidable Mistakes.)

If you read the documentation for fancyhdr, you will see that a lot of the stuff you are doing with \makeatletter and \makeatother is not necessary and can be done in a simpler way with its commands.

And finally, I don't understand what it is you are trying to do with regard to "@\chapter"; try to be a little clearer. There's a good chance the fancyhdr documentation will clear this up too, but it not, then you probably have in mind something that can be done with \leftmark or \rightmark or by redefining \chaptermark, but without knowing what you're trying to do, I can't say.
lehibou
Posts: 4
Joined: Wed Sep 29, 2010 10:15 am

Layout automation ?

Post by lehibou »

I will try to do my best. Here is the MWE, concerning the hitch :

Code: Select all

\documentclass[12pt,a4paper,twoside]{book}
\usepackage[utf8x]{inputenc}
\usepackage{fancyhdr}
\title{The World is mine}
\author{kevin}
\date{\today}
\begin{document}
\maketitle
% The code for clean empty page after \cleardoublepage:
\makeatletter
\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
  \hbox{}
  \thispagestyle{empty}
  \newpage
  \if@twocolumn\hbox{}\newpage\fi\fi\fi}
\makeatother

% Settings headers/footers:
\fancyhf{} % clear all header and footer fields
\fancyhead[LE]{\leftmark}
\fancyhead[RO]{\rightmark}
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
\pagestyle{fancy}

% Redefining plain style:
\fancypagestyle{plain}{%
\fancyhf{} % clear all header and footer fields
\fancyfoot[C]{\thepage} % except the center
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{1pt}}

\tableofcontents
\setcounter{page}{-1}
\part{La naissance}
\chapter{La respiration}
\section{Les poumons}
Lorem ipsum 

\end{document}
We can see that the TOC, the Part and Chapter pages have a footnote + separation line.
I just want it on the Chapter pages.

Depending on the answer, the other point is useless or not.

I hope I did it the right way this time,

Thanks,
meho_r
Posts: 823
Joined: Tue Aug 07, 2007 5:28 pm

Layout automation ?

Post by meho_r »

Since you still haven't explain what exactly do you want to achieve, I'll assume the following:

1. "Table of contents" pages: no footer rule, just page number (roman), starting from 1. For this purpose, I created a new page style named "intro".

2. "Part" page: no footer rule and no page number. A redefinition of "part" sectioning unit is necessary to remove page number and footer rule from it. For this purpose I used titlesec package.

3. "Chapter" and normal pages: contain footer rule and page number, but header is empty. For this purpose, I created a new page style named "main".

Here's an example:

Code: Select all

\documentclass[12pt,a4paper,twoside]{book}
\usepackage[utf8x]{inputenc}
\usepackage{fancyhdr}
\usepackage{titlesec}
\usepackage{lipsum}


\title{The World is mine}
\author{kevin}
\date{\today}

% The code for clean empty page after \cleardoublepage:
\makeatletter
\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
  \hbox{}
  \thispagestyle{empty}
  \newpage
  \if@twocolumn\hbox{}\newpage\fi\fi\fi}
\makeatother

% Defining page style for TOC, LOF and LOT (”intro” page style):
\fancypagestyle{intro}{%
\fancyhf{}
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
	\fancypagestyle{plain}{% Redefinition of “plain” page style
	\fancyhf{}
	\fancyfoot[C]{\thepage}
	\renewcommand{\headrulewidth}{0pt}
	\renewcommand{\footrulewidth}{0pt}}
}

% Defining page style for other parts of document (”main” page style):
\fancypagestyle{main}{%
\fancyhf{} % clear all header and footer fields
%\fancyhead[LE]{\leftmark} % uncomment these two lines if you want chapter/section titles in headers
%\fancyhead[RO]{\rightmark}
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{1pt}
	\fancypagestyle{plain}{% Redefinition of “plain” page style
	\fancyhf{}
	\fancyfoot[C]{\thepage}
	\renewcommand{\headrulewidth}{0pt}
	\renewcommand{\footrulewidth}{1pt}}
}

% Redefining part sectioning unit (needed to remove page number and footer rule):
\titleformat{\part}[display]{\filcenter\bfseries\huge\thispagestyle{empty}}{Part~\thepart}{18pt}{}

\begin{document}

\maketitle
\pagestyle{intro}\pagenumbering{roman}
\tableofcontents
\clearpage

\pagestyle{main}\pagenumbering{arabic}
\part{La naissance}
\chapter{La respiration}
\section{Les poumons}
\lipsum[1-22]

\end{document}
lehibou
Posts: 4
Joined: Wed Sep 29, 2010 10:15 am

Layout automation ?

Post by lehibou »

:D
meho_r, would you like a hug ? an Inyambirano k'ubuntu ? (I like this one because of Linux) :D

I tried something similar but I was trying to redefine twice the plain style and obviously the compilation recognized only one of us.

You've got the final point.

But when you said that i didn't explained :
lehibou wrote:We can see that the TOC, the Part and Chapter pages have a footnote + separation line.
I just want it on the Chapter pages.

That is good to me.
The layout automation is now an aberration. So my hitch is now solved.

Thanks a lot,

LeHibou
Post Reply