4

I'm using the memoir class and the adjustwidth* environment to extend some parts of the text beyond the outer margins. It's a twoside document and if understand correctly the changepage package manual (which I believe is loaded with the memoir class), the starred environment should handle the switch between odd and even pages automatically.

It doesn't work for continuing paragraphs as stated in the memoir manual:

enter image description here

In fact, an additional lipsum paragraph that I inserted in order to check that statement (originally though that it applied only to the unstarred version of adjustwidth) seems to prove that it applies to the starred environment as well.

Is there any sensible way to automatically switch the margin that is being adjusted, for the case of paragraphs that cross pages? (I'm guessing this would have been included in the package if it were easy.)

For what it's worth I'm actually trying to temporarily change the margins for text that is inside a shaded environment or a tcolorbox that can cross pages.

A minimal working example is

\documentclass[10pt,twoside,onecolumn,openright,extrafontsizes,final]{memoir}      
\usepackage{lipsum}

\begin{document}

\lipsum[1-2]

\strictpagecheck
\begin{adjustwidth*}{}{-30mm}
\lipsum[20-25] 
\end{adjustwidth*}

\lipsum[3]

\begin{adjustwidth*}{}{-30mm}
\lipsum[4] 
\end{adjustwidth*}

\end{document}

The result for page 1:

And for page 2:

Notice that the paragraphs that cross pages are extended on the wrong side of the page. On the contrary, the last paragraph in page 2 is set correctly.

3
  • 3
    This remains an open problem. I don't think there are fully automated solutions, but you can do it with \parshape.
    – Werner
    Jan 23, 2019 at 23:34
  • 1
    ...another possibility is to break the paragraph into boxes once you know how many lines should fit on one page and process them separately.
    – Werner
    Jan 23, 2019 at 23:42
  • 1
    I think someone once provided a version that does this, in memoir our general consensus is that adjustwidth should not be used for something that extends page breaks. If that is needed use other tools.
    – daleif
    Jan 24, 2019 at 8:53

2 Answers 2

6

A solution using the tcolorbox package without colors

\documentclass[10pt,twoside,onecolumn,openright,extrafontsizes,final]{memoir}  
\usepackage{tcolorbox}
\tcbuselibrary{breakable}
\newtcolorbox{enlargedparbox}[1][30mm]{
                              parbox=false,
                              grow to right by=#1,
                              breakable,
                              toggle enlargement=evenpage,
                              size=minimal,
                              colback=white,
                              before upper={\indent},
                              extras={frame empty}}
\usepackage{lipsum}

\begin{document}
\textbf{ Normal paragraph width}

\lipsum[1-2]

\textbf{ Enlarged paragraph width by 30 mm (default value)}

\begin{enlargedparbox}
\lipsum[20-25]
\end{enlargedparbox}

\textbf{ Normal paragraph width}

\lipsum[3]

\textbf{ Enlarged paragraph width by 20mm}
\begin{enlargedparbox}[20mm]
\lipsum[20-25]
\end{enlargedparbox}

\textbf{ Normal paragraph width}

\lipsum[1-2]


\end{document}

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

2
  • 1
    Looks like the magic happens in the toggle enlargement=evenpage option of tcolorbox. Jan 24, 2019 at 16:08
  • @ShreevatsaR LaTeX is magic! Jan 24, 2019 at 16:18
2

As @Werner said this is, in general, an open problem in that TeX sets a complete paragraph at a time and doesn't take any account of page breaks and possible layout changes within a paragraph.

Knuth wrote (TeX book exercise 14.15): ... the computers memory capacity might be exceeded if you are typesetting the works of some philosopher or modernistic novelist who writes 200-line paragraphs. Suggest a way to cope with such authors.

And he answered (TeX book answer 14.15): ... the remedy is to insert {\parfillskip=0pt\par\parskip=0pt\noindent} in random places, after every 50 lines or so of text. (Every space between words is usually a feasible breakpoint, when you get sufficiently far from the beginning of a paragraph.)

I implemented a macro in memoir following this as

\newcommand{\parnopar}{\parfillskip=0pt\par%
  \parskip=0pt\noindent}

which was meant to invisibly break a long paragraph into two. On the test cases I tried it, it worked when the original paragraph was very long and I put \parnopar about the middle of the text.

So I was going to suggest to the OP to put \parnopar in the running text just after the last word on the first page. However, doing some experiments on shorter paragraphs that was not a good solution as it led to strange spacing at the end of the second "split paragraph".

A better solution is defining a macro as

\newcommand{\parnoparc}{\parfillskio=0pt\par%
  \parskip=0pt\noindent\parfillskip=0pt plus1fil}

Which when used will reset the \parfillskip to the default for any following paragraphs.

Insert this in the running text just after (or before) the last word on the line where you need to (invisibly) start a new paragraph.

Perhaps someone might like to produce a package about this but if so please let me know beforehand.

3
  • 1
    Perhaps a better defintion of \parnopar is newcommand{\parnopar{{\parfillskip=0pt\par\parskip=0pt\noindent}} enclosing the length changes within a group. Jan 27, 2019 at 21:41
  • 1
    Related to long paragraphs: Components of (La)TeX's memory usage
    – Werner
    Jan 27, 2019 at 21:54
  • Memoir already use the {{...}} version of \parnopar (since 2010).
    – daleif
    Jan 29, 2019 at 11:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .