1

I have been using this code to put an image next to a chapter title in my TOC :

\DeclareRobustCommand\addimg[1]{\llap{\raisebox{-\dp\strutbox}{\includegraphics[height=\baselineskip]{#1} \kern20pt}}}

\chapter[\addimg{en.jpg}Machines d'audit et processus MCO et MCS]{Machines d'audit et processus MCO et MCS}

It works just fine but it's messing with my header as you can see here : enter image description here

I can't find a proper solution to keep my TOC as it is and remove the image (or maybe move it ?).

Here are my \fancyhead definition :

\pagestyle{fancy}
\fancyhead[LE]{\bf \changefont \leftmark} 
\fancyhead[RE]{\thepage}
\fancyhead[LO]{\thepage} 
\fancyhead[RO]{\bf \changefont \leftmark}

Thanks for any help !

MWE :

\documentclass[a4paper,openright]{book} 
\usepackage[utf8]{inputenc}  
\usepackage[T1]{fontenc}      % Format d'encodage
\usepackage[french]{babel}    % Langue français
\usepackage[left=2.5cm, right=2.5cm, top=2.5cm, bottom=2.5cm]{geometry}
\usepackage{multicol}
\usepackage[normalem]{ulem}
\usepackage{shorttoc}
\usepackage{nccrules}
\usepackage{eurosym}
\usepackage{enumerate}
\usepackage{tablists}
\usepackage{multirow}
\usepackage{array}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage{longtable}
\usepackage[labelsep=endash]{caption}
\usepackage{arydshln}
\usepackage{hhline}
\usepackage{shapepar}
\usepackage{fancyhdr}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{titlesec}
\usepackage[obeyspaces]{url}
\usepackage{esint} 
\usepackage{varioref}
\usepackage{caption}
\usepackage{textcomp}
\usepackage{sistyle}
\usepackage[titletoc]{appendix}
\usepackage{tikz}
\usepackage[bookmarks=true]{hyperref}
\usepackage{rotating}
\usepackage{csquotes}
\usepackage[backend=biber,style=numeric,sorting=none]{biblatex}
\usepackage{xspace}
\usepackage{floatrow}
\usepackage{placeins}
\usepackage{caption}


\DeclareRobustCommand\addimg[1]{\llap{\raisebox{-\dp\strutbox}{\includegraphics[height=\baselineskip]{#1} \kern20pt}}}

% Table float box with bottom caption, box width adjusted to content
\newfloatcommand{capbtabbox}{table}[][\FBwidth]


\setcounter{tocdepth}{2}

\usetikzlibrary{arrows,shapes,positioning,shadows,trees}
\tikzset{
  basic/.style  = {draw, text width=2cm, drop shadow, font=\sffamily, rectangle},
  root/.style   = {basic, rounded corners=2pt, thin, align=center, fill=green!30},
  level 2/.style = {basic, rounded corners=6pt, thin,align=center, fill=green!60, text width=8em},
  level 3/.style = {basic, thin, align=left, fill=pink!60, text width=6.5em}
}

\newcommand{\addstufftotoc}[2][toc]{% \addimagetotoc[<toc>]{<stuff>}
  \addtocontents{#1}{#2}}

\newcommand{\changefont}{
\fontsize{11}{13}\selectfont
}

\pagestyle{fancy}
\fancyhead[LE]{\bf \changefont \leftmark} 
\fancyhead[RE]{\thepage}
\fancyhead[LO]{\thepage} 
\fancyhead[RO]{\bf \changefont \leftmark}

\fancyfoot{}
\fancypagestyle{nofooter}{%
    \renewcommand{\headrulewidth}{0pt}
    \fancyhead{}
    \fancyfoot{}%
}
\fancypagestyle{noheader}{%
    \renewcommand{\headrulewidth}{0pt}
    \fancyhead{}
    \fancyfoot{}%
}

\titleformat{\chapter}[frame]
{\normalsize}%
{\filright\sffamily\bfseries\Large%
\enspace Chapitre \thechapter\enspace}%
{8pt}
{\rule{0pt}{30pt}\sffamily\Huge\bfseries\filcenter}%

\titleformat{\part}[display]
  {\centering\sffamily\huge}
  {\partname}
  {20pt}
  {\Huge}
  
\setlength{\headheight}{15pt}

\begin{document}

\tableofcontents

\chapter[\addimg{en.jpg}Machines d'audit et processus MCO et MCS]{Machines d'audit et processus MCO et MCS \label{chap:Machinesaudit}}

test
\pagebreak
test

\end{document}
6
  • 1
    could you upload code as MWE so that we can compile it and see the problem
    – js bibra
    Sep 13, 2020 at 14:33
  • I've updated with MWE, it should work
    – Hekmil
    Sep 13, 2020 at 14:40
  • 1
    works fine - no messing with headers -- did you compile the above code -- did it reproduce your problem
    – js bibra
    Sep 13, 2020 at 14:51
  • My bad it's messing with the header only for the pages after the title of the chapter, so adding text or lipsum
    – Hekmil
    Sep 13, 2020 at 15:06
  • Updated with \pagebreak
    – Hekmil
    Sep 13, 2020 at 15:12

1 Answer 1

0

Untested, but this should work:

\fancyhead[LE]{\renewcommand{\addimg}[1]{}\bf \changefont \leftmark} 
\fancyhead[RE]{\thepage}
\fancyhead[LO]{\thepage} 
\fancyhead[RO]{\renewcommand{\addimg}[1]{}\bf \changefont \leftmark}
1
  • Hum, doesn't change anything for me
    – Hekmil
    Sep 13, 2020 at 16:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .