# rounded rectangle with tikzpicture: oval not round

here's my MWE:

\documentclass{book}
\usepackage{lipsum}
\usepackage{fmtcount}
\usepackage[many]{tcolorbox}
\usepackage{calc}
\usetikzlibrary{positioning,shapes.misc,calc}
\usepackage[scale=1,angle=0,opacity=1]{background}
\usepackage{ifthen}
\usepackage{xcolor}

\definecolor{mp}{RGB}{240,240,240}

\SetBgScale{1}
\SetBgAngle{0}
\SetBgOpacity{1}
\SetBgContents{}

\newcounter{partshift}
\newcommand{\maxpart}{9}

\makeatletter
\newcommand{\parttitle}{}
\def\@part[#1]#2{%
\renewcommand{\parttitle}{#1}\pf
\ifnum \c@secnumdepth >-2\relax
\refstepcounter{part}%
\else
\fi
\markboth{}{}%
{\centering
\interlinepenalty \@M
\normalfont
\ifnum \c@secnumdepth >-2\relax
\huge\Ordinalstring{part}\nobreakspace\partname
\par
\vskip 20\p@
\fi
\bfseries\color{gray}\fontsize{28}{30}\selectfont #2\par}%
\@endpart}

\newcommand\pf{%
\ifthenelse{\isodd{\thepage}}
{\SetBgContents{%
\begin{tikzpicture}[overlay,remember picture]
\node[
fill=mp,
inner sep=0pt,
rounded rectangle,
text width=5mm,
text height=\paperheight/\maxpart,
align=center,
anchor=north east] at
($(current page.north east) + (1mm,-\thepartshift*\paperheight/\maxpart)$){};
\end{tikzpicture}}%
}
{\SetBgContents{%
\begin{tikzpicture}[overlay,remember picture]
\node[
fill=mp,
inner sep=0pt,
rounded rectangle,
text width=5mm,
text height=\paperheight/\maxpart,
align=center,
anchor=north west] at
($(current page.north west) + (-1mm,-\thepartshift*\paperheight/\maxpart)$){};
\end{tikzpicture}}
}
\bg@material}%
\stepcounter{partshift}
}
\makeatother

\begin{document}

\part{A}
\chapter{a1}

\part{B}
\chapter{b1}
\lipsum[1-7]

\part{C}
\chapter{c1}
\lipsum[1-7]

\end{document}


I'd like to make it look like the right one

How can I do that?

-
Can you please describe in a little more detail what exactly do you want? Do you want all your pages to have a decoration like the one on the image to the right? The decoration is just the oval figure or also the darker stripe extending all the paper height? – Gonzalo Medina Apr 30 '14 at 2:18
I just added one more picture. I just want to change the shape to look like a real rounded rectangle (and not a circle) – Moldevort Apr 30 '14 at 2:20
why are you using the old syntax for background? What version of the package are you using? By the way, I posted an answer drawing the exact shape required, in case you are interested. – Gonzalo Medina Apr 30 '14 at 2:51
What old syntax do you mean? It is working, the way I posted and Harish Kumar replied. Is there any reason, I should use the new one? – Moldevort Apr 30 '14 at 12:59
The \SetBg... family of commands were the ones I used for the first versions of the package; since version 2.0 I changed to a more convenient syntax using a key=value mechanism (in my answer you can see the code using the new syntax). The old commands are still fully functional though, but modern document should use the new syntax. (Cont.) – Gonzalo Medina Apr 30 '14 at 17:23

You can use

            rectangle,


to get it. I have also increased the minimum width and the coordinates as in

 minimum width=1cm,
.
.
anchor=north east] at
($(current page.north east) + (5mm,-\thepartshift*\paperheight/\maxpart)$){};


Note 5mm and -5mm (in even page). You may adjust these values accordingly.

\documentclass{book}
\usepackage{lipsum}
\usepackage{fmtcount}
\usepackage[many]{tcolorbox}
\usepackage{calc}
\usetikzlibrary{positioning,shapes.misc,calc}
\usepackage[scale=1,angle=0,opacity=1]{background}
\usepackage{ifthen}
\usepackage{xcolor}

\definecolor{mp}{RGB}{240,240,240}

\SetBgScale{1}
\SetBgAngle{0}
\SetBgOpacity{1}
\SetBgContents{}

\newcounter{partshift}
\newcommand{\maxpart}{9}

\makeatletter
\newcommand{\parttitle}{}
\def\@part[#1]#2{%
\renewcommand{\parttitle}{#1}\pf
\ifnum \c@secnumdepth >-2\relax
\refstepcounter{part}%
\else
\fi
\markboth{}{}%
{\centering
\interlinepenalty \@M
\normalfont
\ifnum \c@secnumdepth >-2\relax
\huge\Ordinalstring{part}\nobreakspace\partname
\par
\vskip 20\p@
\fi
\bfseries\color{gray}\fontsize{28}{30}\selectfont #2\par}%
\@endpart}

\newcommand\pf{%
\ifthenelse{\isodd{\thepage}}
{\SetBgContents{%
\begin{tikzpicture}[overlay,remember picture]
\node[
fill=mp,
inner sep=0pt,
rectangle,
rounded corners=2ex,
text width=5mm,
minimum width=1cm,
text height=\paperheight/\maxpart,
align=center,
anchor=north east] at
($(current page.north east) + (5mm,-\thepartshift*\paperheight/\maxpart)$){};
\end{tikzpicture}}%
}
{\SetBgContents{%
\begin{tikzpicture}[overlay,remember picture]
\node[
fill=mp,
inner sep=0pt,
rectangle,
rounded corners=2ex,
text width=5mm,
minimum width=1cm,
text height=\paperheight/\maxpart,
align=center,
anchor=north west] at
($(current page.north west) + (-5mm,-\thepartshift*\paperheight/\maxpart)$){};
\end{tikzpicture}}
}
\bg@material}%
\stepcounter{partshift}
}
\makeatother

\begin{document}

\part{A}
\chapter{a1}

\part{B}
\chapter{b1}
\lipsum[1-7]

\part{C}
\chapter{c1}
\lipsum[1-7]

\end{document}


-

Here's a solution which doesn't imply guessing lengths and draws the exact required shape (This other answer just draws a full rectangle but half of it falls outside the page). This solution also uses the new syntax for the background package:

\documentclass{book}
\usepackage{lipsum}
\usepackage{fmtcount}
\usepackage[many]{tcolorbox}
\usepackage{calc}
\usetikzlibrary{positioning,shapes.misc,calc}
\usetikzlibrary{chains,qrr.shapes.openrectangle}
\usepackage[scale=1,angle=0,opacity=1,contents={}]{background}
\usepackage{xcolor}

\definecolor{mp}{RGB}{240,240,240}

\newcounter{partshift}
\newcommand{\maxpart}{9}

\makeatletter
\newcommand{\parttitle}{}
\def\@part[#1]#2{%
\renewcommand{\parttitle}{#1}\pf
\ifnum \c@secnumdepth >-2\relax
\refstepcounter{part}%
\else
\fi
\markboth{}{}%
{\centering
\interlinepenalty \@M
\normalfont
\ifnum \c@secnumdepth >-2\relax
\huge\Ordinalstring{part}\nobreakspace\partname
\par
\vskip 20\p@
\fi
\bfseries\color{gray}\fontsize{28}{30}\selectfont #2\par}%
\@endpart}

\newcommand\pf{%
\ifodd\value{page}\relax
\backgroundsetup{contents={%
\begin{tikzpicture}[overlay,remember picture]
\node[
shape=open rectangle,
rounded corners=20pt,
open rectangle fill=mp,
open rectangle sides=nws,
align=center,
inner sep=0pt,
text width=10mm,
text height=\paperheight/\maxpart,
anchor=north east,
] at
( $(current page.north east) + (1mm,-\thepartshift*\paperheight/\maxpart)$){};
\end{tikzpicture}}}%
\else
\backgroundsetup{contents={%
\begin{tikzpicture}[overlay,remember picture]
\node[
shape=open rectangle,
rounded corners=20pt,
open rectangle fill=mp,
open rectangle sides=ens,
text width=10mm,
text height=\paperheight/\maxpart,
align=center,
anchor=north west
] at
($(current page.north west) + (-1mm,-\thepartshift*\paperheight/\maxpart)$){};
\end{tikzpicture}}}
\fi
\BgMaterial}%
\stepcounter{partshift}
}
\makeatother

\begin{document}

\part{A}
\chapter{a1}

\part{B}
\chapter{b1}
\lipsum[1-7]

\part{C}
\chapter{c1}
\lipsum[1-7]

\end{document}


The code used the libraries:

written by Qrrbrbirlbel.

Following the links, download the files and save them somewhere TeX can find them (the current working directory is the easiest place).

-