3

Is it possible to have different geometries on different section levels, assuming always that you can guarantee they are on different pages. It may sound weird, but let me illustrate with a case where it should be obvious the need.

\documentclass{scrreprt}
\usepackage[outer=7cm, inner=3cm, marginparwidth=4cm, marginparsep=10mm, showframe]{geometry}
\begin{document}
  \part{test}
\end{document}

In this example of a document that uses wide margin notes, the part pages would be separators between chapters, and I would expect to have those pages centered differently from the main pages (i.e. centered to paper, and therefore with a geometry without margins)

enter image description here

I understan I could \newgeometry and \restoregeometry every time, but I would expect I could associate it with \part{} and get it done automatically. Is there a way to achieve this ?

2

Here is the way:

\documentclass{scrreprt}
\usepackage{lipsum}
\usepackage[outer=7cm, inner=3cm, marginparwidth=4cm, marginparsep=10mm, showframe]{geometry}
\let\oldpart\part
\def\part#1{\newgeometry{marginparwidth=0cm,marginparsep=0cm,showframe,inner=0cm,outer=0cm}\oldpart{#1}\restoregeometry}
\begin{document}
  \part{test}
  \chapter{Test}
  \lipsum[1-3]
  \part{test}
  \chapter{Test}
  \lipsum[1-3]
\end{document}

Just test it and change it to your needs... PS: I don't think that a screenshot is needed.

| improve this answer | |
  • 1
    Nice idea but please try \part[Detest]{test} with and without your redefinition of \part. You may want to use something like titlesec to patch the command. – user121799 Jul 14 '19 at 23:43
  • @marmot ... it can be solved with this way: tex.stackexchange.com/a/394571/120578 but is too rare (the optional argument inside part) and I don't want to make it so complicated here without a reason ... If the OP will ask something like that (s)he can find it on this link ... or can ask me to change all sections to parts in that code. Thanks although about the useful comment – koleygr Jul 14 '19 at 23:50
  • @koleygr With xparse, redefining the sectioning commands in a way that handles all variants can be done with little pain (clearly less than in the link you gave), see here for an example by egreg. – frougon Jul 15 '19 at 6:33
0

You can patch the section level command to change the geometry:

\usepackage{xpatch}
\xpretocmd\part
  {\newgeometry{marginparwidth=0cm,marginparsep=0cm,showframe,inner=0cm,outer=0cm}}
  {}{\PatchFailedI}

If a section level puts its headings on an own page, then it is a part like section level with style=part (option of \DeclareSectionCommand etc, see the documentation). You can patch \partheademptypage to restore the geometry after all section levels using style=part. This works also for \addpart and the starred versions. Additionally the optional argument of \part can be used.

Example:

\documentclass[chapterprefix]{scrreprt}
\usepackage{lipsum}
\usepackage[outer=7cm, inner=3cm, marginparwidth=4cm, marginparsep=10mm, showframe]{geometry}

\usepackage{xpatch}
\xpretocmd\part
  {\newgeometry{marginparwidth=0cm,marginparsep=0cm,showframe,inner=0cm,outer=0cm}}
  {}{\PatchFailedI}
\xapptocmd\partheademptypage
  {\restoregeometry}
  {}{\PatchFailedII}

\begin{document}
\tableofcontents
\part{test}
\chapter{Test}
\lipsum[1-3]
\addpart{test}
\chapter{Test}
\lipsum[1-3]
\part[toc entry]{title}
\chapter{Test}
\lipsum
\end{document}

If you want to do the same for chapters, change the style option to part and patch \chapter:

\RedeclareSectionCommand[
  style=part,
]{chapter}
\xpretocmd\chapter
  {\newgeometry{marginparwidth=0cm,marginparsep=0cm,showframe,inner=0cm,outer=0cm}}
  {}{\PatchFailedIII}

Starting with version 3.27 KOMA-Script will provide new Hooks (DoHooks). At the moment you need the prerelease of 3.27 (available on the KOMA-Script website) to test the following example:

\documentclass{scrreprt}[2019/07/29]% needs prerelease 3.27.3193 or newer
\usepackage{lipsum}
\usepackage[outer=7cm, inner=3cm, marginparwidth=4cm, marginparsep=10mm, showframe]{geometry}

\AddtoDoHook{heading/postinit/part}{\partgeometry}
\newcommand*\partgeometry[1]
  {\newgeometry{marginparwidth=0cm,marginparsep=0cm,showframe,inner=0cm,outer=0cm}}
\let\originalpartheademptypage\partheademptypage
\renewcommand\partheademptypage
  {\originalpartheademptypage\restoregeometry}

\begin{document}
\tableofcontents
\part{test}
\chapter{Test}
\lipsum[1-3]
\addpart{test}
\chapter{Test}
\lipsum[1-3]
\part[toc entry]{title}
\chapter{Test}
\lipsum
\end{document}
| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.