Page Layoutchange papersize in mid document and also fill the page

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
AndreGismo
Posts: 6
Joined: Sat Nov 06, 2021 10:23 am

change papersize in mid document and also fill the page

Post by AndreGismo »

Hello Community,

I am looking for a way to change the papersize (normally A4 to A3 for one page) in my document. I need this, because I want to explicitly write out a big matrix in the appendix (I know, I could use things like

Code: Select all

\vdots
or

Code: Select all

\ddots
to compress the matrix, but I want to show the whole matrix, as I think, it is important for a good understanding of what I am doing).

I have found several approaches, like:
- here
- or here

But they don't match my needs: they change the paper size, but the area for the text on the new page doesn't really change.

In my case I get an A3-page in landscape format - ok, that is good.
BUT:
- The text seems to be aligned to the text on the A4-page in portrait format, so I can't even use the new gained place
- The page number appears in the middle of the page (I guess at the same position, where it used to be on the former A4-page) thus messing up my matrix, because one could think that it is an element of the matrix.

Another "problem": the approach uses Koma-Script, and it seems that it doesn't get along with the

Code: Select all

\usepackage{fancyhdr}
I use for headers and footers in the finaly document. That is what I have learned in a Latex-Beginner-Corse. When I asked the same question to the lecturer he said: "oh, that's Koma-Script. Better stick to 'normal' Latex". And I think I could create a nice document just using 'normal' Latex - even the template of my university just uses 'normal' Latex. So It would be great, if there is a solution to my answer using just the 'normal' Latex.

I try to show you a working minimal example (but I'm not shure, if I'm using the correct command - please excuse me, I'm completely new to this forum and LaTeX):

Code: Select all

\documentclass{article}
\usepackage[ngerman]{babel} % für deutsche Namen (Zusammenfassung statt Abstract z.B.)
\usepackage[T1]{fontenc} % ermöglicht Umlaute
\usepackage[utf8]{inputenc} % 5 ermöglicht Umlaute
\usepackage{color} % ermöglicht farbigen Text
\usepackage{setspace} \onehalfspacing % generelle Einstellung für Abstände zwischen Zeilen
\usepackage[a4paper]{typearea} % für Einstellungen von Rändern
\usepackage{hyperref} % für klickbare Verweise
\usepackage{amsmath, amssymb}
%\geometry{left=3cm,right=3.5cm,top=3cm,bottom=3cm}
\setlength{\parindent}{0pt}
\setcounter{MaxMatrixCols}{20}

\begin{document}
\section{Hello World}
Some text .......
On the following side comes the big matrix:

\newpage

% I even have to use A2 to make it fit on the paper
% if it was possible to correctly use the available place
% a A3-page would suffice
\KOMAoptions{paper=A2,paper=landscape}
\recalctypearea

\begin{equation}
	\begin{pmatrix}
		Z_1 & Z_1 + Z_2 & Z_1 + Z_2 + Z_3 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
		1 & 1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
		u_{1,1} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
		0 & u_{1,2} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
		0 & 0 & u_{1,3} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
		u_{1,1} \cdot \Delta t & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & -1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
		0 & u_{1,2} \cdot \Delta t & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & -1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
		0 & 0 & u_{1,3} \cdot \Delta t & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & -1 & 0 & 0 & 0 & 0 & 0 & 0 \\
		%
		0 & 0 & 0 & 0 & 0 & 0 & Z_1 & Z_1 + Z_2 & Z_1 + Z_2 + Z_3 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
		0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
		0 & 0 & 0 & 0 & 0 & 0 & u_{2,1} & 0 & 0 & 0 & 0 & 0 &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 & 0 & 0 & 0 & u_{3,2} \cdot \Delta t & 0 & 0 & 0 & 0 \\
		0 & 0 & u_{1,3} \cdot \Delta t & 0 & 0 & 0 & 0 & 0 & u_{2,3} \cdot \Delta t & 0 & 0 & 0 & 0 & 0 & u_{3,3} \cdot \Delta t & 0 & 0 & 0 \\
		%
		%0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & u_{3,2} \cdot \Delta t \\
		%0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & u_{3,2} \cdot \Delta t \\
		%0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & u_{3,2} \cdot \Delta t \\
	\end{pmatrix}
	\cdot
	\begin{pmatrix}
		i_{1,1} \\
		i_{1,2} \\
		i_{1,3} \\
		SOC_{1,1} \\
		SOC_{1,2} \\
		SOC_{1,3} \\
		i_{2,1} \\
		i_{2,2} \\
		i_{2,3} \\
		SOC_{2,1} \\
		SOC_{2,2} \\
		SOC_{2,3} \\
		i_{3,1} \\
		i_{3,2} \\
		i_{3,3} \\
		SOC_{3,1} \\
		SOC_{3,2} \\
		SOC_{3,3} \\
	\end{pmatrix}
	=
	\begin{pmatrix}
		u_{min} + u_{0}\\
		i_{max} \\
		P_{max, 1} \\
		P_{max, 2} \\
		P_{max, 3} \\
		0 \\
		0 \\
		0 \\
		u_{min} + u_{0}\\
		i_{max} \\
		P_{max, 1} \\
		P_{max, 2} \\
		P_{max, 3} \\
		0 \\
		0 \\
		0 \\
		u_{min} + u_{0}\\
		i_{max} \\
		P_{max, 1} \\
		P_{max, 2} \\
		P_{max, 3} \\
		SOC_{soll_{1}} - SOC_{start_{1}} \\
		SOC_{soll_{2}} - SOC_{start_{2}} \\
		SOC_{soll_{3}} - SOC_{start_{3}} \\
	\end{pmatrix}
\end{equation}
\end{document}
Thank you for any help in advance!!
Last edited by Stefan Kottwitz on Sat Nov 06, 2021 1:16 pm, edited 1 time in total.
Reason: code tag fixed

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

change papersize in mid document and also fill the page

Post by Ijon Tichy »

Unfortunately your code is not marked correctly as block code. Because of this, I cannot test and modify it in the online editor/compiler of latex.org. However, as you are using package typearea, I can tell you, that the example in section 20.2 of the German scrguide (unfortunately the English scrguien of KOMA-Script up to version 3.34 uses a much simpler example without paper size change) does show you how to change the page size and increase the text area. From KOMA-Script 3.35 the English manual shows and explains the same example. But despite in KOMA-Script 3.34 it is in German available only, you should be able to test the example and understand it. If you do not understand German, you should read and test the example in the English scrguien first. Then you should also be able to understand the German example. The manual also describes an option usegeometry, if you like to mix typearea's skill to change the paper size, with geometry's user interface to change margins and the text area more.

BTW: \setlength{\parindent}{0pt} is not recommended, it is a very bad idea. See "How to correctly prevent paragraph indentation" (or in German „Wie der Absatzeinzug korrekt verhindert wird“ for more information.

BTW2: \usepackage[utf8]{inputenc} is not needed any longer since LaTeX 2018/04/01.

BTW3: hyperref should be loaded as late as possible, i.e. after amsmath, because it has to patch commands of several other packages, e.g., of amsmath, and can doe this only, if it is loaded after those packages.

BTW4: Is seems your lecturer does not know a lot about LaTeX ad KOMA-Script. KOMA-Script is normal LaTeX. KOMA-Script classes are not the standard LaTeX classes, but they are still LaTeX. Using KOMA-Script classes or packages does not differ from using other classes or packages, e.g., geometry or tikz. And if the non-standard LaTeX package fancyhdr has problems with pagesize changes, maybe the KOMA-Script LaTeX package scrlayer-scrpage would be an alternative, because it can handle such changes. But maybe we can also fix a problem with fancyhdr, if you show it in a new question.

Without using the KOMA-Script package typearea my only idea is to generate the page as a stand-alone document and load it using pdfpages, because the also non-standard LaTeX package geometry is not able to change the paper size on its own. But maybe you simply should ask the lecturer, how to change the paper size inside a document without using a non-standard LaTeX package?
Last edited by Ijon Tichy on Tue Nov 09, 2021 10:56 am, edited 1 time in total.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
AndreGismo
Posts: 6
Joined: Sat Nov 06, 2021 10:23 am

change papersize in mid document and also fill the page

Post by AndreGismo »

@ Ijon Tichy: wow, thank you for the quick answer! :)
Unfortunately your code is not marked correctly as block code. Because of this, I cannot test and modify it in the online editor/compiler of latex.org.
Yes, I'm sorry, I thought I have to use the LaTeX-Button to create an executable version, but someone hat allready fixed this, thank you @Stefan Kottwitz ! In the future I will know how to create correct working examples with the code-tag.
Despite it is in German, you should be able to test the example and understand it.
Don't worry, german is my native language ;)
I will definitely have a look at this example!
BTW: \setlength{\parindent}{0pt} is not recommended, it is a very bad idea. See "How to correctly prevent paragraph indentation" (or in German „Wie der Absatzeinzug korrekt verhindert wird“ for more information.

BTW2: \usepackage[utf8]{inputenc} is not needed any longer since LaTeX 2018/04/01.

BTW3: hyperref should be loaded as late as possible, i.e. after amsmath, because it has to patch commands of several other packages, e.g., of amsmath, and can doe this only, if it is loaded after those packages.
Thank you! I didn't know all of this.
BTW4: Is seems your lecturer does not know a lot about LaTeX ad KOMA-Script.
Haha, yes, this might actually be true :lol:

Yes, it seems, I have to consider using KOMA-Script. I have seen the documentation here and I was hoping, I could just skip these pages and proceed using Latex without KOMA-script. But that is ok, it seems, KOMA-script really has some advantages.

Anyway, thank you again for helping out a beginner!
I will have a further look into the KOMA-script documentation and the examples you have mentioned.
Maybe I will be able to make it work on my own. If some qestions remain, I will come back with an executable example.
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

change papersize in mid document and also fill the page

Post by Ijon Tichy »

AndreGismo wrote: I have seen the documentation here
Be careful, the linked document is a very old version of the KOMA-Script manual. It is not valid for the current version of KOMA-Script. You should ignore it.

See "How to find the manual for KOMA-Script classes and packages" (or „Wie die Anleitung zu KOMA-Script-Klassen und -Paketen zu finden ist“) for more information about getting manuals of an installed packages or of up-to-date package versions (not only the manual of KOMA-Script).

BTW: There are many more HowTo pages in English and in German at the KOMA-Script wiki.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

change papersize in mid document and also fill the page

Post by Stefan Kottwitz »

AndreGismo wrote:Don't worry, german is my native language ;)
So you could also visit us on TeXwelt.de or goLaTeX.de if you like. ;-)

Stefan
LaTeX.org admin
AndreGismo
Posts: 6
Joined: Sat Nov 06, 2021 10:23 am

change papersize in mid document and also fill the page

Post by AndreGismo »

Stefan Kottwitz wrote:
AndreGismo wrote:Don't worry, german is my native language ;)
So you could also visit us on TeXwelt.de or goLaTeX.de if you like. ;-)

