本章最后一页的标题宽度

时间:2009-05-06 11:52:06

标签: latex

我正在尝试使用这个使用multicols和chngpage包的新环境启动新的multicols环境时关闭marginpar:

\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}}

哪个效果很好: latex header http://img6.imageshack.us/img6/6757/screenshotewa.png

嗯,差不多,因为在当前章节“Lorem ipsum”的最后一页上,它表现得像我没有指示它:\ addtolength {\ headwidth} {\ newtextwidth}: latex header at the end of the chapter http://img11.imageshack.us/img11/6072/screenshotwbd.png

我该如何解决?

修改

我也在使用fancyhdr。

第二次修改

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}

应该可以在“multi”之后在同一页面上继续单列,但是必须像在“多”环境中启动页面一样保留标题。

为什么我需要在具有marginpar的同一页面上的多列之后使用单列?想象一下,展示文章的源代码,边缘有一些小提示。 (这就是上市包的用途)

2 个答案:

答案 0 :(得分:7)

我怀疑你的文字完成制作多元素盒后你的最后一个标题框正在构建,所以你不在你的变化范围内。它可以追溯到旧的价值。

您可能最好添加fancyhdr包并使用它。我相信它在多列中表现得很好。

好的,所以这几乎可以肯定是范围的事情。您正在新的multi环境中执行adjustwidth。当您的文本在多个环境中用完时,您还没有填写最后一页;页面填充后才会设置标题。所以你的mutlti环境完成了框,你离开了范围,然后页面完成并发出。使用旧的宽度。

在环境外设置标题宽度和参数。

答案 1 :(得分:5)

我运行了你的测试文件。它似乎有一个错误,\newlength{\newtextwidth}具有全局效应,因此导致错误。不知道为什么会这样,但我把它从\newenvironment{multi}中拉出来没有任何不良影响。

查理的诊断肯定是正确的。另一种解决方案是在多核之后但在调整宽度之前结束页面,因此:

\newenvironment{multi}[1]{%
   ...}
{\end{multicols}\vfill\break\end{adjustwidth}}

我已经测试了这个解决方案,并且在您的示例文档中,它可以产生良好的输出。

相关问题