3

I am trying about section's in tcolorbox. My code is

\documentclass[a4paper,twoside,openright,11pt]{scrbook}
\usepackage[left=1cm,right=1cm,top=3cm,bottom=1.5cm,marginparwidth=6cm,marginparsep=.5cm,
outer=7.5cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{color}
\usepackage[svgnames]{xcolor}
\usepackage[listings,skins,breakable,hooks,theorems]{tcolorbox}
\usepackage{mhsetup}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{ifoddpage}
\usepackage{fancyhdr}
\usepackage{lipsum}

\pagestyle{fancy}
\fancyheadoffset[LE,RO]{\marginparsep+\marginparwidth}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{ #1}}
\fancyhf{}
\fancyhead[RO]{\textbf{\nouppercase{Section \thesection{}}\quad\textcolor{orange}{$\blacksquare$}\quad}\textit{\rightmark}\quad\quad\textcolor{blue}{\textbf\thepage}}
\fancyhead[LE]{\textcolor{blue}{\textbf\thepage}\textbf{\quad\quad\nouppercase{Chapter{ }\thechapter\quad\textcolor{orange}{$\blacksquare$}\quad}}\textit{\leftmark}}
\fancypagestyle{plain}{%
\fancyhead{} % get rid of headers
\renewcommand{\headrulewidth}{0pt}
}

\begin{document}
\chapter{Hello}
\lipsum[1-7]

\begin{tcolorbox}[enhanced,interior style={left color=red!20!yellow,right color=black!40!white},leftrule=0mm,frame hidden,left=0mm,right=0mm,top=-1mm,bottom=1mm,arc=2mm]\textit{\section{Coulomb’s Law}}
\end{tcolorbox}

\lipsum[1-7]

\begin{tcolorbox}[enhanced,interior style={left color=red!20!yellow,right color=black!40!white},leftrule=0mm,frame hidden,left=0mm,right=0mm,top=-1mm,bottom=1mm,arc=2mm]\textit{\section{Heron's Law}}
\end{tcolorbox}

\lipsum[1-7]
\section{Leva's Law}
\lipsum[1-7]
\end{document}

But, it doesn't display \section name, number... at header in \tcolorbox. In the other hand it does display \section name, number... at header in not \tcolorbox. That is, In the 3. page, section information is not displayed.

In the \section{Leva's Law} working but other sections not working. It may be the solution this problem?

...EDITED... Page 3 and page 4 good working.

enter image description here

But I wrote @Christian Hupfer's codes, displayed following the picture. Section 1.10 is not Test section.

enter image description here

1
  • The displayed headers on the pages originate from your setup of \fancy.... etc. tcolorbox has no information your section titles ahead, you must choose another way, e.g. via nameref!
    – user31729
    Sep 1, 2014 at 9:09

1 Answer 1

5

This solution uses a label for each section inside a tcolorbox, calling the title with \nameref*{}

\documentclass[a4paper,twoside,openright,11pt]{scrbook}
\usepackage{etoolbox}%
\usepackage[many]{tcolorbox}
\usepackage{fancyhdr}
\usepackage{ifthen}
\usepackage{lipsum}
\usepackage{nameref}%



\pagestyle{fancy}
\makeatletter
\newlength{\overhanglength}
\AtBeginDocument{%
\setlength{\overhanglength}{\marginparwidth}
\addtolength{\overhanglength}{\marginparsep}
\ifthenelse{\NOT\boolean{@mparswitch}\AND\boolean{@twoside}}
{\fancyhfoffset[RE,RO]{\overhanglength}}
{\fancyhfoffset[LE,RO]{\overhanglength}}
}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\fancyhf{} 
\ifthenelse{\boolean{@twoside}}{%
\fancyhead[LE]{\textit{\thepage\quad\S\quad\nouppercase{\leftmark}}}%
\fancyhead[RO]{\textit{\nouppercase{\rightmark}\quad\S\quad\thepage}}%
}{
\fancyhead[RE,RO]{\nouppercase{\rightmark}\quad\thepage}%
}
\makeatother
\tcbuselibrary{breakable}
\makeatletter
\def\tcb@parbox@use@false{%
\def\@parboxrestore{\linewidth\hsize\let\@parboxrestore=\tcb@parboxrestore}%
}
\makeatother

\begin{document}
\chapter{Hello}
\begin{tcolorbox}[parbox=false,title=\nameref*{section::number_one}]
\section{This section title is shown!} \label{section::number_one}%
abc\par cde
\end{tcolorbox}
\lipsum[1-20]
\section{Test} 
\begin{tcolorbox}[title=\nameref*{section::2}]%
\section{This section title is also shown!} \label{section::2}%
abc\par cde
\end{tcolorbox}
\lipsum[1-20]
\end{document}

enter image description here

6
  • Hupher, your source code it is not working in my computer. In the line \begin{tcolorbox}[parbox=false,title=\nameref*{section::number_one}] , it's take error Missing $ inserted . I'm erasing the asterix then code is working but not exactly. Always 1.2 Test writing in header. I did edited my question, added the about picture. I hope you good work.
    – Özgür
    Sep 2, 2014 at 22:45
  • My code works as expected. There are no error messages. Do you have the latest TexLive distribution? I update every day. If you edit your question, I can't do anything more, since you added not more code, especially about section numbers being 1.10 etc. while there are just three sections in your example
    – user31729
    Sep 3, 2014 at 6:21
  • Dear @Christian Hupfer, up to now I am grateful for you for all your helps. I am so sorry I got to spend your working time. I edited my question, because; it be clearly. I had no bad intention, indeed. Anymore, both I will work yours code and I will look answer or later again question. (Ubuntu12.04LTS - LaTeXila 2.4.0)
    – Özgür
    Sep 3, 2014 at 16:21
  • @Özgür: Sorry, I will look later on... I have been busy on other stuff
    – user31729
    Sep 5, 2014 at 19:56
  • you're welcome. Good luck your stuff. No problem.
    – Özgür
    Sep 5, 2014 at 20:03

You must log in to answer this question.

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