Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is it possible to have diverging values for \textwidth on the first page and all other pages.

On the first page I would like to set the width of the text to 12cm, on the following pages to 16cm.

\documentclass[ngerman,12pt]{scrlttr2}
\usepackage{babel,blindtext}

\setlength{\textwidth}{12cm}

\setkomavar{fromname}{Just me}
\setkomavar{fromaddress}{Just some place}

\begin{document}
\begin{letter}{Some one \\ Some Place}
\opening{fsdfsdafs}

\blindtext[5]

\closing{Best wishes}
\end{letter}
\end{document}
share|improve this question
    
why do you want to change \textwidth (which is hard to coordinate with the output routine) rather than just change the width of the text (which is trivial, eg using an environment based on quote using a different, possibly negat?ive, indent) –  David Carlisle Nov 3 '13 at 10:36
    
I thought that adjusting \textwidth would be the right way. –  Uwe Ziegenhagen Nov 3 '13 at 10:43
    
Also when changing the width it is much much easier to have a forced page break, as changing the width mid-paragraph requires multiple passes and calculating a \parshape. Is a forced page break acceptable? –  David Carlisle Nov 3 '13 at 10:51
    
No, not really. The text should flow normally, without the need to enforce a pagebreak. –  Uwe Ziegenhagen Nov 3 '13 at 11:15
    
Ah in that case changing \textwidth is the least of your worries. It's not really possible in TeX in general but so long as there is only normal text and no large inserts, so you can guess accurately how many lines are on the page it is possible in simple cases. –  David Carlisle Nov 3 '13 at 11:19

2 Answers 2

up vote 4 down vote accepted

The basic technique is like this:

enter image description here

\documentclass[ngerman,12pt]{scrlttr2}
\usepackage{babel,blindtext}

\setlength{\textwidth}{16cm}

\setkomavar{fromname}{Just me}
\setkomavar{fromaddress}{Just some place}

\def\pshape#1{%
\parshape #1 \pshapexiicm{#1} 0pt 16cm }

\def\pshapexiicm#1{%
 \ifnum#1>1 0pt 12cm \expandafter
  \pshapexiicm\expandafter{\the\numexpr#1-1\expandafter\relax\expandafter}\fi}

\begin{document}



\begin{letter}{Some one \\ Some Place}
\opening{fsdfsdafs}

\pshape{26}
aaa\blindtext[5]

\closing{Best wishes}
\end{letter}
\end{document}

To make it more general you need to trap paragraph breaks and restart the new paragraph with a \parshape that has a reduced number of short lines, depending on how many lines you just did. (code could be stolen from the wrapfig package for that:-)

If however you have stretch parskip or anything else complicated on the page working out exactly how many short lines you need can be challenging.

share|improve this answer
    
Is it more easier to use afterpage? –  Marco Daniel Nov 3 '13 at 11:45
1  
@MarcoDaniel It's easy to use afterpage, it just doesn't help. –  David Carlisle Nov 3 '13 at 11:51

Uwe, It is possible in TeX, through the pagegoaland hsize commands, as long as you can deduce the value that is needed, which in your case, even if your aim, were to include graphics in said document, it can be easily accomplished by this method.

Either way, you just need to get the desired value where the page break must occur, regardless of the page, that is, whether it's the first, second, or third.

So the answer in TeX is:




\documentclass[ngerman,12pt]{scrlttr2}
\usepackage{babel,blindtext}



\setkomavar{fromname}{Just me}
\setkomavar{fromaddress}{Just some place}

\begin{document}
\begin{letter}{Some one \\ Some Place}
\opening{fsdfsdafs}

\pagegoal=22.1cm % or 629pt-630pt
\blindtext[2]  
\hsize 12cm 

\blindtext[5]
\hsize 16cm

\closing{Best wishes}
\end{letter}
\end{document}

enter image description here enter image description here

Uwe, I am updating my answer not to correct what I already said, but to advise against using parshape. Parshape just squeezes the length of the lines but with no purpose whatsoever, than to shape the boxes therein. So in other words, its purpose is to compress according to the specified dimensions. and nothing else. It's in the same category than hangafter and hangindent. This is one of the reasons why it could be used, as long as the input is text, not so much as when you'd like to include something else. So it does not matter, whether you repeat three times: ''Knuth is the man with the master plan'' because even Knuth designed it that way.

So for example:



\documentclass[ngerman,12pt]{scrlttr2}
\usepackage{babel,blindtext}
\usepackage{lipsum}

\setkomavar{fromname}{Just me}
\setkomavar{fromaddress}{Just some place}

\begin{document}
\begin{letter}{Some one \\ Some Place}
\opening{fsdfsdafs}

\parshape 1 0pt 11.5cm \medskip %In your case with 12cm of width, you could apply deliberately some infinite glue with vfill
 \blindtext[2]

\parshape 1 1pt 450pt
\lipsum[3]

\closing{Best wishes}
\end{letter}
\end{document}

enter image description here enter image description here

Could work, but like I said, it is impractical, if you want to include something else.

A better option would be to use everypar with the desired dimensions, which contrarily to parshape, will allow you to insert floats and graphics, and whatnot. Of course, pagegoal would still be my first choice.

Like this:



\documentclass[ngerman,12pt]{scrlttr2}
\usepackage{babel,blindtext}
\usepackage{lipsum}
\usepackage{wrapfig,graphicx}

\setkomavar{fromname}{Just me}
\setkomavar{fromaddress}{Just some place}


\begin{document}
\begin{letter}{Some one \\ Some Place}
\opening{fsdfsdafs}

\parshape 1 0pt 11.5cm \medskip
 \blindtext[2]

\parshape 1 1pt 390pt
\lipsum[3]

\pagegoal= 750pt 
\begin{wrapfigure}{r}{0.35\textwidth}
\includegraphics[width=0.25\textwidth]{/TeXlogo}
\end{wrapfigure}
\lipsum[2]

\everypar{\hsize 12cm}\begin{wrapfigure}{r}{0.35\textwidth}
\includegraphics[width=0.25\textwidth]{/TeXlogo}
\end{wrapfigure}
\lipsum[1]

\everypar{\hsize 8cm}
\lipsum[2]

\closing{Best wishes}
\end{letter}
\end{document}

enter image description here enter image description here enter image description here

share|improve this answer
1  
As I said in comments, it is possible in easy cases such as this, where the change is happening between paragraphs. If the change is happening mid paragraph, especially if the paragraph extends a long way into the next page (which means pagegoal doesn't have much useful information outside the out put routine) then it is much harder, –  David Carlisle Nov 4 '13 at 13:22
1  
Also you should always use a list environment rather than changing \hsize directly otherwise all latex display environments will not do the right thing after the change. –  David Carlisle Nov 4 '13 at 13:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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