# How to adjust textwidth and textheight to paper size in mid document? (and header and footer “length” as well)

I want to adjust textwidth and textheight to papersize in mid document, that simple.

I am planning to change some pages paper size, but I need both the header, footer and text to adjust (better if automatically) to the paper size.

I've been playing around with geometry package and I was unable to find an option that help me.

## MWE:

\documentclass{article}
\usepackage{geometry}
\usepackage{lipsum}
\usepackage{fancyhdr}
\begin{document}

\thispagestyle{fancy}
\newlength{\classpageheight} \setlength{\classpageheight}{\pdfpageheight}
\newlength{\classpagewidth} \setlength{\classpagewidth}{\pdfpagewidth}

\lipsum[1-6]
\newpage
\thispagestyle{fancy}
\eject \pdfpagewidth=17in \pdfpageheight=18in
\lipsum[1-6]

\eject \pdfpagewidth=\classpagewidth \pdfpageheight=\classpageheight
\newpage
\thispagestyle{fancy}
\lipsum[1-6]

\end{document}

• you can see tex.stackexchange.com/questions/226930/… maybe it help – touhami Mar 16 '15 at 7:45
• @HarishKumar Thank you for answering, I did so, but it didn't worked, can you please post the full answer?. – Hans Mar 16 '15 at 7:55
• @touhami Thanks for answering. I did just took a look at that post and tried to implemented, but failed doing so, would you please help me getting that to work?. – Hans Mar 16 '15 at 7:57
• @HarishKumar I did so, but it is still not working, I don't know if I didn't make myself clear. What I am trying to do is change the paper size, just for a couple of pages, to a large customize paper size, then be able to write all over the page without scaling the text and having the header all the way through the paper size as well. Please feel free to have a look to the link I provided in my question, the second page will make my question more explicit. Also feel free to ask, maybe I am not being clear in off. – Hans Mar 16 '15 at 8:12
• @Hans Sorry I made a mistake in my last comment. → Remember that you can't change paper size midway though. Read as can't. – user11232 Mar 16 '15 at 8:24

Here is my solution your remarks are welcome

\documentclass{article}
\usepackage{geometry}
\usepackage{lipsum}
\usepackage{fancyhdr}

\def\vcoef#1{#1=\dimexpr #1*\pdfpageheight/\paperheight\relax}
\def\hcoef#1{#1=\dimexpr #1*\pdfpagewidth/\paperwidth\relax}

\makeatletter
\newpage
\pdfpagewidth=#1 \pdfpageheight=#2
\hcoef\textwidth
\vcoef\textheight
\vsize=\textheight
\@colroom=\textheight
\@colht=\textheight
\columnwidth=\textwidth
\if@twocolumn%
\divide\columnwidth\tw@%
\@firstcolumntrue%
\fi%
\hsize=\columnwidth
\linewidth=\hsize
\hcoef\evensidemargin
\hcoef\oddsidemargin
\vcoef\topmargin
\vcoef\footskip
\hcoef\marginparwidth
\hcoef\marginparsep
% this is important but does nothing here
\paperwidth=\pdfpagewidth
\paperheight=\pdfpageheight}
\makeatother
\begin{document}

\thispagestyle{fancy}
%----->I change something here
\newlength{\classpageheight}
\setlength{\classpageheight}{\paperheight}
\newlength{\classpagewidth}
\setlength{\classpagewidth}{\paperwidth}

\lipsum[1-6]

\thispagestyle{fancy}

\lipsum[1-6]


• Thanks sir, the output is just what I need, but I have two questions so far, How do I get it to work with two columns if the document was with two columns, and with one column? (maybe this is explained in the \columnsep advice, but I couldn't implement it), and How do I manually set the margins?. As you may notice, I've never toggled with code in LaTeX. – Hans Mar 16 '15 at 19:45