章节最后一页的标题宽度

发布于 2024-07-18 11:54:53 字数 2778 浏览 4 评论 0原文

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

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

效果很好: 乳胶标头 http://img6.imageshack.us/img6/6757/screenshotewa.png< /a>

嗯,几乎,因为在当前章节“Lorem ipsum”的最后一页上,它的行为就像我没有指示它:\addtolength{\headwidth}{\newtextwidth}: 章节末尾的乳胶标题 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”之后应该可以在同一页面上继续单列,但标题必须像在“multi”环境中启动页面时一样保留。

为什么同一页上的多列之后需要单列并带有边距? 想象一下,展示文章的源代码,并在页边空白处添加一些小提示。 (这就是列表包的用途)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空袭的梦i 2024-07-25 11:54:53

我怀疑您的最后一个标题框是在您的文本完成制作多栏框后构建的,因此您超出了更改范围。 它返回到旧值。

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

好的,所以这几乎肯定是范围问题。 您正在新的 multi 环境中进行调整宽度。 当你的文字在多环境下用完时,你还没有写完最后一页; 在页面填满之前不会设置标题。 因此,您的多环境完成了该框,您离开了范围,然后页面完成并发出。 使用旧的宽度。

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

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.

林空鹿饮溪 2024-07-25 11:54:53

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

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

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

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

I ran your test document. It seems to have a bug in that \newlength{\newtextwidth} has a global effect, and so causes an error. Not sure why that is but I pulled it out of the \newenvironment{multi} with no ill effect.

Charlie's diagnosis is definitely correct. An alternative solution is to end the page after the multicols but before the adjustwidth, thus:

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

I have tested this solution and on your sample document, it produces good output.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文