thispagestyle has no effect if no page broken(clearpage, newpage) is given
Clash Royale CLAN TAG#URR8PPP
At a certain position in the article, the page that it belongs, need a special fancy style which I do by thispagestyle
from the package fancyhdr
.
In my example as shown in the MWE below, the page, and only the page where the text "bbb" is in(it's at the second page in this example, but may also at the other page, determined by the length of article), need a chead
. However, the content of chead
is in fact at the first page, not in the second page as I expect.
I think this is because no page-break is given. But the position of text "bbb" is up to the length of article, so how to deal with this problem?
My MWE is:
documentclassarticle
usepackagefancyhdr
begindocument
fancypagestylecommoncheadI want my header only on the page at which ``bbb'' is located
aaaparvspace80em
bbbthispagestylecommonparvspace80em
ccc
enddocument
EDIT:
To make my intention more clearly, I'd like to give the following modified MWE.
My desire is: all pages should have the same header/footer contents which are defined in fancypagestyleallpages
, except that the page which "bbb" is in(in this example,it's the second page), has a different header/footer defined by fancypagestyleonlythispage
.
But the real typeset is far from my intention. I think this is because no page-breaks are given.
As the position of "bbb" is up to the length of article, I can't forsee which page it will be in. So, is there an unvesal method to deal with such kind of problem?
documentclassarticle
usepackagefancyhdr,
begindocument
fancypagestyleonlythispagecheadonly this pagecfootonly this page
fancypagestyleallpagesfancyhfcheadall pagescfootall pages
pagestyleallpages
aaaparvspace80em
bbbthispagestyleonlythispageparvspace80em
ccc
enddocument
fancyhdr
add a comment |
At a certain position in the article, the page that it belongs, need a special fancy style which I do by thispagestyle
from the package fancyhdr
.
In my example as shown in the MWE below, the page, and only the page where the text "bbb" is in(it's at the second page in this example, but may also at the other page, determined by the length of article), need a chead
. However, the content of chead
is in fact at the first page, not in the second page as I expect.
I think this is because no page-break is given. But the position of text "bbb" is up to the length of article, so how to deal with this problem?
My MWE is:
documentclassarticle
usepackagefancyhdr
begindocument
fancypagestylecommoncheadI want my header only on the page at which ``bbb'' is located
aaaparvspace80em
bbbthispagestylecommonparvspace80em
ccc
enddocument
EDIT:
To make my intention more clearly, I'd like to give the following modified MWE.
My desire is: all pages should have the same header/footer contents which are defined in fancypagestyleallpages
, except that the page which "bbb" is in(in this example,it's the second page), has a different header/footer defined by fancypagestyleonlythispage
.
But the real typeset is far from my intention. I think this is because no page-breaks are given.
As the position of "bbb" is up to the length of article, I can't forsee which page it will be in. So, is there an unvesal method to deal with such kind of problem?
documentclassarticle
usepackagefancyhdr,
begindocument
fancypagestyleonlythispagecheadonly this pagecfootonly this page
fancypagestyleallpagesfancyhfcheadall pagescfootall pages
pagestyleallpages
aaaparvspace80em
bbbthispagestyleonlythispageparvspace80em
ccc
enddocument
fancyhdr
add a comment |
At a certain position in the article, the page that it belongs, need a special fancy style which I do by thispagestyle
from the package fancyhdr
.
In my example as shown in the MWE below, the page, and only the page where the text "bbb" is in(it's at the second page in this example, but may also at the other page, determined by the length of article), need a chead
. However, the content of chead
is in fact at the first page, not in the second page as I expect.
I think this is because no page-break is given. But the position of text "bbb" is up to the length of article, so how to deal with this problem?
My MWE is:
documentclassarticle
usepackagefancyhdr
begindocument
fancypagestylecommoncheadI want my header only on the page at which ``bbb'' is located
aaaparvspace80em
bbbthispagestylecommonparvspace80em
ccc
enddocument
EDIT:
To make my intention more clearly, I'd like to give the following modified MWE.
My desire is: all pages should have the same header/footer contents which are defined in fancypagestyleallpages
, except that the page which "bbb" is in(in this example,it's the second page), has a different header/footer defined by fancypagestyleonlythispage
.
But the real typeset is far from my intention. I think this is because no page-breaks are given.
As the position of "bbb" is up to the length of article, I can't forsee which page it will be in. So, is there an unvesal method to deal with such kind of problem?
documentclassarticle
usepackagefancyhdr,
begindocument
fancypagestyleonlythispagecheadonly this pagecfootonly this page
fancypagestyleallpagesfancyhfcheadall pagescfootall pages
pagestyleallpages
aaaparvspace80em
bbbthispagestyleonlythispageparvspace80em
ccc
enddocument
fancyhdr
At a certain position in the article, the page that it belongs, need a special fancy style which I do by thispagestyle
from the package fancyhdr
.
In my example as shown in the MWE below, the page, and only the page where the text "bbb" is in(it's at the second page in this example, but may also at the other page, determined by the length of article), need a chead
. However, the content of chead
is in fact at the first page, not in the second page as I expect.
I think this is because no page-break is given. But the position of text "bbb" is up to the length of article, so how to deal with this problem?
My MWE is:
documentclassarticle
usepackagefancyhdr
begindocument
fancypagestylecommoncheadI want my header only on the page at which ``bbb'' is located
aaaparvspace80em
bbbthispagestylecommonparvspace80em
ccc
enddocument
EDIT:
To make my intention more clearly, I'd like to give the following modified MWE.
My desire is: all pages should have the same header/footer contents which are defined in fancypagestyleallpages
, except that the page which "bbb" is in(in this example,it's the second page), has a different header/footer defined by fancypagestyleonlythispage
.
But the real typeset is far from my intention. I think this is because no page-breaks are given.
As the position of "bbb" is up to the length of article, I can't forsee which page it will be in. So, is there an unvesal method to deal with such kind of problem?
documentclassarticle
usepackagefancyhdr,
begindocument
fancypagestyleonlythispagecheadonly this pagecfootonly this page
fancypagestyleallpagesfancyhfcheadall pagescfootall pages
pagestyleallpages
aaaparvspace80em
bbbthispagestyleonlythispageparvspace80em
ccc
enddocument
fancyhdr
fancyhdr
edited Feb 21 at 7:17
lyl
asked Feb 20 at 19:42
lyllyl
70638
70638
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You can use a mark
command:
documentclassarticle
usepackagefancyhdr
fancypagestylecommonfancyhfcheadrightmark
pagestylecommon
begindocument
aaaparvspace80em
bbbmarkrightI want my header only on the page at which ``bbb'' is locatedmarkrightparvspace80em
ccc
enddocument
You can also pass a boolean with the mark command use this in the header. The value of the first markright on the page will win.
documentclassarticle
usepackagefancyhdr
usepackageetoolbox
newboolbbbpage
begindocument
fancypagestyleallpagesfancyhf%
cheadrightmarkifboolbbbpageonly this pageall pages
cfootrightmarkifboolbbbpageonly this pageall pages
pagestyleallpages
aaaparvspace80em
bbbmarkrightbooltruebbbpagemarkrightboolfalsebbbpageparvspace80em
ccc
enddocument
In case you need markright/rightmark, e.g. to get some section
on the headers, you could use your own marks (but this could break e.g. with twocolumn or multicolumn).
Besides chead, there are also rhead, lhead, cfoot...etc. in my article. I edit my question. Would you have a look at it?
– lyl
Feb 21 at 9:17
1
I don't like it very much if questions are extended and changed and so make existing answers invalid. I edited now once, but if you have more questions, ask a new one.
– Ulrike Fischer
Feb 21 at 15:23
@lyl The community seems to agree with Ulrike's disliking of edits that invalidate existing answers. See for example tex.meta.stackexchange.com/q/3625/35864, tex.meta.stackexchange.com/q/7678/35864, tex.meta.stackexchange.com/q/7425/35864, tex.meta.stackexchange.com/q/7869/35864 ... It's free to ask a new question in case you later find out that you actually wanted to ask something slightly different (or more).
– moewe
Feb 21 at 15:29
add a comment |
I guess you're using headers, but that's not really relevant.
The problem is that page breaking is asynchronous: typically TeX reads more that fits in a page before deciding it has to ship out a page. In your case, thispagestyle
is seen and processed while TeX has not yet decided to eject page 1.
The command thispagestyle
is only reliable if given shortly after a page break, for instance when a new chapter is started, a feature which standard classes use for issuing thispagestyleplain
.
The only reliable method is to use the label
-pageref
mechanism. Here I implement the job with the help of refcount
that provides an expandable version of pageref
, namely getpagerefnumber
.
documentclassarticle
usepackagefancyhdr
usepackagerefcount,pdftexcmds
pagestylefancy
makeatletter
chead%
ifnumpdf@strcmpthepagegetpagerefnumberbbb=z@
I want my header only on the page at which ``bbb'' is located%
else
Normal header%
fi
makeatother
begindocument
aaaparvspace80em
bbblabelbbbparvspace80em
ccc
enddocument
I use pdf@strcmp
in order to ensure that any kind of page numbering is supported.
The following supports any number of variant headers. Please, don't dare to ask for a version without ExplSyntaxOn
.
The alternate headers are collected in a property list, indexed by the labels we want to use. At begin document, this property list is reindexed using the page number corresponding to the reference. Due to this, later appearing labels will take precedence in case two labels for alternate headers happen to fall on the same page.
documentclassarticle
usepackage[a6paper]geometry % just to make a smaller picture
usepackagefancyhdr
usepackagerefcount,xparse
ExplSyntaxOn
NewDocumentCommanddefinelylheadersmm
% #1: default header
% #2: label=alternate header, label=alternate header, ...
tl_gset:Nn g_lylheader_default_tl #1
prop_gset_from_keyval:Nn g_lylheader_headers_prop #2
prop_map_inline:Nn g_lylheader_headers_prop
seq_gput_right:Nn g_lylheaders_labels_seq ##1
AtBeginDocument
seq_map_inline:Nn g_lylheaders_labels_seq
prop_gput:Nxx g_lylheaders_headers_body_prop
getpagerefnumber#1
prop_item:Nn g_lylheader_headers_prop #1
NewDocumentCommandlylheaders
prop_if_in:NxTF g_lylheaders_headers_body_prop thepage
prop_item:Nx g_lylheaders_headers_body_prop thepage
tl_use:N g_lylheader_default_tl
cs_generate_variant:Nn prop_if_in:NnTF Nx
cs_generate_variant:Nn prop_item:Nn Nx
cs_generate_variant:Nn prop_gput:Nnn Nxx
tl_new:N g_lylheader_default_tl
prop_new:N g_lylheaders_headers_prop
prop_new:N g_lylheaders_headers_body_prop
seq_new:N g_lylheaders_labels_seq
ExplSyntaxOff
pagestylefancy
cheadlylheaders
definelylheadersDefault header
bbb = This is the header for bbb,
ccc = This is the header for ccc,
begindocument
aaaparvspacedimexprtextheight-topskip
bbblabelbbbparvspacedimexprtextheight-topskip
ccclabelcccparvspacedimexprtextheight-topskip
ddd
enddocument
Isz@
equal to zero?
– Sigur
Feb 20 at 22:36
1
@Sigur Yes. This usage also terminates the number to be looked for.
– egreg
Feb 20 at 22:37
But is it testing if some number is zero? I confess that I didn't follow the idea. Without it I got error Missing = inserted for ifnum. but since you usedz@
, the error after removing it was expected. No surprise.
– Sigur
Feb 20 at 22:41
@Sigurpdf@strcmp
returns 0 if the two strings given as argument are, after full expansion, equal and a nonzero number otherwise.
– egreg
Feb 20 at 22:58
Oh, now it makes sense to me. Now I understand. Thanks for attention.
– Sigur
Feb 20 at 23:07
|
show 3 more comments
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "85"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f475877%2fthispagestyle-has-no-effect-if-no-page-broken-clearpage-newpage-is-given%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use a mark
command:
documentclassarticle
usepackagefancyhdr
fancypagestylecommonfancyhfcheadrightmark
pagestylecommon
begindocument
aaaparvspace80em
bbbmarkrightI want my header only on the page at which ``bbb'' is locatedmarkrightparvspace80em
ccc
enddocument
You can also pass a boolean with the mark command use this in the header. The value of the first markright on the page will win.
documentclassarticle
usepackagefancyhdr
usepackageetoolbox
newboolbbbpage
begindocument
fancypagestyleallpagesfancyhf%
cheadrightmarkifboolbbbpageonly this pageall pages
cfootrightmarkifboolbbbpageonly this pageall pages
pagestyleallpages
aaaparvspace80em
bbbmarkrightbooltruebbbpagemarkrightboolfalsebbbpageparvspace80em
ccc
enddocument
In case you need markright/rightmark, e.g. to get some section
on the headers, you could use your own marks (but this could break e.g. with twocolumn or multicolumn).
Besides chead, there are also rhead, lhead, cfoot...etc. in my article. I edit my question. Would you have a look at it?
– lyl
Feb 21 at 9:17
1
I don't like it very much if questions are extended and changed and so make existing answers invalid. I edited now once, but if you have more questions, ask a new one.
– Ulrike Fischer
Feb 21 at 15:23
@lyl The community seems to agree with Ulrike's disliking of edits that invalidate existing answers. See for example tex.meta.stackexchange.com/q/3625/35864, tex.meta.stackexchange.com/q/7678/35864, tex.meta.stackexchange.com/q/7425/35864, tex.meta.stackexchange.com/q/7869/35864 ... It's free to ask a new question in case you later find out that you actually wanted to ask something slightly different (or more).
– moewe
Feb 21 at 15:29
add a comment |
You can use a mark
command:
documentclassarticle
usepackagefancyhdr
fancypagestylecommonfancyhfcheadrightmark
pagestylecommon
begindocument
aaaparvspace80em
bbbmarkrightI want my header only on the page at which ``bbb'' is locatedmarkrightparvspace80em
ccc
enddocument
You can also pass a boolean with the mark command use this in the header. The value of the first markright on the page will win.
documentclassarticle
usepackagefancyhdr
usepackageetoolbox
newboolbbbpage
begindocument
fancypagestyleallpagesfancyhf%
cheadrightmarkifboolbbbpageonly this pageall pages
cfootrightmarkifboolbbbpageonly this pageall pages
pagestyleallpages
aaaparvspace80em
bbbmarkrightbooltruebbbpagemarkrightboolfalsebbbpageparvspace80em
ccc
enddocument
In case you need markright/rightmark, e.g. to get some section
on the headers, you could use your own marks (but this could break e.g. with twocolumn or multicolumn).
Besides chead, there are also rhead, lhead, cfoot...etc. in my article. I edit my question. Would you have a look at it?
– lyl
Feb 21 at 9:17
1
I don't like it very much if questions are extended and changed and so make existing answers invalid. I edited now once, but if you have more questions, ask a new one.
– Ulrike Fischer
Feb 21 at 15:23
@lyl The community seems to agree with Ulrike's disliking of edits that invalidate existing answers. See for example tex.meta.stackexchange.com/q/3625/35864, tex.meta.stackexchange.com/q/7678/35864, tex.meta.stackexchange.com/q/7425/35864, tex.meta.stackexchange.com/q/7869/35864 ... It's free to ask a new question in case you later find out that you actually wanted to ask something slightly different (or more).
– moewe
Feb 21 at 15:29
add a comment |
You can use a mark
command:
documentclassarticle
usepackagefancyhdr
fancypagestylecommonfancyhfcheadrightmark
pagestylecommon
begindocument
aaaparvspace80em
bbbmarkrightI want my header only on the page at which ``bbb'' is locatedmarkrightparvspace80em
ccc
enddocument
You can also pass a boolean with the mark command use this in the header. The value of the first markright on the page will win.
documentclassarticle
usepackagefancyhdr
usepackageetoolbox
newboolbbbpage
begindocument
fancypagestyleallpagesfancyhf%
cheadrightmarkifboolbbbpageonly this pageall pages
cfootrightmarkifboolbbbpageonly this pageall pages
pagestyleallpages
aaaparvspace80em
bbbmarkrightbooltruebbbpagemarkrightboolfalsebbbpageparvspace80em
ccc
enddocument
In case you need markright/rightmark, e.g. to get some section
on the headers, you could use your own marks (but this could break e.g. with twocolumn or multicolumn).
You can use a mark
command:
documentclassarticle
usepackagefancyhdr
fancypagestylecommonfancyhfcheadrightmark
pagestylecommon
begindocument
aaaparvspace80em
bbbmarkrightI want my header only on the page at which ``bbb'' is locatedmarkrightparvspace80em
ccc
enddocument
You can also pass a boolean with the mark command use this in the header. The value of the first markright on the page will win.
documentclassarticle
usepackagefancyhdr
usepackageetoolbox
newboolbbbpage
begindocument
fancypagestyleallpagesfancyhf%
cheadrightmarkifboolbbbpageonly this pageall pages
cfootrightmarkifboolbbbpageonly this pageall pages
pagestyleallpages
aaaparvspace80em
bbbmarkrightbooltruebbbpagemarkrightboolfalsebbbpageparvspace80em
ccc
enddocument
In case you need markright/rightmark, e.g. to get some section
on the headers, you could use your own marks (but this could break e.g. with twocolumn or multicolumn).
edited Feb 21 at 15:22
answered Feb 20 at 20:13
Ulrike FischerUlrike Fischer
196k8302689
196k8302689
Besides chead, there are also rhead, lhead, cfoot...etc. in my article. I edit my question. Would you have a look at it?
– lyl
Feb 21 at 9:17
1
I don't like it very much if questions are extended and changed and so make existing answers invalid. I edited now once, but if you have more questions, ask a new one.
– Ulrike Fischer
Feb 21 at 15:23
@lyl The community seems to agree with Ulrike's disliking of edits that invalidate existing answers. See for example tex.meta.stackexchange.com/q/3625/35864, tex.meta.stackexchange.com/q/7678/35864, tex.meta.stackexchange.com/q/7425/35864, tex.meta.stackexchange.com/q/7869/35864 ... It's free to ask a new question in case you later find out that you actually wanted to ask something slightly different (or more).
– moewe
Feb 21 at 15:29
add a comment |
Besides chead, there are also rhead, lhead, cfoot...etc. in my article. I edit my question. Would you have a look at it?
– lyl
Feb 21 at 9:17
1
I don't like it very much if questions are extended and changed and so make existing answers invalid. I edited now once, but if you have more questions, ask a new one.
– Ulrike Fischer
Feb 21 at 15:23
@lyl The community seems to agree with Ulrike's disliking of edits that invalidate existing answers. See for example tex.meta.stackexchange.com/q/3625/35864, tex.meta.stackexchange.com/q/7678/35864, tex.meta.stackexchange.com/q/7425/35864, tex.meta.stackexchange.com/q/7869/35864 ... It's free to ask a new question in case you later find out that you actually wanted to ask something slightly different (or more).
– moewe
Feb 21 at 15:29
Besides chead, there are also rhead, lhead, cfoot...etc. in my article. I edit my question. Would you have a look at it?
– lyl
Feb 21 at 9:17
Besides chead, there are also rhead, lhead, cfoot...etc. in my article. I edit my question. Would you have a look at it?
– lyl
Feb 21 at 9:17
1
1
I don't like it very much if questions are extended and changed and so make existing answers invalid. I edited now once, but if you have more questions, ask a new one.
– Ulrike Fischer
Feb 21 at 15:23
I don't like it very much if questions are extended and changed and so make existing answers invalid. I edited now once, but if you have more questions, ask a new one.
– Ulrike Fischer
Feb 21 at 15:23
@lyl The community seems to agree with Ulrike's disliking of edits that invalidate existing answers. See for example tex.meta.stackexchange.com/q/3625/35864, tex.meta.stackexchange.com/q/7678/35864, tex.meta.stackexchange.com/q/7425/35864, tex.meta.stackexchange.com/q/7869/35864 ... It's free to ask a new question in case you later find out that you actually wanted to ask something slightly different (or more).
– moewe
Feb 21 at 15:29
@lyl The community seems to agree with Ulrike's disliking of edits that invalidate existing answers. See for example tex.meta.stackexchange.com/q/3625/35864, tex.meta.stackexchange.com/q/7678/35864, tex.meta.stackexchange.com/q/7425/35864, tex.meta.stackexchange.com/q/7869/35864 ... It's free to ask a new question in case you later find out that you actually wanted to ask something slightly different (or more).
– moewe
Feb 21 at 15:29
add a comment |
I guess you're using headers, but that's not really relevant.
The problem is that page breaking is asynchronous: typically TeX reads more that fits in a page before deciding it has to ship out a page. In your case, thispagestyle
is seen and processed while TeX has not yet decided to eject page 1.
The command thispagestyle
is only reliable if given shortly after a page break, for instance when a new chapter is started, a feature which standard classes use for issuing thispagestyleplain
.
The only reliable method is to use the label
-pageref
mechanism. Here I implement the job with the help of refcount
that provides an expandable version of pageref
, namely getpagerefnumber
.
documentclassarticle
usepackagefancyhdr
usepackagerefcount,pdftexcmds
pagestylefancy
makeatletter
chead%
ifnumpdf@strcmpthepagegetpagerefnumberbbb=z@
I want my header only on the page at which ``bbb'' is located%
else
Normal header%
fi
makeatother
begindocument
aaaparvspace80em
bbblabelbbbparvspace80em
ccc
enddocument
I use pdf@strcmp
in order to ensure that any kind of page numbering is supported.
The following supports any number of variant headers. Please, don't dare to ask for a version without ExplSyntaxOn
.
The alternate headers are collected in a property list, indexed by the labels we want to use. At begin document, this property list is reindexed using the page number corresponding to the reference. Due to this, later appearing labels will take precedence in case two labels for alternate headers happen to fall on the same page.
documentclassarticle
usepackage[a6paper]geometry % just to make a smaller picture
usepackagefancyhdr
usepackagerefcount,xparse
ExplSyntaxOn
NewDocumentCommanddefinelylheadersmm
% #1: default header
% #2: label=alternate header, label=alternate header, ...
tl_gset:Nn g_lylheader_default_tl #1
prop_gset_from_keyval:Nn g_lylheader_headers_prop #2
prop_map_inline:Nn g_lylheader_headers_prop
seq_gput_right:Nn g_lylheaders_labels_seq ##1
AtBeginDocument
seq_map_inline:Nn g_lylheaders_labels_seq
prop_gput:Nxx g_lylheaders_headers_body_prop
getpagerefnumber#1
prop_item:Nn g_lylheader_headers_prop #1
NewDocumentCommandlylheaders
prop_if_in:NxTF g_lylheaders_headers_body_prop thepage
prop_item:Nx g_lylheaders_headers_body_prop thepage
tl_use:N g_lylheader_default_tl
cs_generate_variant:Nn prop_if_in:NnTF Nx
cs_generate_variant:Nn prop_item:Nn Nx
cs_generate_variant:Nn prop_gput:Nnn Nxx
tl_new:N g_lylheader_default_tl
prop_new:N g_lylheaders_headers_prop
prop_new:N g_lylheaders_headers_body_prop
seq_new:N g_lylheaders_labels_seq
ExplSyntaxOff
pagestylefancy
cheadlylheaders
definelylheadersDefault header
bbb = This is the header for bbb,
ccc = This is the header for ccc,
begindocument
aaaparvspacedimexprtextheight-topskip
bbblabelbbbparvspacedimexprtextheight-topskip
ccclabelcccparvspacedimexprtextheight-topskip
ddd
enddocument
Isz@
equal to zero?
– Sigur
Feb 20 at 22:36
1
@Sigur Yes. This usage also terminates the number to be looked for.
– egreg
Feb 20 at 22:37
But is it testing if some number is zero? I confess that I didn't follow the idea. Without it I got error Missing = inserted for ifnum. but since you usedz@
, the error after removing it was expected. No surprise.
– Sigur
Feb 20 at 22:41
@Sigurpdf@strcmp
returns 0 if the two strings given as argument are, after full expansion, equal and a nonzero number otherwise.
– egreg
Feb 20 at 22:58
Oh, now it makes sense to me. Now I understand. Thanks for attention.
– Sigur
Feb 20 at 23:07
|
show 3 more comments
I guess you're using headers, but that's not really relevant.
The problem is that page breaking is asynchronous: typically TeX reads more that fits in a page before deciding it has to ship out a page. In your case, thispagestyle
is seen and processed while TeX has not yet decided to eject page 1.
The command thispagestyle
is only reliable if given shortly after a page break, for instance when a new chapter is started, a feature which standard classes use for issuing thispagestyleplain
.
The only reliable method is to use the label
-pageref
mechanism. Here I implement the job with the help of refcount
that provides an expandable version of pageref
, namely getpagerefnumber
.
documentclassarticle
usepackagefancyhdr
usepackagerefcount,pdftexcmds
pagestylefancy
makeatletter
chead%
ifnumpdf@strcmpthepagegetpagerefnumberbbb=z@
I want my header only on the page at which ``bbb'' is located%
else
Normal header%
fi
makeatother
begindocument
aaaparvspace80em
bbblabelbbbparvspace80em
ccc
enddocument
I use pdf@strcmp
in order to ensure that any kind of page numbering is supported.
The following supports any number of variant headers. Please, don't dare to ask for a version without ExplSyntaxOn
.
The alternate headers are collected in a property list, indexed by the labels we want to use. At begin document, this property list is reindexed using the page number corresponding to the reference. Due to this, later appearing labels will take precedence in case two labels for alternate headers happen to fall on the same page.
documentclassarticle
usepackage[a6paper]geometry % just to make a smaller picture
usepackagefancyhdr
usepackagerefcount,xparse
ExplSyntaxOn
NewDocumentCommanddefinelylheadersmm
% #1: default header
% #2: label=alternate header, label=alternate header, ...
tl_gset:Nn g_lylheader_default_tl #1
prop_gset_from_keyval:Nn g_lylheader_headers_prop #2
prop_map_inline:Nn g_lylheader_headers_prop
seq_gput_right:Nn g_lylheaders_labels_seq ##1
AtBeginDocument
seq_map_inline:Nn g_lylheaders_labels_seq
prop_gput:Nxx g_lylheaders_headers_body_prop
getpagerefnumber#1
prop_item:Nn g_lylheader_headers_prop #1
NewDocumentCommandlylheaders
prop_if_in:NxTF g_lylheaders_headers_body_prop thepage
prop_item:Nx g_lylheaders_headers_body_prop thepage
tl_use:N g_lylheader_default_tl
cs_generate_variant:Nn prop_if_in:NnTF Nx
cs_generate_variant:Nn prop_item:Nn Nx
cs_generate_variant:Nn prop_gput:Nnn Nxx
tl_new:N g_lylheader_default_tl
prop_new:N g_lylheaders_headers_prop
prop_new:N g_lylheaders_headers_body_prop
seq_new:N g_lylheaders_labels_seq
ExplSyntaxOff
pagestylefancy
cheadlylheaders
definelylheadersDefault header
bbb = This is the header for bbb,
ccc = This is the header for ccc,
begindocument
aaaparvspacedimexprtextheight-topskip
bbblabelbbbparvspacedimexprtextheight-topskip
ccclabelcccparvspacedimexprtextheight-topskip
ddd
enddocument
Isz@
equal to zero?
– Sigur
Feb 20 at 22:36
1
@Sigur Yes. This usage also terminates the number to be looked for.
– egreg
Feb 20 at 22:37
But is it testing if some number is zero? I confess that I didn't follow the idea. Without it I got error Missing = inserted for ifnum. but since you usedz@
, the error after removing it was expected. No surprise.
– Sigur
Feb 20 at 22:41
@Sigurpdf@strcmp
returns 0 if the two strings given as argument are, after full expansion, equal and a nonzero number otherwise.
– egreg
Feb 20 at 22:58
Oh, now it makes sense to me. Now I understand. Thanks for attention.
– Sigur
Feb 20 at 23:07
|
show 3 more comments
I guess you're using headers, but that's not really relevant.
The problem is that page breaking is asynchronous: typically TeX reads more that fits in a page before deciding it has to ship out a page. In your case, thispagestyle
is seen and processed while TeX has not yet decided to eject page 1.
The command thispagestyle
is only reliable if given shortly after a page break, for instance when a new chapter is started, a feature which standard classes use for issuing thispagestyleplain
.
The only reliable method is to use the label
-pageref
mechanism. Here I implement the job with the help of refcount
that provides an expandable version of pageref
, namely getpagerefnumber
.
documentclassarticle
usepackagefancyhdr
usepackagerefcount,pdftexcmds
pagestylefancy
makeatletter
chead%
ifnumpdf@strcmpthepagegetpagerefnumberbbb=z@
I want my header only on the page at which ``bbb'' is located%
else
Normal header%
fi
makeatother
begindocument
aaaparvspace80em
bbblabelbbbparvspace80em
ccc
enddocument
I use pdf@strcmp
in order to ensure that any kind of page numbering is supported.
The following supports any number of variant headers. Please, don't dare to ask for a version without ExplSyntaxOn
.
The alternate headers are collected in a property list, indexed by the labels we want to use. At begin document, this property list is reindexed using the page number corresponding to the reference. Due to this, later appearing labels will take precedence in case two labels for alternate headers happen to fall on the same page.
documentclassarticle
usepackage[a6paper]geometry % just to make a smaller picture
usepackagefancyhdr
usepackagerefcount,xparse
ExplSyntaxOn
NewDocumentCommanddefinelylheadersmm
% #1: default header
% #2: label=alternate header, label=alternate header, ...
tl_gset:Nn g_lylheader_default_tl #1
prop_gset_from_keyval:Nn g_lylheader_headers_prop #2
prop_map_inline:Nn g_lylheader_headers_prop
seq_gput_right:Nn g_lylheaders_labels_seq ##1
AtBeginDocument
seq_map_inline:Nn g_lylheaders_labels_seq
prop_gput:Nxx g_lylheaders_headers_body_prop
getpagerefnumber#1
prop_item:Nn g_lylheader_headers_prop #1
NewDocumentCommandlylheaders
prop_if_in:NxTF g_lylheaders_headers_body_prop thepage
prop_item:Nx g_lylheaders_headers_body_prop thepage
tl_use:N g_lylheader_default_tl
cs_generate_variant:Nn prop_if_in:NnTF Nx
cs_generate_variant:Nn prop_item:Nn Nx
cs_generate_variant:Nn prop_gput:Nnn Nxx
tl_new:N g_lylheader_default_tl
prop_new:N g_lylheaders_headers_prop
prop_new:N g_lylheaders_headers_body_prop
seq_new:N g_lylheaders_labels_seq
ExplSyntaxOff
pagestylefancy
cheadlylheaders
definelylheadersDefault header
bbb = This is the header for bbb,
ccc = This is the header for ccc,
begindocument
aaaparvspacedimexprtextheight-topskip
bbblabelbbbparvspacedimexprtextheight-topskip
ccclabelcccparvspacedimexprtextheight-topskip
ddd
enddocument
I guess you're using headers, but that's not really relevant.
The problem is that page breaking is asynchronous: typically TeX reads more that fits in a page before deciding it has to ship out a page. In your case, thispagestyle
is seen and processed while TeX has not yet decided to eject page 1.
The command thispagestyle
is only reliable if given shortly after a page break, for instance when a new chapter is started, a feature which standard classes use for issuing thispagestyleplain
.
The only reliable method is to use the label
-pageref
mechanism. Here I implement the job with the help of refcount
that provides an expandable version of pageref
, namely getpagerefnumber
.
documentclassarticle
usepackagefancyhdr
usepackagerefcount,pdftexcmds
pagestylefancy
makeatletter
chead%
ifnumpdf@strcmpthepagegetpagerefnumberbbb=z@
I want my header only on the page at which ``bbb'' is located%
else
Normal header%
fi
makeatother
begindocument
aaaparvspace80em
bbblabelbbbparvspace80em
ccc
enddocument
I use pdf@strcmp
in order to ensure that any kind of page numbering is supported.
The following supports any number of variant headers. Please, don't dare to ask for a version without ExplSyntaxOn
.
The alternate headers are collected in a property list, indexed by the labels we want to use. At begin document, this property list is reindexed using the page number corresponding to the reference. Due to this, later appearing labels will take precedence in case two labels for alternate headers happen to fall on the same page.
documentclassarticle
usepackage[a6paper]geometry % just to make a smaller picture
usepackagefancyhdr
usepackagerefcount,xparse
ExplSyntaxOn
NewDocumentCommanddefinelylheadersmm
% #1: default header
% #2: label=alternate header, label=alternate header, ...
tl_gset:Nn g_lylheader_default_tl #1
prop_gset_from_keyval:Nn g_lylheader_headers_prop #2
prop_map_inline:Nn g_lylheader_headers_prop
seq_gput_right:Nn g_lylheaders_labels_seq ##1
AtBeginDocument
seq_map_inline:Nn g_lylheaders_labels_seq
prop_gput:Nxx g_lylheaders_headers_body_prop
getpagerefnumber#1
prop_item:Nn g_lylheader_headers_prop #1
NewDocumentCommandlylheaders
prop_if_in:NxTF g_lylheaders_headers_body_prop thepage
prop_item:Nx g_lylheaders_headers_body_prop thepage
tl_use:N g_lylheader_default_tl
cs_generate_variant:Nn prop_if_in:NnTF Nx
cs_generate_variant:Nn prop_item:Nn Nx
cs_generate_variant:Nn prop_gput:Nnn Nxx
tl_new:N g_lylheader_default_tl
prop_new:N g_lylheaders_headers_prop
prop_new:N g_lylheaders_headers_body_prop
seq_new:N g_lylheaders_labels_seq
ExplSyntaxOff
pagestylefancy
cheadlylheaders
definelylheadersDefault header
bbb = This is the header for bbb,
ccc = This is the header for ccc,
begindocument
aaaparvspacedimexprtextheight-topskip
bbblabelbbbparvspacedimexprtextheight-topskip
ccclabelcccparvspacedimexprtextheight-topskip
ddd
enddocument
edited Feb 21 at 10:15
answered Feb 20 at 22:30
egregegreg
727k8819223231
727k8819223231
Isz@
equal to zero?
– Sigur
Feb 20 at 22:36
1
@Sigur Yes. This usage also terminates the number to be looked for.
– egreg
Feb 20 at 22:37
But is it testing if some number is zero? I confess that I didn't follow the idea. Without it I got error Missing = inserted for ifnum. but since you usedz@
, the error after removing it was expected. No surprise.
– Sigur
Feb 20 at 22:41
@Sigurpdf@strcmp
returns 0 if the two strings given as argument are, after full expansion, equal and a nonzero number otherwise.
– egreg
Feb 20 at 22:58
Oh, now it makes sense to me. Now I understand. Thanks for attention.
– Sigur
Feb 20 at 23:07
|
show 3 more comments
Isz@
equal to zero?
– Sigur
Feb 20 at 22:36
1
@Sigur Yes. This usage also terminates the number to be looked for.
– egreg
Feb 20 at 22:37
But is it testing if some number is zero? I confess that I didn't follow the idea. Without it I got error Missing = inserted for ifnum. but since you usedz@
, the error after removing it was expected. No surprise.
– Sigur
Feb 20 at 22:41
@Sigurpdf@strcmp
returns 0 if the two strings given as argument are, after full expansion, equal and a nonzero number otherwise.
– egreg
Feb 20 at 22:58
Oh, now it makes sense to me. Now I understand. Thanks for attention.
– Sigur
Feb 20 at 23:07
Is
z@
equal to zero?– Sigur
Feb 20 at 22:36
Is
z@
equal to zero?– Sigur
Feb 20 at 22:36
1
1
@Sigur Yes. This usage also terminates the number to be looked for.
– egreg
Feb 20 at 22:37
@Sigur Yes. This usage also terminates the number to be looked for.
– egreg
Feb 20 at 22:37
But is it testing if some number is zero? I confess that I didn't follow the idea. Without it I got error Missing = inserted for ifnum. but since you used
z@
, the error after removing it was expected. No surprise.– Sigur
Feb 20 at 22:41
But is it testing if some number is zero? I confess that I didn't follow the idea. Without it I got error Missing = inserted for ifnum. but since you used
z@
, the error after removing it was expected. No surprise.– Sigur
Feb 20 at 22:41
@Sigur
pdf@strcmp
returns 0 if the two strings given as argument are, after full expansion, equal and a nonzero number otherwise.– egreg
Feb 20 at 22:58
@Sigur
pdf@strcmp
returns 0 if the two strings given as argument are, after full expansion, equal and a nonzero number otherwise.– egreg
Feb 20 at 22:58
Oh, now it makes sense to me. Now I understand. Thanks for attention.
– Sigur
Feb 20 at 23:07
Oh, now it makes sense to me. Now I understand. Thanks for attention.
– Sigur
Feb 20 at 23:07
|
show 3 more comments
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f475877%2fthispagestyle-has-no-effect-if-no-page-broken-clearpage-newpage-is-given%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown