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












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.



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










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

    – user31729
    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.



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










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

    – user31729
    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.



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










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.



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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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
















  • 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










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












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





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

    – user31729
    Feb 2 at 10:03



















0














May be I have missed something! I have just add usepackage{xcolor} to the OP MWE preamble and I get this output:



enter image description here



documentclass{book}
usepackage[english]{babel}
usepackage{xcolor} % I add this line

begin{document}
chapter{Lions and Birds textcolor{red}{(Document Form 1)}}

end{document}





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





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

    – user31729
    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 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}





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

    – user31729
    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 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}





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






share|improve this answer














share|improve this answer



share|improve this answer








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














  • 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

    – 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











0














May be I have missed something! I have just add usepackage{xcolor} to the OP MWE preamble and I get this output:



enter image description here



documentclass{book}
usepackage[english]{babel}
usepackage{xcolor} % I add this line

begin{document}
chapter{Lions and Birds textcolor{red}{(Document Form 1)}}

end{document}





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 usepackage{xcolor} to the OP MWE preamble and I get this output:



enter image description here



documentclass{book}
usepackage[english]{babel}
usepackage{xcolor} % I add this line

begin{document}
chapter{Lions and Birds textcolor{red}{(Document Form 1)}}

end{document}





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 usepackage{xcolor} to the OP MWE preamble and I get this output:



enter image description here



documentclass{book}
usepackage[english]{babel}
usepackage{xcolor} % I add this line

begin{document}
chapter{Lions and Birds textcolor{red}{(Document Form 1)}}

end{document}





share|improve this answer













May be I have missed something! I have just add usepackage{xcolor} to the OP MWE preamble and I get this output:



enter image description here



documentclass{book}
usepackage[english]{babel}
usepackage{xcolor} % I add this line

begin{document}
chapter{Lions and Birds textcolor{red}{(Document Form 1)}}

end{document}






share|improve this answer












share|improve this answer



share|improve this answer










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

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

Npm cannot find a required file even through it is in the searched directory