1

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}

MWE compiled here.

Hans
  • 1,013
  • you can see http://tex.stackexchange.com/questions/226930/change-textheight-in-function-of-width maybe it help – touhami Mar 16 '15 at 07: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 07: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 07: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 08: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. –  Mar 16 '15 at 08:24
  • @HarishKumar I am following the instructions shown in the accepted answer here http://tex.stackexchange.com/questions/6834/change-paper-size-in-mid-document – Hans Mar 16 '15 at 12:29
  • @Hans i was at work. i have a solution just give me some time – touhami Mar 16 '15 at 17:12

1 Answers1

0

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 
\def\adjustpagedim#1#2{%
\newpage
\pdfpagewidth=#1 \pdfpageheight=#2
\hcoef\textwidth
\vcoef\textheight
\vsize=\textheight
\@colroom=\textheight
\@colht=\textheight
\columnwidth=\textwidth
\if@twocolumn%
   \advance\columnwidth-\columnsep
   \divide\columnwidth\tw@%
   \@firstcolumntrue%
\fi%
\hsize=\columnwidth
\linewidth=\hsize
\hcoef\evensidemargin
\hcoef\oddsidemargin
\vcoef\topmargin
\vcoef\headheight
\vcoef\headsep
\vcoef\footskip
\hcoef\marginparwidth
\hcoef\marginparsep
\headwidth=\textwidth
% 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]

\adjustpagedim{17in}{18in}
\thispagestyle{fancy}

\lipsum[1-6]

\adjustpagedim{\classpagewidth}{\classpageheight}
\thispagestyle{fancy}

\lipsum[1-6]

\end{document}
touhami
  • 19,520