2

I am using chapter decorations from template "Legrand Orange book". But I am getting very strange vertical spacing with it. See the picture. because of capital letter H spacing between 3rd and 4th line is way bigger than previos one where there is no "above-line" letters.

So, this small vertical spacing is weird for me... Am I wrong? I would like to change vertical spacing to normal (where there is a gap for capital letters)

enter image description here

Here is minimal working example.

\documentclass{book} 

\usepackage{geometry}
\usepackage[russian]{babel}
\usepackage{tikz} 
\usepackage{xcolor} 
\definecolor{prpl}{RGB}{150, 120, 182} 
\usepackage[utf8]{inputenc} 
\usepackage[T2A]{fontenc} 

\makeatletter
\def\@makechapterhead#1{%
{\begin{tikzpicture}[remember picture,overlay]
\node at (current page.north west)
{\begin{tikzpicture}[remember picture,overlay]
\draw[anchor=west] (\Gm@lmargin,-5cm) node [line width=2pt,rounded corners=15pt,draw=prpl,fill=white,fill opacity=0.5,inner sep=45pt]{\makebox[22cm]{}};
\draw[anchor=west] (\Gm@lmargin+.3cm,-5cm) node[text width=16cm] {\huge\sffamily\bfseries\color{black}\thechapter. #1};
\end{tikzpicture}};
\end{tikzpicture}
}}
\makeatother

\begin{document}
\chapter{Исследование функций одной переменной при помощи первой и второй производных на монотонность, локальные экстремумы, выпуклость. Необходимые условия, достаточные условия.}
\end{document}
  • 1
    Is the box with the rounded corners supposed to bleed off the page? What size is it supposed to be? – sgmoye Jul 22 '18 at 17:26
  • @sgmoye yes, it's supposed to bleed off the page... I am fine with both variants of size: fixed one (which I do have now) and the second one which takes textheight as a parameter... – user98432 Jul 22 '18 at 21:03
  • You are nesting tikzpictures which is not supported. Moreover, you are nesting one remember picture, overlay in another, which doesn't make any sense at all. – cfr Jul 22 '18 at 21:24
  • @cfr this is how it is done in template itself. I thought there is hidden sence in it :-) – user98432 Jul 23 '18 at 10:37
  • @Lust_For_Love Whenever people say 'template', expect trouble. The majority are extremely poorly written and cause deep, mysterious and generally quite horrible problems sooner or later. – cfr Jul 23 '18 at 22:19
3

I'm not sure what it should look like. Here's a way of getting the 'correct' line spacing i.e. the proper line-spacing for \huge. If you want something different, you can use \fontsize{<dimen>}{<dimen>}\selectfont in place of \huge, where the first number gives the point size of the font and the second the baseline skip e.g. {12pt}{14pt}.

I've eliminated the nested tikzpictures as this is not supported and known to cause problems. This is even more so with a nested remember picture, overlay, which makes no sense at all.

You might find tikzpagenodes useful to avoid the use of internal geometry dimensions.

\documentclass[russian]{book} 
\usepackage[showframe]{geometry}
\usepackage{babel}
\usepackage{tikz} 
\definecolor{prpl}{RGB}{150, 120, 182} 
\usepackage[utf8]{inputenc} 
\usepackage[T2A]{fontenc} 
\usepackage{kantlipsum}

\makeatletter
\def\@makechapterhead#1{%
  \noindent
  \begin{tikzpicture}[remember picture]
    \node (n) at (\Gm@lmargin,-\Gm@tmargin) [ inner sep=3mm, fill=white, fill opacity=0.5, text width={\textwidth-6mm}, text opacity=1, font=\huge\sffamily\bfseries, text=black]{\thechapter. #1};
  \end{tikzpicture}%
  \begin{tikzpicture}[remember picture,overlay]
    \draw [line width=2pt, rounded corners=15pt, prpl] (n.north -| current page.east) -| (n.south west) -- (n.south -| current page.east); 
  \end{tikzpicture}%
  \bigskip\par
}
\makeatother

