Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

header width on the last page of the chapter

Tags:

latex

I'm trying to turn off marginpar when starting a new multicols environment with this new environment, which uses the multicols and chngpage packages:

\newenvironment{multi}[1]{%
\newlength{\newtextwidth}%
\setlength{\newtextwidth}{\marginparwidth}%
\addtolength{\newtextwidth}{-1cm}%
\addtolength{\headheight}{.5cm}%
\let\oldheadrule\headrule%
\addtolength{\headwidth}{\newtextwidth}%
\begin{adjustwidth}{}{-\newtextwidth}\begin{multicols}{#1}}%
{\end{multicols}\end{adjustwidth}}

Which works great: latex header http://img6.imageshack.us/img6/6757/screenshotewa.png

Uhm, almost, since on the last page of the current chapter "Lorem ipsum" it behaves like I hadn't instruct it to: \addtolength{\headwidth}{\newtextwidth}: latex header at the end of the chapter http://img11.imageshack.us/img11/6072/screenshotwbd.png

How could I fix that?

Edit:

I'm also using fancyhdr.

2nd Edit:

A PoC:

\documentclass[12pt,a4paper,oneside]{report}
\usepackage[utf8]{inputenc}
\usepackage[top=2cm,left=2cm,right=4.5cm]{geometry}
\usepackage{chngpage}
\usepackage{color}
\usepackage{amsmath}
\usepackage[pdftex,bookmarks,pdfpagemode=UseOutlines,bookmarksopen,backref
,colorlinks,urlcolor=blue,linktocpage]{hyperref}
\usepackage{url}
\usepackage{amssymb}
\usepackage{lipsum}
\usepackage{fancyhdr}
\usepackage{multicol}
\usepackage{indentfirst}
\usepackage{listings}
\usepackage{boxedminipage}
\pagestyle{fancy}

\setlength{\columnseprule}{1pt}

\setlength{\marginparwidth}{4cm}

\rhead{\large\leftmark}
\renewcommand{\chaptermark}[1]{%
  \markboth{#1}{}}

\makeatletter
\renewcommand*\@makechapterhead[1]{%
  {\parindent \z@ \raggedright \normalfont
    \huge\bfseries
    #1\par\nobreak
    \vskip 20\p@
  }}
\makeatother

\let\oldmarginpar\marginpar
\renewcommand\marginpar[1]{\-\oldmarginpar[\sffamily\raggedleft\footnotesize #1]%
{\sffamily\raggedright\footnotesize
\begin{boxedminipage}{\marginparwidth}#1\end{boxedminipage}
}}




\newenvironment{multi}[1]{%
\newlength{\newtextwidth}%
\setlength{\newtextwidth}{\marginparwidth}%
\addtolength{\newtextwidth}{-1cm}%
\addtolength{\headheight}{.5cm}%
\let\oldheadrule\headrule%
\addtolength{\headwidth}{\newtextwidth}%
\begin{adjustwidth}{}{-\newtextwidth}\begin{multicols}{#1}}%
{\end{multicols}\end{adjustwidth}}


\begin{document}
\tableofcontents

\chapter{Lorem ipsum}
\begin{multi}{2}
\lipsum[1-20]
\end{multi}

\chapter{Lorem ipsum}
\begin{multi}{2}
\lipsum[1-20]
\end{multi}

\chapter{Lorem ipsum}
\begin{multi}{2}
\lipsum[1-20]
\end{multi}


\end{document}

It should be possible to continue single-column on the same page, after "multi", but the headers must be kept like when the page was started within the "multi" environment.

Why would I need single-column after multi-column on the same page with a marginpar? Imagine presenting the source code for the article, with small hints on the margin. (That's what the listing package is there for)

like image 327
Flavius Avatar asked Dec 17 '22 08:12

Flavius


1 Answers

I suspect your last heading box is being constructed after your text finishes making the multicol boxes, so you're out of the scope of your change. It goes back to the old value.

You'd probably do well to add the fancyhdr package and use it. I believe it's well-behaved in multicolumn.

Okay, so it's almost certainly the scope thing. You're doing the adjustwidth in your new multi environment. When your text runs out in the multi envirnment, you haven't filled the last page; headers aren't set up until the page is filled. So your mutlti environment finishes the box, you leave the scope, and THEN the page is finished and emitted. Using the old width.

Set the header width and parameters outside the environment.

like image 114
Charlie Martin Avatar answered Feb 19 '23 00:02

Charlie Martin