0

I have struggle with changing the color of my chapter name and section name.

Here is my work

\documentclass[a4paper,12pt, twoside]{report}
\usepackage[utf8]{inputenc}
    \usepackage[english, vietnamese]{babel}
    \usepackage{wrapfig} 
    \usepackage[dvipsnames]{xcolor}
    \usepackage[top=2cm, bottom=2cm, left=2cm, right=2cm]{geometry}
    \usepackage{color,graphicx,multicol,hyperref,geometry,graphicx,amsmath,tikz,amssymb,pgf,tkz-tab,amsfonts,amsthm,array,fancyhdr}
    \usepackage{lipsum}
    \usepackage{amsxtra, latexsym, amscd, enumerate, ifthen, amstext}
    \usepackage{array, tabularx, longtable}
    \usepackage{mathrsfs}
    \usepackage[all]{xy}
    \usepackage{subcaption}
    \usepackage{csquotes}
    \usepackage{textcmds}
    \DeclareRobustCommand{\divby}{\mathrel{\vbox{\baselineskip.65ex\lineskiplimit0pt\hbox{.}\hbox{.}\hbox{.}}}}
    \DeclareGraphicsExtensions{.pdf,.jpg,.png,.bmp}
    \let\mod=\undefined
    \let\top=\undefined
     \DeclareMathOperator{\im}{Im}
     \DeclareMathOperator{\Ker}{Ker}
    \DeclareMathOperator{\rk}{rank} 
    
    \newtheorem{defi}{Definition}[section]
    \newtheorem{theo}[defi]{Theorem}
    \newtheorem{cor}[defi]{Corollary}
    \newtheorem{lem}{Lemma}[section]
    \newtheorem{prop}[defi]{Proposition}
    \newtheorem{exam}{Example}
    \newtheorem{rema}{Remark}[section]
    \newtheorem{construction}{Construction}[section]
    \newtheorem{prob}{Problem}[section]
    \newtheorem{ques}{Question}
    \newtheorem{exe}{Exercise}
    
    \newcommand{\Np}{\mathbb{N^*}}
    \newcommand{\C}{\mathbb{C}}
    \newcommand{\Z}{\mathbb{Z}}
    \newcommand{\N}{\mathbb{N}}
    \newcommand{\Q}{\mathbb{Q}} 
    \newcommand{\R}{\mathbb{R}} 
    \newcommand{\pr}{\textnormal{P}}
    \newcommand{\E}{\textnormal{E}}
    \renewcommand{\baselinestretch}{1.3}
    \newcommand{\parallelsum}{\mathbin{\!/\mkern-5mu/\!}}
    \newcommand{\B}{\hfill$\qedsymbol$}
    \usepackage{centernot} 
    \usepackage{indentfirst}
    \usepackage{setspace}
    \usepackage[shortlabels]{enumitem}
    %\setlist{leftmargin=5mm}
    %Tạo frame
    \usepackage[most]{tcolorbox}
    %\renewcommand\familydefault{\sfdefault}
    %san - mathversion
    %\DeclareMathVersion{sans}
    %\SetSymbolFont{operators}{sans}{OT1}{cmbr}{m}{n}
    %\SetSymbolFont{letters}{sans}{OML}{cmbrm}{m}{it}
    %\SetSymbolFont{symbols}{sans}{OMS}{cmbrs}{m}{n}
    %\SetMathAlphabet{\mathit}{sans}{OT1}{cmbr}{m}{sl}
    %\SetMathAlphabet{\mathbf}{sans}{OT1}{cmbr}{bx}{n}
    %\SetMathAlphabet{\mathtt}{sans}{OT1}{cmtl}{m}{n}
    %\SetSymbolFont{largesymbols}{sans}{OMX}{iwona}{m}{n}
    %\sffamily\mathversion{sans}
    \newtcolorbox[auto counter]{problem}[1][]{%
        enhanced,
        breakable,
        colback=white,
        colbacktitle=white,
        coltitle=black,
        fonttitle=\bfseries,
        boxrule=1.25pt,
        titlerule=.2pt,
        toptitle=3pt,
        bottomtitle=3pt,
        title=Problem~\thetcbcounter,
        #1}
    \newtcolorbox[auto counter]{activity}[1][]{%
        enhanced,
        breakable,
        colback=white,
        colbacktitle=white,
        coltitle=black,
        fonttitle=\bfseries,
        boxrule=1.25pt,
        titlerule=.2pt,
        toptitle=3pt,
        bottomtitle=3pt,
        title=Activity~\thetcbcounter,
        #1}
    \usepackage{fancyhdr,lipsum}
    \usepackage{pgfplots}
    \pgfplotsset{compat=1.15}
    \usepackage{mathrsfs}
    \usetikzlibrary{arrows}
    
    \pagestyle{fancy}
    \fancypagestyle{plain}{%
      \renewcommand{\headrulewidth}{0pt}%
      \fancyhf{}%
    }
    \renewcommand{\chaptermark}[1]{%
    \markboth{\bfseries\chaptername
    \ \thechapter.\ #1}{}}
    \fancyhead[R]{\bf \thepage}
    \fancyhead[L]{\leftmark}
    \fancyfoot{}
    
    \usepackage{titlesec}
    \titleformat{\chapter}[display]
      {\bfseries\huge}
      {\filright\huge\chaptertitlename~\thechapter}
      {0.5cm}
      {\titlerule[2.5pt]\vspace{0.1cm}\filright}
      [{\vspace{0.1cm}\titlerule[2.5pt]}]
    
    
    \begin{document}
    \chapter{chapter 1}
    \section{section 1}
    \newpage
    \chapter{chapter 2}
    \end{document}

The result is as follows

enter image description here

How can I change the color of Chapter 1, its title and the section title into blue but still keep the two horizontal lines above and below it? I tried the command \chapterfont{\color{blue}}, but the two lines would disappear. I am new with \LaTeX, so please help me. Thank you very much.

2
  • \documentclass{report} is missing from the code
    – anis
    Dec 9, 2022 at 14:36
  • Thank you. I have edited it.
    – Tom Howard
    Dec 9, 2022 at 14:40

1 Answer 1

1

edited to answer comments. This did it for me:

\titleformat{\chapter}[display]
{\bfseries\huge\color{blue}}
{\filright\huge\chaptertitlename~\thechapter}
{0.5cm}
{\color{black}\titlerule[2.5pt]\color{blue}\vspace{0.1cm}\filright}
[{\vspace{0.1cm}\color{black}\titlerule[2.5pt]}]

enter image description here

4
  • Is there any way to keep the black color for the two lines? Thank you.
    – Tom Howard
    Dec 9, 2022 at 14:42
  • I have changed it to basically alternate between \color{black} then \color{blue} then \color{black}
    – anis
    Dec 9, 2022 at 14:55
  • Thank you very much!
    – Tom Howard
    Dec 10, 2022 at 2:57
  • You may want to validate the answer to close the post.
    – anis
    Dec 10, 2022 at 8:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.