Change font within Chapter Title - e.g. first part black, second red

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












3















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.



documentclassbook
usepackage[english]babel
usepackagexcolor

begindocument
chapterLions and Birds textcolorred(Document Form 1)
%
newpage
%
chapterAlligators and Storks textcolorred(Document Form 1)
enddocument


Thanks in advance and best regards, Manuel










share|improve this question



















  • 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

    – Christian Hupfer
    Feb 2 at 9:41
















3















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.



documentclassbook
usepackage[english]babel
usepackagexcolor

begindocument
chapterLions and Birds textcolorred(Document Form 1)
%
newpage
%
chapterAlligators and Storks textcolorred(Document Form 1)
enddocument


Thanks in advance and best regards, Manuel










share|improve this question



















  • 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

    – Christian Hupfer
    Feb 2 at 9:41














3












3








3








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.



documentclassbook
usepackage[english]babel
usepackagexcolor

begindocument
chapterLions and Birds textcolorred(Document Form 1)
%
newpage
%
chapterAlligators and Storks textcolorred(Document Form 1)
enddocument


Thanks in advance and best regards, Manuel










share|improve this question
















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.



documentclassbook
usepackage[english]babel
usepackagexcolor

begindocument
chapterLions and Birds textcolorred(Document Form 1)
%
newpage
%
chapterAlligators and Storks textcolorred(Document Form 1)
enddocument


Thanks in advance and best regards, Manuel







fonts sectioning color






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 2 at 13:29









moewe

91.6k10114347




91.6k10114347










asked Feb 2 at 9:37









ManuelManuel

656




656







  • 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

    – Christian Hupfer
    Feb 2 at 9:41













  • 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

    – Christian Hupfer
    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

– Christian Hupfer
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

– Christian Hupfer
Feb 2 at 9:41











2 Answers
2






active

oldest

votes


















5














enter image description here



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 textcolorref... into textcolorRED... 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.



newrobustcmdredtext[1]%
textcolorred#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.



documentclassbook
usepackagexcolor
usepackageetoolbox
usepackageblindtext
usepackage[english]babel

newrobustcmdredtext[1]%
textcolorred#1%


newrobustcmdbluetext[1]%
textcolorblue#1%



begindocument
tableofcontents

chapterLions and Birds redtext(Document Form 1)

chapterCats and mice bluetext(Document Form 2)

chapter[Cows and goats]Cows and goats textcolorbrown(Document Form 3)

blindtext[5]

enddocument





share|improve this answer




















  • 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 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

    – Christian Hupfer
    Feb 2 at 10:03


















0














May be I have missed something! I have just add usepackagexcolor to the OP MWE preamble and I get this output:



enter image description here



documentclassbook
usepackage[english]babel
usepackagexcolor % I add this line

begindocument
chapterLions and Birds textcolorred(Document Form 1)

enddocument





share|improve this answer


















  • 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 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










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
);



);













draft saved

draft discarded


















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









5














enter image description here



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 textcolorref... into textcolorRED... 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.



newrobustcmdredtext[1]%
textcolorred#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.



documentclassbook
usepackagexcolor
usepackageetoolbox
usepackageblindtext
usepackage[english]babel

newrobustcmdredtext[1]%
textcolorred#1%


newrobustcmdbluetext[1]%
textcolorblue#1%



begindocument
tableofcontents

chapterLions and Birds redtext(Document Form 1)

chapterCats and mice bluetext(Document Form 2)

chapter[Cows and goats]Cows and goats textcolorbrown(Document Form 3)

blindtext[5]

enddocument





share|improve this answer




















  • 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 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

    – Christian Hupfer
    Feb 2 at 10:03















5














enter image description here



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 textcolorref... into textcolorRED... 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.



newrobustcmdredtext[1]%
textcolorred#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.



documentclassbook
usepackagexcolor
usepackageetoolbox
usepackageblindtext
usepackage[english]babel

newrobustcmdredtext[1]%
textcolorred#1%


newrobustcmdbluetext[1]%
textcolorblue#1%



begindocument
tableofcontents

chapterLions and Birds redtext(Document Form 1)

chapterCats and mice bluetext(Document Form 2)

chapter[Cows and goats]Cows and goats textcolorbrown(Document Form 3)

blindtext[5]

enddocument





share|improve this answer




















  • 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 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

    – Christian Hupfer
    Feb 2 at 10:03













5












5








5







enter image description here



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 textcolorref... into textcolorRED... 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.



newrobustcmdredtext[1]%
textcolorred#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.



documentclassbook
usepackagexcolor
usepackageetoolbox
usepackageblindtext
usepackage[english]babel

newrobustcmdredtext[1]%
textcolorred#1%


newrobustcmdbluetext[1]%
textcolorblue#1%



begindocument
tableofcontents

chapterLions and Birds redtext(Document Form 1)

chapterCats and mice bluetext(Document Form 2)

chapter[Cows and goats]Cows and goats textcolorbrown(Document Form 3)

blindtext[5]

enddocument





share|improve this answer















enter image description here



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 textcolorref... into textcolorRED... 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.



newrobustcmdredtext[1]%
textcolorred#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.



documentclassbook
usepackagexcolor
usepackageetoolbox
usepackageblindtext
usepackage[english]babel

newrobustcmdredtext[1]%
textcolorred#1%


newrobustcmdbluetext[1]%
textcolorblue#1%



begindocument
tableofcontents

chapterLions and Birds redtext(Document Form 1)

chapterCats and mice bluetext(Document Form 2)

chapter[Cows and goats]Cows and goats textcolorbrown(Document Form 3)

blindtext[5]

enddocument






share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 2 at 9:51

























answered Feb 2 at 9:45









Christian HupferChristian Hupfer

151k15199394




151k15199394







  • 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 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

    – Christian Hupfer
    Feb 2 at 10:03












  • 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 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

    – Christian Hupfer
    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

– Christian Hupfer
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

– Christian Hupfer
Feb 2 at 10:03











0














May be I have missed something! I have just add usepackagexcolor to the OP MWE preamble and I get this output:



enter image description here



documentclassbook
usepackage[english]babel
usepackagexcolor % I add this line

begindocument
chapterLions and Birds textcolorred(Document Form 1)

enddocument





share|improve this answer


















  • 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 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















0














May be I have missed something! I have just add usepackagexcolor to the OP MWE preamble and I get this output:



enter image description here



documentclassbook
usepackage[english]babel
usepackagexcolor % I add this line

begindocument
chapterLions and Birds textcolorred(Document Form 1)

enddocument





share|improve this answer


















  • 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 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













0












0








0







May be I have missed something! I have just add usepackagexcolor to the OP MWE preamble and I get this output:



enter image description here



documentclassbook
usepackage[english]babel
usepackagexcolor % I add this line

begindocument
chapterLions and Birds textcolorred(Document Form 1)

enddocument





share|improve this answer













May be I have missed something! I have just add usepackagexcolor to the OP MWE preamble and I get this output:



enter image description here



documentclassbook
usepackage[english]babel
usepackagexcolor % I add this line

begindocument
chapterLions and Birds textcolorred(Document Form 1)

enddocument






share|improve this answer












share|improve this answer



share|improve this answer










answered Feb 2 at 12:33









Hafid BoukhouldaHafid Boukhoulda

3,9921624




3,9921624







  • 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 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












  • 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 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







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

















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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






Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay