0

I'm looking to write the chapter number in roman using tikz.

I tried to double the rule, and add the tikz node, but it didn't work properly.

This is the example I'm aiming to ''resemble'', at least. enter image description here

The best I could get was this enter image description here

My code is somewhat elementary

\documentclass[12pt,a4paper]{report}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage[top=3cm,bottom=3cm,left=3cm,right=3cm,headheight=3cm,footskip=1cm,marginparwidth=2cm]{geometry}
\usepackage{fancyhdr}
\usepackage{lipsum}
\usepackage{mathpazo}
\usepackage{domitian}
\usepackage[T1]{fontenc}
\usepackage{setspace}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{subcaption}
\fancypagestyle{MyStyle}
{
\fancyhf{}
\fancyhead[L]{\slshape\leftmark}
\renewcommand{\headrulewidth}{2pt}
\fancyfoot[C]{\thepage}
\renewcommand{\footrulewidth}{2pt}
}
\let\oldstylenums\oldstyle

\begin{document}

\chapter{Klauss}

\begin{tikzpicture}[squarednode/.style={rectangle, draw=blue!60, fill=blue!5, very thick, minimum size=10mm}, ] \node[squarednode] (maintopic) {2}; \end{tikzpicture} \rule{\textwidth}{3pt}\vspace{-0.5cm} \rule{\textwidth}{3pt} \lipsum \end{document}

Some packages aren't related to this problem

Hamdiken
  • 143
  • First, check out https://tex.stackexchange.com/questions/23477/fancy-chapter-headings?r=SearchResults&s=2%7C89.1573, https://tex.stackexchange.com/questions/503083/fancy-chapter-headings-style?r=SearchResults&s=3%7C85.8461 and similar questions for ideas. – John Kormylo Mar 19 '23 at 23:23

1 Answers1

9

Edit: see below an updated code for new requirement asked by the OP.

Using my answer for a similar question (see https://tex.stackexchange.com/a/679614/132405), with few adaptations, I suggest you the code below.

I have kept the font provided by the package domitian from your code, for the title of the chapter.

I have removed the tikzlibrary positioning from your code, as it is unnecessary here.

\documentclass[12pt,a4paper]{report}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage[top=3cm,bottom=3cm,left=3cm,right=3cm,headheight=3cm,footskip=1cm,marginparwidth=2cm]{geometry}
\usepackage{fancyhdr}
\usepackage{lipsum}
\usepackage{mathpazo}
\usepackage{domitian}
\usepackage[T1]{fontenc}
\usepackage{setspace}
\usepackage{tikz}

\usepackage{subcaption} \fancypagestyle{MyStyle} { \fancyhf{} \fancyhead[L]{\slshape\leftmark} \renewcommand{\headrulewidth}{2pt} \fancyfoot[C]{\thepage} \renewcommand{\footrulewidth}{2pt} } \let\oldstylenums\oldstyle

\definecolor{myBlue}{rgb}{0,0.32,0.6}

\usepackage{titlesec} % formatting of the chapter title (number+text) \titleformat{\chapter}% sectionning type to customize [display]% shape, here number and title text on separate lines {\normalfont\bfseries\color{myBlue}}%format {\numberChapter}% formatting code of the section (here chapter) number. {1em}% in "display" shape, the distance between the "number" and the "title" {\titlerule[2.5pt]\vspace{3pt}\titlerule\vspace{4pt}\LARGE}% code before the title text. Here for rules and the title format.

% Setting of the space before and after the title \titlespacing{\chapter}% Place the chapter block almost at top of the page {0pt}% space added at left {20pt}% vertical space added before {20pt}% vertical space added after (space between chapter title and section title, for example)

\usepackage{etoolbox} % to correct a bug, so the chapter block is really a the top of the page (see https://tex.stackexchange.com/questions/59389/package-titlesec-adds-extra-space-on-top-of-chapter-despite-commands-to-the-co/59392#59392) \makeatletter % the macro name contains @ \patchcmd{\ttl@mkchap@i}{\vspace*{@tempskipa}}{}{}{} \makeatother

\usepackage{microtype} % for the \textls command

\newcommand{\numberChapter}{% \hspace*{\fill}\begin{tikzpicture} \node[% fill = myBlue, minimum width = 4cm, minimum height = 4cm, font = \color{white}\fontsize{120}{120}\selectfont % ] (block) {\thechapter}; \node[% rotate = 90, anchor = center, font = \color{black}\LARGE\normalfont ] at ([xshift=-15pt] block.west) {\textls[160]{\textsc{Chapitre}}}; \end{tikzpicture}% }

\pagestyle{MyStyle} %% added, so the style MyStyle that you have created is used for header and footer

\begin{document}

\chapter{Klauss}

\lipsum \end{document}

Result:

enter image description here

Edit: new layout after the OP asking for it in the comments.

With this new code, we can see that it is probably better to not justify the title when the title is long. I demonstrate also an adapting shape for the chapter number, so it can handle numbers above 9.

\documentclass[12pt,a4paper]{report}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage[top=3cm,bottom=3cm,left=3cm,right=3cm,headheight=3cm,footskip=1cm,marginparwidth=2cm]{geometry}
\usepackage{fancyhdr}
\usepackage{lipsum}
\usepackage{mathpazo}
\usepackage{domitian}
\usepackage[T1]{fontenc}
\usepackage{setspace}
\usepackage{tikz}

\usepackage{subcaption} \fancypagestyle{MyStyle} { \fancyhf{} \fancyhead[L]{\slshape\leftmark} \renewcommand{\headrulewidth}{2pt} \fancyfoot[C]{\thepage} \renewcommand{\footrulewidth}{2pt} } \let\oldstylenums\oldstyle

\definecolor{myBlue}{rgb}{0,0.32,0.6} \newlength{\chaptNumWd} \newlength{\sepBlock} \setlength{\sepBlock}{2em} \newsavebox{\mybox}% for saving the chapter block, so we can obtain his width and

\usepackage{titlesec} % formatting of the chapter title (number+text) \titleformat{\chapter}% sectionning type to customize [block]% shape, here number and title text on a block {\normalfont\bfseries\color{myBlue}}%format {}% formatting code of the section (here chapter) number. {0pt}% in "block" shape, the left margin
{\chapterFormat}% code before the title text (takes the title of the chapter as the argument) [\vspace{1em}{\titlerule[2.5pt]}\vspace{3pt}\titlerule\vspace{4pt}]

% Setting of the space before and after the title \titlespacing{\chapter}% Place the chapter block almost at top of the page {0pt}% space added at left {20pt}% vertical space added before {20pt}% vertical space added after (space between chapter title and section title, for example)

\usepackage{etoolbox} % to correct a bug, so the chapter block is really a the top of the page (see https://tex.stackexchange.com/questions/59389/package-titlesec-adds-extra-space-on-top-of-chapter-despite-commands-to-the-co/59392#59392) \makeatletter % the macro name contains @ \patchcmd{\ttl@mkchap@i}{\vspace*{@tempskipa}}{}{}{} \makeatother

\usepackage{microtype} % for the \textls command

\newcommand\chapterFormat[1]{% \sbox{\mybox}{% \begin{tikzpicture}[outer sep=0pt]% \node[% fill = myBlue, minimum width = 4cm, minimum height = 4cm, inner xsep=1.2em, font = \color{white}\fontsize{120}{120}\selectfont % ] (block) {\thechapter}; \node[% rotate = 90, inner xsep=0pt, anchor = center, font = \color{black}\LARGE\normalfont ] at ([xshift=-15pt] block.west) {\textls[140]{\textsc{Chapitre}}}; \end{tikzpicture}% }% \settowidth{\chaptNumWd}{\usebox{\mybox}}% \parbox[b]{\dimexpr\textwidth-\chaptNumWd-\sepBlock}{\LARGE#1}\hfill\usebox{\mybox}% }

\pagestyle{MyStyle} %% added

\begin{document} \chapter{Klauss}

\lipsum[1-2]

\setcounter{chapter}{9} \chapter{Équations intégro-différencielles du premier ordre}

\section{Section Un}

\lipsum \end{document}

enter image description here

enter image description here

Above, the situation is "extreme" as I use a word which don't hyphenate at beggining ("diffé"), resulting with an underfull hbox.

This can be modified with a ragged right title.

Replacing :

\parbox[b]{\dimexpr\textwidth-\chaptNumWd-\sepBlock}{\LARGE#1}\hfill\usebox{\mybox}%

with

\parbox[b]{\dimexpr\textwidth-\chaptNumWd-\sepBlock}{\raggedright\LARGE#1}\hfill\usebox{\mybox}%,

we obtain:

enter image description here

quark67
  • 4,166