Stefan
Ah ok, thank you for the hint! I will definitely give it a try for the next questions (they are allready in the pipe :D).
AndreGismo
Posts: 6
Joined: Sat Nov 06, 2021 10:23 am

change papersize in mid document and also fill the page

Post by AndreGismo »

I have tried the example mentioned by Ion Tichy, and it almost works as expected, I have also managed to switch back to A4 from A3. But now the only problem remaining is, the typearea isn't computed accordingly (so the text goes outside the page). I have tried to use\recalctytearea or \typearea[current]{last} as an alternative (as mentioned here), but it doesn't work.

Here is my example:

Code: Select all

\documentclass[areasetadvanced]{scrartcl}

\usepackage[automark, headsepline=true, footsepline=true]{scrlayer-scrpage}
\usepackage[ngerman]{babel}
\usepackage{amsmath, amssymb}
\usepackage{lipsum}
\usepackage{hyperref}  % erst so spät wie möglich einbinden

\areaset[current]{\textwidth}{\textheight}


\begin{document}
%\noindent\rule{\textwidth}{\textheight}

\thispagestyle{empty}
\section*{Kurzfassung}
\lipsum[1-2]

\newpage

\tableofcontents

\newpage

\section{Einleitung}
\lipsum[1-6]

\KOMAoption{paper}{a3, landscape}
\areaset[current]{\dimexpr\textwidth+.5\paperwidth\relax}{\textheight}
\lipsum[7-18]

\clearpage

\KOMAoption{paper}{a4, portrait}
\areaset[current]{\textwidth}{\textheight}
% hiermit sollte doch eigentlich wieder der passende Satzspiegel errechnet werden
\typearea[current]{last}
%\recalctypearea  % Alternative
\section{Weiterer Anhang}
\lipsum[2-7]
\end{document}
Is there a way, to correctly calculate the typearea?
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

change papersize in mid document and also fill the page

Post by Ijon Tichy »

You don't need to recalculate the typing area. Just use \storeareas\meinegespeichertenWerte before changing the paper size and \clearpage\meinegespeichertenWerte as shown in the example in the scrguide:

Code: Select all

\documentclass[areasetadvanced]{scrartcl}

\usepackage[automark, headsepline=true, footsepline=true]{scrlayer-scrpage}
\usepackage[ngerman]{babel}
\usepackage{amsmath, amssymb}
\usepackage{lipsum}
\usepackage{hyperref}  % erst so spät wie möglich einbinden

\areaset[current]{\textwidth}{\textheight}


\begin{document}
%\noindent\rule{\textwidth}{\textheight}

\thispagestyle{empty}
\section*{Kurzfassung}
\lipsum[1-2]

\newpage

\tableofcontents

\newpage

\section{Einleitung}
\lipsum[1-6]

\storeareas\meinegespeichertenWerte% store the current typing area in \meinegespeichertenWerte
\KOMAoption{paper}{a3, landscape}
\areaset[current]{\dimexpr\textwidth+.5\paperwidth\relax}{\textheight}
\lipsum[7-18]

\clearpage
\meinegespeichertenWerte%restore the typing area, that was valid at \storeareas\meinegespeichertenWerte
\section{Weiterer Anhang}
\lipsum[2-7]
\end{document}
Additional explanation:

\textwidth is the current with of the text area. \textheight the current height. So \areaset[current]{\textwidth}{\textheight} does try to recalculate margins for the current settings of these values. This cannot work here after changing the page size.

\typearea[current]{last} cannot work here, because the last calculation was a \areaset calculation.

You could store the \textwidth and \textheight from the initial \aereaset command and repeat this with the stored values. But usage of \storearea is easier and designed for this. And it would also work after changes of the typing area without using package typearea, e.g., using geometry.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

change papersize in mid document and also fill the page

Post by Stefan Kottwitz »

Hi Andre,
AndreGismo wrote:I will definitely give it a try for the next questions (they are allready in the pipe :D).
I like this, because questions are the foundation of such web forums. Without questions, it would be very silent. Quick thoughts: TeXwelt.de is for clear questions that can have a clear answer, goLaTeX.de is better for discussions or broad or unclear issues. In any case, full (but short) code is appreciated.

Stefan
LaTeX.org admin
AndreGismo
Posts: 6
Joined: Sat Nov 06, 2021 10:23 am

change papersize in mid document and also fill the page

Post by AndreGismo »

Ijon Tichy wrote:You don't need to recalculate the typing area. Just use \storeareas\meinegespeichertenWerte before changing the paper size and \clearpage\meinegespeichertenWerte as shown in the example in the scrguide:

Code: Select all

\documentclass[areasetadvanced]{scrartcl}

\usepackage[automark, headsepline=true, footsepline=true]{scrlayer-scrpage}
\usepackage[ngerman]{babel}
\usepackage{amsmath, amssymb}
\usepackage{lipsum}
\usepackage{hyperref}  % erst so spät wie möglich einbinden

\areaset[current]{\textwidth}{\textheight}


\begin{document}
%\noindent\rule{\textwidth}{\textheight}

\thispagestyle{empty}
\section*{Kurzfassung}
\lipsum[1-2]

\newpage

\tableofcontents

\newpage

\section{Einleitung}
\lipsum[1-6]

\storeareas\meinegespeichertenWerte% store the current typing area in \meinegespeichertenWerte
\KOMAoption{paper}{a3, landscape}
\areaset[current]{\dimexpr\textwidth+.5\paperwidth\relax}{\textheight}
\lipsum[7-18]

\clearpage
\meinegespeichertenWerte%restore the typing area, that was valid at \storeareas\meinegespeichertenWerte
\section{Weiterer Anhang}
\lipsum[2-7]
\end{document}
Additional explanation:

\textwidth is the current with of the text area. \textheight the current height. So \areaset[current]{\textwidth}{\textheight} does try to recalculate margins for the current settings of these values. This cannot work here after changing the page size.

\typearea[current]{last} cannot work here, because the last calculation was a \areaset calculation.

You could store the \textwidth and \textheight from the initial \aereaset command and repeat this with the stored values. But usage of \storearea is easier and designed for this. And it would also work after changes of the typing area without using package typearea, e.g., using geometry.
Ah perfect, thank you! :)

I didn't know what this \meinegespeichertenWerte was supposed to be - I thouhgt it was some variable declared outside the example, that's why I left it away. So you just store the values with \storeareas. Yeah, sounds logic if I think about it :D

Thank you for your efforts, that helps me a lot!
Post Reply