Page LayoutMoving box with chapter number on margin

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
bartzmc
Posts: 10
Joined: Thu Apr 06, 2017 9:15 pm

Moving box with chapter number on margin

Post by bartzmc »

Hi,
I need to make some sort of moving shape with chapter number inside which will be moving with scrolling pages on twosided document.
Something like this:
page.jpg
page.jpg (147.34 KiB) Viewed 3867 times
Which package can provide me some help to implement this or it is even possible to do this?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Moving box with chapter number on margin

Post by Stefan Kottwitz »

Welcome to the forum!

This looks like a job for chapterthumbs.

Stefan
LaTeX.org admin
bartzmc
Posts: 10
Joined: Thu Apr 06, 2017 9:15 pm

Moving box with chapter number on margin

Post by bartzmc »

Thanks, it should work but I need more help to adjust some things.
I'm using phd report class and I had to use scrpage2 instead fancyhdr.
This is result: http://i.imgur.com/vB4upJm.jpg
Box is static, does not move with scrolling pages, it shows only 0 in TOC and 1 on every odd page, does not change to 2nd chapter and it is in wrong place on the left from page number. I marked where I want it to be.
Code:

Code: Select all

%########################################
\documentclass[a4paper,12pt,twoside,openright]{phd}
\usepackage{sectsty}
\chapterfont{\centering}
\sectionfont{\centering}
\subsectionfont{\centering}
\indexsetup{othercode=\small}
\makeindex[program=makeindex,columns=2,intoc=true,options={-s indeks-styl.ist}]
\makeatletter
\renewcommand{\@seccntformat}[1]{}
\renewcommand{\numberline}[1]{}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Chapter thumbs with scrpage2
%
 
% Safty first
\@ifundefined{chapter}{\let\chapter\undefined
   \chapter must be defined to use chapter thumbs!}{%
 
% Two new commands for the width and height of the boxes with the
% chapter number at the thumbs (use of commands instead of lengths
% for sparing registers)
\newcommand*{\chapterthumbwidth}{2em}
\newcommand*{\chapterthumbheight}{1em}
 
% Two new commands for the colors of the box background and the
% chapter numbers of the thumbs
\newcommand*{\chapterthumbboxcolor}{black}
\newcommand*{\chapterthumbtextcolor}{white}
 
% New command to set a chapter thumb. I'm using a group at this
% command, because I'm changing the temporary dimension \@tempdima
\newcommand*{\putchapterthumb}{%
   \begingroup
     \Large
     % calculate the horizontal possition of the right paper border
     % (I ignore \hoffset, because I interprete \hoffset moves the page
     % at the paper e.g. if you are using cropmarks)
     \setlength{\@tempdima}{\@oddheadshift}% (internal from scrpage2)
     \setlength{\@tempdima}{-\@tempdima}%
     \addtolength{\@tempdima}{\paperwidth}%
     \addtolength{\@tempdima}{-\oddsidemargin}%
     \addtolength{\@tempdima}{-1in}%
     % putting the thumbs should not change the horizontal
     % possition
     \rlap{%
       % move to the calculated horizontal possition
       \hspace*{\@tempdima}%
       % putting the thumbs should not change the vertical
       % possition
       \vbox to 0pt{%
         % calculate the vertical possition of the thumbs (I ignore
         % \voffset for the same reasons told above)
         \setlength{\@tempdima}{\chapterthumbwidth}%
         \multiply\@tempdima by\value{chapter}%
         \addtolength{\@tempdima}{-\chapterthumbwidth}%
         \addtolength{\@tempdima}{-\baselineskip}%
         % move to the calculated vertical possition
         \vspace*{\@tempdima}%
         % put the thumbs left so the current horizontal possition
         \llap{%
           % and rotate them
           \rotatebox{90}{\colorbox{\chapterthumbboxcolor}{%
               \parbox[c][\chapterthumbheight][c]{\chapterthumbwidth}{%
                 \centering
                 \textcolor{\chapterthumbtextcolor}{%
                   \strut\thechapter}\\
               }%
             }%
           }%
         }%
         % avoid overfull \vbox messages
         \vss
       }%
     }%
   \endgroup
}
 
% New command, which works like \lohead but also puts the thumbs (you
% cannot use \ihead with this definition but you may change this, if
% you use more internal scrpage2 commands)
\newcommand*{\loheadwithchapterthumbs}[2][]{%
   \lohead[\putchapterthumb#1]{\putchapterthumb#2}%
}
 
% initial use
\loheadwithchapterthumbs{}
\pagestyle{scrheadings}
 
}
%
%  End of chapter thumbs with scrpage2
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatother

%########################################

\begin{document}

\cleardoublepage
\tableofcontents
\input{kodeks}
\section{DZIAŁ I. PRZEPISY OGÓLNE}
\input{dz1roz1}
\input{dz1roz2}
\input{dz1roz3}
\input{dz1roz4}
\input{dz1roz5}
\input{dz1roz6}
\input{dz1roz7}
\input{dz1roz8}
\input{dz1roz9}
\input{dz1roz10}
\section{DZIAŁ II. POSTĘPOWANIE}
\input{dz2roz1}
\input{dz2roz2}
\setcounter{secnumdepth}{0}
\addcontentsline{toc}{section}{INDEKS}
\printindex 
\end{document}
bartzmc
Posts: 10
Joined: Thu Apr 06, 2017 9:15 pm

Moving box with chapter number on margin

Post by bartzmc »

I come up with other solution but it also needs to be modified.
It looks like https://i.imgur.com/Fbtxy2W.jpg
The problem is that chapter thumb does not increment down the page as dictated by the chapters and I want it to be placed where I marked.

Code: Select all

\documentclass[a4paper,12pt,twoside,openright]{phd}
\usepackage{sectsty}
\chapterfont{\centering}
\sectionfont{\centering}
\subsectionfont{\centering}
\indexsetup{othercode=\small}
\makeindex[program=makeindex,columns=2,intoc=true,options={-s indeks-styl.ist}]
\makeatletter
\renewcommand{\@seccntformat}[1]{}
\renewcommand{\numberline}[1]{}
%======================================================================================
%   CHAPTER THUMB
%======================================================================================

\pagestyle{plain}

% auxiliary counter
\newcounter{chapshift}
\addtocounter{chapshift}{-1}

% the list of colors to be used (add more if needed)
\newcommand\BoxColor{%
  %\ifcase\thechapshift blue!30\or red!30\or olive!30\or magenta!30\else yellow!30\fi}
  ultramarine}


% redefinition of \chaptermark to contain only the title
\renewcommand\chaptermark[1]{\markboth{\thechapter.~#1}{}}


\makeatletter
\newcommand\ChapterBox{%
\begin{tikzpicture}[overlay,remember picture]
  \node[fill=\BoxColor,inner sep=0pt,rectangle,text width=1cm,
    text height=4cm,align=center,anchor=north east]
  at ($ (current page.north east) + (-0cm,-2*\thechapshift cm) $)
  {\rotatebox{90}{\parbox{4cm}{%
    \centering\textcolor{white}{\scshape\@chapapp~\thechapter}}}};
  \end{tikzpicture}%
}
\makeatother
%======================================================================================
%   PAGE HEADERS
%======================================================================================

\usepackage{etoolbox,fancyhdr} % Required for header and footer configuration

\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{{\sffamily\normalsize\bfseries \ #1}}{}} % Chapter text font settings
\renewcommand{\sectionmark}[1]{\markright{{\sffamily\normalsize\thesection\hspace{5pt}#1}}{}} % Section text font settings
\fancyhf{} \fancyhead[LE,RO]{\sffamily\normalsize\thepage} % Font setting for the page number in the header
\fancyhead[LO]{\rightmark\ChapterBox} % Print the nearest section name on the left side of odd pages
\fancyhead[RE]{\leftmark\ChapterBox} % Print the current chapter name on the right side of even pages
\renewcommand{\headrulewidth}{.5pt} % Width of the rule under the header
\addtolength{\headheight}{2.5pt} % Increase the spacing around the header slightly
\newcommand{\headrulecolor}[1]{\patchcmd{\headrule}{\hrule}{\color{#1}\hrule}{}{}}
\headrulecolor{blue!70}% Set header rule colour to 70% red.
\fancypagestyle{plain}{\fancyhead{}\renewcommand{\headrulewidth}{0pt}} % Style for when a plain pagestyle is specified

\fancypagestyle{plain}{%
  \fancyhf{}% Clear header/footer
  \renewcommand{\headrulewidth}{0pt}% No header rule
  \renewcommand{\footrulewidth}{0pt}% No footer rule
}

% Removes the header from odd empty pages at the end of chapters
\makeatletter
\renewcommand{\cleardoublepage}{
\clearpage\ifodd\c@page\else
\hbox{}
\vspace*{\fill}
\thispagestyle{empty}
\newpage
\fi}
\makeatother

%======================================================================================
%   CHAPTER HEADINGS
%======================================================================================

\usepackage[explicit]{titlesec}

\usepackage{xcolor} % Required for specifying colors by name
\definecolor{ocre}{RGB}{52,177,201}
\definecolor{ultramarine}{RGB}{0,45,97}
\definecolor{mybluei}{RGB}{0,173,239}
\definecolor{myblueii}{RGB}{63,200,244}
\definecolor{myblueiii}{RGB}{199,234,253}

\renewcommand\thechapter{\arabic{chapter}}

\newcommand\chapnumfont{% font specification for the number
  \fontsize{380}{130}\color{myblueii}\selectfont%
}

\newcommand\chapnamefont{% font specification for the name "PART"
  \normalfont\color{white}\scshape\small\bfseries
}

\titleformat{\chapter}
  {\normalfont\huge\filleft}
  {}
  {0pt}
  {\stepcounter{chapshift}%
  \begin{tikzpicture}[remember picture,overlay]
  \fill[myblueiii]
    (current page.north west) rectangle ([yshift=-13cm]current page.north east);
  \node[
      fill=mybluei,
      text width=2\paperwidth,
      rounded corners=6cm,
      text depth=18cm,
      anchor=center,
      inner sep=0pt] at (current page.north east) (chaptop)
    {\thechapter};%
    %{};%
  \node[
      anchor=south east,
      inner sep=0pt,
      outer sep=0pt] (chapnum) at ([xshift=-20pt]chaptop.south)
    {\chapnumfont\thechapter};
    %{};
  \node[
      anchor=south,
      inner sep=0pt] (chapname) at ([yshift=2pt]chapnum.south)
 %{\chapnamefont PROBLEM};
 {};
  \node[
      anchor=north east,
      align=right,
      inner xsep=0pt] at ([yshift=-0.5cm]chapname.east|-chapnum.south)
  {\parbox{.7\textwidth}{\raggedleft#1}};
  \end{tikzpicture}%
  }

\titleformat{name=\chapter,numberless}
  {\normalfont\huge\filleft}
  {}
  {0pt}
  {\begin{tikzpicture}[remember picture,overlay]
  \fill[myblueiii]
    (current page.north west) rectangle ([yshift=-13cm]current page.north east);
  \node[
      fill=mybluei,
      text width=2\paperwidth,
      rounded corners=6cm,
      text depth=18cm,
      anchor=center,
      inner sep=0pt] at (current page.north east) (chaptop)
    {};%
  \node[
      anchor=south east,minimum width=2in,
      inner sep=0pt,
      outer sep=0pt] (chapnum) at ([xshift=-20pt]chaptop.south)
    {};
  \node[
      anchor=south,
      inner sep=0pt] (chapname) at ([yshift=2pt]chapnum.south)
  {};
  \node[
      anchor=north east,
      align=right,
      inner xsep=0pt] at ([yshift=-0.5cm]chapname.east|-chapnum.south)
  {\parbox{.7\textwidth}{\raggedleft#1}};
  \end{tikzpicture}%
  }

\titlespacing*{\chapter}{0pt}{0pt}{3.5in}
\titlespacing*{name=\chapter,numberless}{0pt}{0pt}{3.5in}



%########################################

\begin{document}

\cleardoublepage
\tableofcontents
\input{kodeks}
\section{DZIAŁ I. PRZEPISY OGÓLNE}
\input{dz1roz1}
\input{dz1roz2}
\input{dz1roz3}
\input{dz1roz4}
\input{dz1roz5}
\input{dz1roz6}
\input{dz1roz7}
\input{dz1roz8}
\input{dz1roz9}
\input{dz1roz10}
\section{DZIAŁ II. POSTĘPOWANIE}
\input{dz2roz1}
\input{dz2roz2}
\setcounter{secnumdepth}{0}
\addcontentsline{toc}{section}{INDEKS}
\printindex 
\end{document}
Post Reply