TransWikia.com

How to add text above a chapter heading without vertical shift

TeX - LaTeX Asked by Christian Andersen on December 30, 2020

I want to insert some text (author names and author-related information for a journal) at the top of pages beginning a new chapter. While I know of solutions like textpos and different solutions here, I wanted to find a simple way (because of incompatabilities and speed).

Having a look at how chapter is working in different classes, I redefined clearpage or cleardoublepage and inserted a parbox with zero width and height. Apparently this box is not invisible for latex, so it omits 0.34cm of vertical space in book class. In memoir and scrbook the chapter headings are on the exactly same height.

How can I change the code to prevent chapter to omit some of the vertical spacing? Is it possibe to find a way to make the text invisible to chapter?

I would love to have a generic solution (so eg. not touching @makechapterhead because that is not used by scrbook) or at least one that that works at least with memoir, scrbook and book/report class.

enter image description here

documentclass[oneside]{book}
%documentclass[oneside]{report}
%documentclass[oneside]{scrbook}
%documentclass[oneside]{memoir}
usepackage{zref-savepos}
usepackage[margin=0pt,paperwidth=10cm,paperheight=10cm]{geometry}
makeatletter
newcommandcauthor[1]{def@cauthor{#1}}
newcommandctitle[1]{def@ctitle{#1}}
NewDocumentCommand cmaketitle {}
{
  bgroup
  if@openright 
    cleardoublepage
    letcleardoublepagerelax
  else 
    clearpage
    letclearpagerelax
  fi
  noindentparbox[t][0pt]{0pt}{@cauthor}%
  noindentparbox[t]textwidth{%
  chapter{@ctitle}mbox{}}
  egroup
}
makeatother
begin{document}

chapter{Normal Positionzsavepos{normal}hrulefill}

ctitle{My problemzsavepos{cmaketitle}}
cauthor{Schmidfootnote{Blacksmith University}
         Kovačević
         Ferrari
         Kowalski}
cmaketitle

noindent This heading (made by verb|cmaketitle|) is shifted by
ExplSyntaxOn
dim_new:N l_diff_dim
dim_sub:Nn l_diff_dim {zposy{normal}sp-zposy{cmaketitle}sp}
dim_to_decimal_in_unit:nn { dim_use:N l_diff_dim } { 1cm }cm~
ExplSyntaxOff
compared to the normal verb|chapter|.


end{document}

And if there is a solution without boxes preventing footnotetext to show up, that would be great!

One Answer

I think that I found a solution. But maybe others can see if there are problems arising from this approach. At least it seems to work together well with book, scrbook, memoir and also some other classes and also with fncychap. The main part (still) are the cauthor, title and cmaketitle-commands. Using a combination of makebox(0,0)[lt] and parbox[t]textwidth works well. The par is only needed in the scrbook-class.

newcommandcauthor[1]{def@cauthor{#1}}
newcommandctitle[1]{def@ctitle{#1}}
NewDocumentCommand cmaketitle {}
{%
  bgroup%
  if@openright %
    cleardoublepage%
  else %
    clearpage%
  fi%
  noindentmakebox(0,0)[lt]{parbox[t]{textwidth}{@cauthor}}
  ifscrbookelseparfi
    letcleardoublepagerelax letclearpagerelax%
  chapter{@ctitle}
  egroup
}

enter image description here So now everything is perfectly aligned.

Complete document with some tested classes and packages. All tested combinations worked.

PassOptionsToPackage{margin=0pt,paperwidth=10cm,paperheight=10cm}{geometry}
documentclass[oneside]{book}
%documentclass[oneside]{report}
%documentclass[oneside]{scrbook}
%documentclass[oldfontcommands,oneside]{memoir}
%documentclass{basque-book}
%documentclass{ycbook}
%documentclass{octavo}
%documentclass{willowtreebook}
%documentclass{elegantbook}
usepackage{geometry}
%usepackage[Lenny]{fncychap}
%usepackage[Sonny]{fncychap}
%usepackage[Glenn]{fncychap}
%usepackage[Conny]{fncychap}
%usepackage[Rejne]{fncychap}
%usepackage[Bjarne]{fncychap}
%usepackage[Bjornstrup]{fncychap}
makeatletter
newififscrbook
newififfncychap
@ifclassloaded{scrbook}{scrbooktrue}{scrbookfalse}
@ifpackageloaded{fncychap}{fncychaptrue}{fncychapfalse}

newcommandcauthor[1]{def@cauthor{#1}}
newcommandctitle[1]{def@ctitle{#1}}
NewDocumentCommand cmaketitle {}
{%
  bgroup%
  if@openright %
    cleardoublepage%
  else %
    clearpage%
  fi%
  noindentmakebox(0,0)[lt]{parbox[t]{textwidth}{@cauthor}}
  ifscrbookelseparfi
    letcleardoublepagerelax letclearpagerelax%
  chapter{@ctitle}
  egroup
}
makeatother
begin{document}

chapter{Normal chapterhrulefill}
text after normal chapterhrulefill

cauthor{Schmidfootnote{Blacksmith University}
         Kovačević
         Ferrari}
ctitle{Ctitle chapterhrulefill}
cmaketitle
text after ctitle chapterhrulefill

chapter{Normal chapterhrulefill}
text after normal chapterhrulefill

end{document}

Is there a solution without the boxes (to get working footnotes)?

Answered by Christian Andersen on December 30, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP