Change font within Chapter Title - e.g. first part black, second red
Since I often use one document in two forms, lets say in form 1 and form 2, I would like to label that accordingly in the chapter headings and have parts in a different color. So the questions is, how can one change Colors within a chapter heading (I know of sectsty
, but this seems to affect the whole and all chapter headings?)?
The following example gives an idea of what I want to achieve, but it does not work since simple text colours in headings seem to be not supported.
documentclass{book}
usepackage[english]{babel}
usepackage{xcolor}
begin{document}
chapter{Lions and Birds textcolor{red}{(Document Form 1)}}
%
newpage
%
chapter{Alligators and Storks textcolor{red}{(Document Form 1)}}
end{document}
Thanks in advance and best regards, Manuel
fonts sectioning color
add a comment |
Since I often use one document in two forms, lets say in form 1 and form 2, I would like to label that accordingly in the chapter headings and have parts in a different color. So the questions is, how can one change Colors within a chapter heading (I know of sectsty
, but this seems to affect the whole and all chapter headings?)?
The following example gives an idea of what I want to achieve, but it does not work since simple text colours in headings seem to be not supported.
documentclass{book}
usepackage[english]{babel}
usepackage{xcolor}
begin{document}
chapter{Lions and Birds textcolor{red}{(Document Form 1)}}
%
newpage
%
chapter{Alligators and Storks textcolor{red}{(Document Form 1)}}
end{document}
Thanks in advance and best regards, Manuel
fonts sectioning color
2
This does not work becauseMakeUppercase
(being used in a macro behindchapter
transformsred
toRED
, which is unknown, of course --textcolor
is no robust macro
– user31729
Feb 2 at 9:41
add a comment |
Since I often use one document in two forms, lets say in form 1 and form 2, I would like to label that accordingly in the chapter headings and have parts in a different color. So the questions is, how can one change Colors within a chapter heading (I know of sectsty
, but this seems to affect the whole and all chapter headings?)?
The following example gives an idea of what I want to achieve, but it does not work since simple text colours in headings seem to be not supported.
documentclass{book}
usepackage[english]{babel}
usepackage{xcolor}
begin{document}
chapter{Lions and Birds textcolor{red}{(Document Form 1)}}
%
newpage
%
chapter{Alligators and Storks textcolor{red}{(Document Form 1)}}
end{document}
Thanks in advance and best regards, Manuel
fonts sectioning color
Since I often use one document in two forms, lets say in form 1 and form 2, I would like to label that accordingly in the chapter headings and have parts in a different color. So the questions is, how can one change Colors within a chapter heading (I know of sectsty
, but this seems to affect the whole and all chapter headings?)?
The following example gives an idea of what I want to achieve, but it does not work since simple text colours in headings seem to be not supported.
documentclass{book}
usepackage[english]{babel}
usepackage{xcolor}
begin{document}
chapter{Lions and Birds textcolor{red}{(Document Form 1)}}
%
newpage
%
chapter{Alligators and Storks textcolor{red}{(Document Form 1)}}
end{document}
Thanks in advance and best regards, Manuel
fonts sectioning color
fonts sectioning color
edited Feb 2 at 13:29
moewe
96.8k10118362
96.8k10118362
asked Feb 2 at 9:37
ManuelManuel
676
676
2
This does not work becauseMakeUppercase
(being used in a macro behindchapter
transformsred
toRED
, which is unknown, of course --textcolor
is no robust macro
– user31729
Feb 2 at 9:41
add a comment |
2
This does not work becauseMakeUppercase
(being used in a macro behindchapter
transformsred
toRED
, which is unknown, of course --textcolor
is no robust macro
– user31729
Feb 2 at 9:41
2
2
This does not work because
MakeUppercase
(being used in a macro behind chapter
transforms red
to RED
, which is unknown, of course -- textcolor
is no robust macro– user31729
Feb 2 at 9:41
This does not work because
MakeUppercase
(being used in a macro behind chapter
transforms red
to RED
, which is unknown, of course -- textcolor
is no robust macro– user31729
Feb 2 at 9:41
add a comment |
2 Answers
2
active
oldest
votes
The same cause why ref
or gls
in a chapter etc. title is problematic occurs with textcolor
: The macro MakeUppercase
for the chapter marks at the heading transforms textcolor{ref}{...}
into textcolor{RED}{...}
first, which is expanded to its final meaning, trying to apply an undefined (most likely) color named RED
.
In order to prevent this, the color change must be hidden in a robust macro (or some macro prepended with protect
, but that might get tedious:
E.g.
newrobustcmd{redtext}[1]{%
textcolor{red}{#1}%
}
defines a macro meant for red text.
Another possibility is using the optional argument of chapter
and omitting the color change there, but this will not colorize the text in the ToC.
Please be aware, that mixing too much colors in text may worsen readability.
documentclass{book}
usepackage{xcolor}
usepackage{etoolbox}
usepackage{blindtext}
usepackage[english]{babel}
newrobustcmd{redtext}[1]{%
textcolor{red}{#1}%
}
newrobustcmd{bluetext}[1]{%
textcolor{blue}{#1}%
}
begin{document}
tableofcontents
chapter{Lions and Birds redtext{(Document Form 1)}}
chapter{Cats and mice bluetext{(Document Form 2)}}
chapter[Cows and goats]{Cows and goats textcolor{brown}{(Document Form 3)}}
blindtext[5]
end{document}
1
Thanks, Christian! This works perfectly fine for me. Since I only plan to use two different colors in headings, defining two robust colors is no issue.
– Manuel
Feb 2 at 10:00
1
@Manuel: You can also use a macroformone
andformtwo
, which does the formatting of your forms without typing the(...)
as well and you can simply change the colors inside theform...
macros instead of switchingredtext
to another macro name -- this depends on your design whatform 1
andform 2
are supposed to do, however
– user31729
Feb 2 at 10:03
add a comment |
May be I have missed something! I have just add usepackage{xcolor}
to the OP MWE preamble and I get this output:
documentclass{book}
usepackage[english]{babel}
usepackage{xcolor} % I add this line
begin{document}
chapter{Lions and Birds textcolor{red}{(Document Form 1)}}
end{document}
1
The issue is that the header uses an ALL-CAPS form of the chapter title and will try to find the colour RED, which does not exists. The problem only becomes apparent if you add a second page to the MWE so that you get a page with an actual header. (See also Christian's answer.)
– moewe
Feb 2 at 13:16
Thank you very much @moewe! Now I got it.
– Hafid Boukhoulda
Feb 2 at 13:25
Sorry, my bad. I should have included an additional page, in the original example (now edited).
– Manuel
Feb 2 at 13:26
1
@Manuel Note that a colour package (color
orxcolor
) is also needed (I edited it in). Please always test your MWEs before you submit them and make sure the show the same error you receive in your real document.
– moewe
Feb 2 at 13:30
Thanks, that's true. I did get an error, but it was not the same...
– Manuel
Feb 2 at 18:12
add a comment |
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%2f473012%2fchange-font-within-chapter-title-e-g-first-part-black-second-red%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
The same cause why ref
or gls
in a chapter etc. title is problematic occurs with textcolor
: The macro MakeUppercase
for the chapter marks at the heading transforms textcolor{ref}{...}
into textcolor{RED}{...}
first, which is expanded to its final meaning, trying to apply an undefined (most likely) color named RED
.
In order to prevent this, the color change must be hidden in a robust macro (or some macro prepended with protect
, but that might get tedious:
E.g.
newrobustcmd{redtext}[1]{%
textcolor{red}{#1}%
}
defines a macro meant for red text.
Another possibility is using the optional argument of chapter
and omitting the color change there, but this will not colorize the text in the ToC.
Please be aware, that mixing too much colors in text may worsen readability.
documentclass{book}
usepackage{xcolor}
usepackage{etoolbox}
usepackage{blindtext}
usepackage[english]{babel}
newrobustcmd{redtext}[1]{%
textcolor{red}{#1}%
}
newrobustcmd{bluetext}[1]{%
textcolor{blue}{#1}%
}
begin{document}
tableofcontents
chapter{Lions and Birds redtext{(Document Form 1)}}
chapter{Cats and mice bluetext{(Document Form 2)}}
chapter[Cows and goats]{Cows and goats textcolor{brown}{(Document Form 3)}}
blindtext[5]
end{document}
1
Thanks, Christian! This works perfectly fine for me. Since I only plan to use two different colors in headings, defining two robust colors is no issue.
– Manuel
Feb 2 at 10:00
1
@Manuel: You can also use a macroformone
andformtwo
, which does the formatting of your forms without typing the(...)
as well and you can simply change the colors inside theform...
macros instead of switchingredtext
to another macro name -- this depends on your design whatform 1
andform 2
are supposed to do, however
– user31729
Feb 2 at 10:03
add a comment |
The same cause why ref
or gls
in a chapter etc. title is problematic occurs with textcolor
: The macro MakeUppercase
for the chapter marks at the heading transforms textcolor{ref}{...}
into textcolor{RED}{...}
first, which is expanded to its final meaning, trying to apply an undefined (most likely) color named RED
.
In order to prevent this, the color change must be hidden in a robust macro (or some macro prepended with protect
, but that might get tedious:
E.g.
newrobustcmd{redtext}[1]{%
textcolor{red}{#1}%
}
defines a macro meant for red text.
Another possibility is using the optional argument of chapter
and omitting the color change there, but this will not colorize the text in the ToC.
Please be aware, that mixing too much colors in text may worsen readability.
documentclass{book}
usepackage{xcolor}
usepackage{etoolbox}
usepackage{blindtext}
usepackage[english]{babel}
newrobustcmd{redtext}[1]{%
textcolor{red}{#1}%
}
newrobustcmd{bluetext}[1]{%
textcolor{blue}{#1}%
}
begin{document}
tableofcontents
chapter{Lions and Birds redtext{(Document Form 1)}}
chapter{Cats and mice bluetext{(Document Form 2)}}
chapter[Cows and goats]{Cows and goats textcolor{brown}{(Document Form 3)}}
blindtext[5]
end{document}
1
Thanks, Christian! This works perfectly fine for me. Since I only plan to use two different colors in headings, defining two robust colors is no issue.
– Manuel
Feb 2 at 10:00
1
@Manuel: You can also use a macroformone
andformtwo
, which does the formatting of your forms without typing the(...)
as well and you can simply change the colors inside theform...
macros instead of switchingredtext
to another macro name -- this depends on your design whatform 1
andform 2
are supposed to do, however
– user31729
Feb 2 at 10:03
add a comment |
The same cause why ref
or gls
in a chapter etc. title is problematic occurs with textcolor
: The macro MakeUppercase
for the chapter marks at the heading transforms textcolor{ref}{...}
into textcolor{RED}{...}
first, which is expanded to its final meaning, trying to apply an undefined (most likely) color named RED
.
In order to prevent this, the color change must be hidden in a robust macro (or some macro prepended with protect
, but that might get tedious:
E.g.
newrobustcmd{redtext}[1]{%
textcolor{red}{#1}%
}
defines a macro meant for red text.
Another possibility is using the optional argument of chapter
and omitting the color change there, but this will not colorize the text in the ToC.
Please be aware, that mixing too much colors in text may worsen readability.
documentclass{book}
usepackage{xcolor}
usepackage{etoolbox}
usepackage{blindtext}
usepackage[english]{babel}
newrobustcmd{redtext}[1]{%
textcolor{red}{#1}%
}
newrobustcmd{bluetext}[1]{%
textcolor{blue}{#1}%
}
begin{document}
tableofcontents
chapter{Lions and Birds redtext{(Document Form 1)}}
chapter{Cats and mice bluetext{(Document Form 2)}}
chapter[Cows and goats]{Cows and goats textcolor{brown}{(Document Form 3)}}
blindtext[5]
end{document}
The same cause why ref
or gls
in a chapter etc. title is problematic occurs with textcolor
: The macro MakeUppercase
for the chapter marks at the heading transforms textcolor{ref}{...}
into textcolor{RED}{...}
first, which is expanded to its final meaning, trying to apply an undefined (most likely) color named RED
.
In order to prevent this, the color change must be hidden in a robust macro (or some macro prepended with protect
, but that might get tedious:
E.g.
newrobustcmd{redtext}[1]{%
textcolor{red}{#1}%
}
defines a macro meant for red text.
Another possibility is using the optional argument of chapter
and omitting the color change there, but this will not colorize the text in the ToC.
Please be aware, that mixing too much colors in text may worsen readability.
documentclass{book}
usepackage{xcolor}
usepackage{etoolbox}
usepackage{blindtext}
usepackage[english]{babel}
newrobustcmd{redtext}[1]{%
textcolor{red}{#1}%
}
newrobustcmd{bluetext}[1]{%
textcolor{blue}{#1}%
}
begin{document}
tableofcontents
chapter{Lions and Birds redtext{(Document Form 1)}}
chapter{Cats and mice bluetext{(Document Form 2)}}
chapter[Cows and goats]{Cows and goats textcolor{brown}{(Document Form 3)}}
blindtext[5]
end{document}
edited Feb 2 at 9:51
answered Feb 2 at 9:45
user31729
1
Thanks, Christian! This works perfectly fine for me. Since I only plan to use two different colors in headings, defining two robust colors is no issue.
– Manuel
Feb 2 at 10:00
1
@Manuel: You can also use a macroformone
andformtwo
, which does the formatting of your forms without typing the(...)
as well and you can simply change the colors inside theform...
macros instead of switchingredtext
to another macro name -- this depends on your design whatform 1
andform 2
are supposed to do, however
– user31729
Feb 2 at 10:03
add a comment |
1
Thanks, Christian! This works perfectly fine for me. Since I only plan to use two different colors in headings, defining two robust colors is no issue.
– Manuel
Feb 2 at 10:00
1
@Manuel: You can also use a macroformone
andformtwo
, which does the formatting of your forms without typing the(...)
as well and you can simply change the colors inside theform...
macros instead of switchingredtext
to another macro name -- this depends on your design whatform 1
andform 2
are supposed to do, however
– user31729
Feb 2 at 10:03
1
1
Thanks, Christian! This works perfectly fine for me. Since I only plan to use two different colors in headings, defining two robust colors is no issue.
– Manuel
Feb 2 at 10:00
Thanks, Christian! This works perfectly fine for me. Since I only plan to use two different colors in headings, defining two robust colors is no issue.
– Manuel
Feb 2 at 10:00
1
1
@Manuel: You can also use a macro
formone
and formtwo
, which does the formatting of your forms without typing the (...)
as well and you can simply change the colors inside the form...
macros instead of switching redtext
to another macro name -- this depends on your design what form 1
and form 2
are supposed to do, however– user31729
Feb 2 at 10:03
@Manuel: You can also use a macro
formone
and formtwo
, which does the formatting of your forms without typing the (...)
as well and you can simply change the colors inside the form...
macros instead of switching redtext
to another macro name -- this depends on your design what form 1
and form 2
are supposed to do, however– user31729
Feb 2 at 10:03
add a comment |
May be I have missed something! I have just add usepackage{xcolor}
to the OP MWE preamble and I get this output:
documentclass{book}
usepackage[english]{babel}
usepackage{xcolor} % I add this line
begin{document}
chapter{Lions and Birds textcolor{red}{(Document Form 1)}}
end{document}
1
The issue is that the header uses an ALL-CAPS form of the chapter title and will try to find the colour RED, which does not exists. The problem only becomes apparent if you add a second page to the MWE so that you get a page with an actual header. (See also Christian's answer.)
– moewe
Feb 2 at 13:16
Thank you very much @moewe! Now I got it.
– Hafid Boukhoulda
Feb 2 at 13:25
Sorry, my bad. I should have included an additional page, in the original example (now edited).
– Manuel
Feb 2 at 13:26
1
@Manuel Note that a colour package (color
orxcolor
) is also needed (I edited it in). Please always test your MWEs before you submit them and make sure the show the same error you receive in your real document.
– moewe
Feb 2 at 13:30
Thanks, that's true. I did get an error, but it was not the same...
– Manuel
Feb 2 at 18:12
add a comment |
May be I have missed something! I have just add usepackage{xcolor}
to the OP MWE preamble and I get this output:
documentclass{book}
usepackage[english]{babel}
usepackage{xcolor} % I add this line
begin{document}
chapter{Lions and Birds textcolor{red}{(Document Form 1)}}
end{document}
1
The issue is that the header uses an ALL-CAPS form of the chapter title and will try to find the colour RED, which does not exists. The problem only becomes apparent if you add a second page to the MWE so that you get a page with an actual header. (See also Christian's answer.)
– moewe
Feb 2 at 13:16
Thank you very much @moewe! Now I got it.
– Hafid Boukhoulda
Feb 2 at 13:25
Sorry, my bad. I should have included an additional page, in the original example (now edited).
– Manuel
Feb 2 at 13:26
1
@Manuel Note that a colour package (color
orxcolor
) is also needed (I edited it in). Please always test your MWEs before you submit them and make sure the show the same error you receive in your real document.
– moewe
Feb 2 at 13:30
Thanks, that's true. I did get an error, but it was not the same...
– Manuel
Feb 2 at 18:12
add a comment |
May be I have missed something! I have just add usepackage{xcolor}
to the OP MWE preamble and I get this output:
documentclass{book}
usepackage[english]{babel}
usepackage{xcolor} % I add this line
begin{document}
chapter{Lions and Birds textcolor{red}{(Document Form 1)}}
end{document}
May be I have missed something! I have just add usepackage{xcolor}
to the OP MWE preamble and I get this output:
documentclass{book}
usepackage[english]{babel}
usepackage{xcolor} % I add this line
begin{document}
chapter{Lions and Birds textcolor{red}{(Document Form 1)}}
end{document}
answered Feb 2 at 12:33
Hafid BoukhouldaHafid Boukhoulda
4,7891625
4,7891625
1
The issue is that the header uses an ALL-CAPS form of the chapter title and will try to find the colour RED, which does not exists. The problem only becomes apparent if you add a second page to the MWE so that you get a page with an actual header. (See also Christian's answer.)
– moewe
Feb 2 at 13:16
Thank you very much @moewe! Now I got it.
– Hafid Boukhoulda
Feb 2 at 13:25
Sorry, my bad. I should have included an additional page, in the original example (now edited).
– Manuel
Feb 2 at 13:26
1
@Manuel Note that a colour package (color
orxcolor
) is also needed (I edited it in). Please always test your MWEs before you submit them and make sure the show the same error you receive in your real document.
– moewe
Feb 2 at 13:30
Thanks, that's true. I did get an error, but it was not the same...
– Manuel
Feb 2 at 18:12
add a comment |
1
The issue is that the header uses an ALL-CAPS form of the chapter title and will try to find the colour RED, which does not exists. The problem only becomes apparent if you add a second page to the MWE so that you get a page with an actual header. (See also Christian's answer.)
– moewe
Feb 2 at 13:16
Thank you very much @moewe! Now I got it.
– Hafid Boukhoulda
Feb 2 at 13:25
Sorry, my bad. I should have included an additional page, in the original example (now edited).
– Manuel
Feb 2 at 13:26
1
@Manuel Note that a colour package (color
orxcolor
) is also needed (I edited it in). Please always test your MWEs before you submit them and make sure the show the same error you receive in your real document.
– moewe
Feb 2 at 13:30
Thanks, that's true. I did get an error, but it was not the same...
– Manuel
Feb 2 at 18:12
1
1
The issue is that the header uses an ALL-CAPS form of the chapter title and will try to find the colour RED, which does not exists. The problem only becomes apparent if you add a second page to the MWE so that you get a page with an actual header. (See also Christian's answer.)
– moewe
Feb 2 at 13:16
The issue is that the header uses an ALL-CAPS form of the chapter title and will try to find the colour RED, which does not exists. The problem only becomes apparent if you add a second page to the MWE so that you get a page with an actual header. (See also Christian's answer.)
– moewe
Feb 2 at 13:16
Thank you very much @moewe! Now I got it.
– Hafid Boukhoulda
Feb 2 at 13:25
Thank you very much @moewe! Now I got it.
– Hafid Boukhoulda
Feb 2 at 13:25
Sorry, my bad. I should have included an additional page, in the original example (now edited).
– Manuel
Feb 2 at 13:26
Sorry, my bad. I should have included an additional page, in the original example (now edited).
– Manuel
Feb 2 at 13:26
1
1
@Manuel Note that a colour package (
color
or xcolor
) is also needed (I edited it in). Please always test your MWEs before you submit them and make sure the show the same error you receive in your real document.– moewe
Feb 2 at 13:30
@Manuel Note that a colour package (
color
or xcolor
) is also needed (I edited it in). Please always test your MWEs before you submit them and make sure the show the same error you receive in your real document.– moewe
Feb 2 at 13:30
Thanks, that's true. I did get an error, but it was not the same...
– Manuel
Feb 2 at 18:12
Thanks, that's true. I did get an error, but it was not the same...
– Manuel
Feb 2 at 18:12
add a comment |
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%2f473012%2fchange-font-within-chapter-title-e-g-first-part-black-second-red%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
2
This does not work because
MakeUppercase
(being used in a macro behindchapter
transformsred
toRED
, which is unknown, of course --textcolor
is no robust macro– user31729
Feb 2 at 9:41