\begin{document}
\chapter{Исследование функций одной переменной при помощи первой и второй производных на монотонность, локальные экстремумы, выпуклость. Необходимые условия, достаточные условия.}
\kant[1-3]
\end{document}

output

The lines are just from showframe for illustration and debugging. Obviously, you should remove this option when you're happy with the placement.

As an example, \huge means 20pt font with 25pt skip. Substituting \fontsize{20pt}{22pt}\selectfont in the code for \huge closes the lines up:

squishier output

| improve this answer | |
  • 1
    I tried my hand at this (fixing the nested tikzpictures and using tikzpagenodes.sty). The problem is that remember picture,overlay makes the tikzpicture take up no space on the page so that text that follows the chapter head overprints the chapter head. Removing remember picture,overlay in my attempts works, but the log complains of an overfull \hbox, unsurprisingly. In short, I couldn't find a way around this, outside of a hacky \vspace for each occurrence of a \chapter. – sgmoye Jul 23 '18 at 11:12
  • @sgmoye I can look later, but the use of \vspace is not hacky here. In any case, you needed this with your original code already, so that's not knew. Probably the best way is to typeset the chapter title in place and overlay the border. That way, you know how much extra space to allow because it will always be the same amount. – cfr Jul 23 '18 at 15:59
  • @sgmoye Please see edit above. I think this is probably simplest: split the picture and overlay the border. This means the spacing is correct regardless of the height/depth of the chapter title, which will obviously vary. At least, it seemed to work for me. – cfr Jul 23 '18 at 22:18
  • Nice. Wish I'd thought of that... – sgmoye Jul 24 '18 at 0:04
  • @sgmoye Thanks for the prompt. Obviously wasn't thinking about the actual text when I wrote the original version .... – cfr Jul 24 '18 at 0:59
1

Here is my attempt -- it works but seems hacky. The problem is getting text following the chapter head to be located correctly. Please see the comments in the code. I'd like to see a somewhat less hacky solution!

\documentclass{book} 

\usepackage[showframe]{geometry}
\usepackage[russian]{babel}
\usepackage{tikz} 
\usepackage{xcolor} 
\definecolor{prpl}{RGB}{150, 120, 182} 
\usepackage[utf8]{inputenc} 
\usepackage[T2A]{fontenc}
\usepackage{tikzpagenodes}

\newsavebox{\tmpbox}
\newlength{\tmpht}

%% Put the text of the chapter head into an lrbox.
%% Use the lrbox in \@makechapterhead;
%% measure the lrbox to arrive at a \vspace that
%% gets the text of the chapter out the way of
%% the chapter head.

\makeatletter
\def\@makechapterhead#1{%
\begin{lrbox}{\tmpbox}%
    \begin{minipage}{\textwidth}%
        \raggedright\huge\sffamily\bfseries\color{black}\thechapter. #1
    \end{minipage}%
\end{lrbox}%
\noindent
\begin{tikzpicture}[remember picture,overlay]%% The chapter head occupies no space on the page
    \node[anchor=north west,
    rounded corners=15pt,
    draw=prpl!50,
    line width=2pt,
    inner sep=6pt] at (current page text area.north west)
        {\usebox{\tmpbox}\hspace*{22cm}}; %% change '22cm' to suit
\end{tikzpicture}%
\settoheight{\tmpht}{\usebox{\tmpbox}}%
\vspace{\dimexpr\tmpht + 1in}% Adjust 1in to suit
}
\makeatother

\begin{document}
\chapter{Исследование функций одной переменной при помощи первой и второй производных на монотонность, локальные экстремумы, выпуклость. Необходимые условия, достаточные условия.}

\section{This is a section}

More text.

\end{document}

--

enter image description here

| improve this answer | |
  • I don't see why you think this is hacky, to be honest. Maybe it is a bit more of a faff to set-up, but measuring the size of boxes is the point of TeX, isn't it? :-) – cfr Jul 24 '18 at 1:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy