对齐边注

对齐边注

enter image description here

我正在尝试为 Uni 写一份报告,我需要一些类似的东西边注确实如此。问题是我需要在页面左侧设置两个不同的边距。一个用于章节或节标题,一个用于段落,段落左侧应该有一个块标题,水平对齐标题,但该标题不会出现在目录中。也许这个例子可以让您了解我在寻找什么。

\documentclass[10pt,twoside,a4paper,fleqn]{report}
\usepackage[utf8]{inputenc}
\usepackage[centering,left=4cm,right=1cm,top=1cm,bottom=1cm,includeheadfoot]{geometry}
\usepackage[german]{babel,varioref}
\usepackage{marginnote, scrextend, etoolbox, titlesec}

%always put marginals on the left side of the page
\makeatletter
\patchcmd{\@mn@margintest}{\@tempswafalse}{\@tempswatrue}{}{}
\patchcmd{\@mn@margintest}{\@tempswafalse}{\@tempswatrue}{}{}
\reversemarginpar 
\makeatother

\titlespacing*{\section}{-3cm}{\parskip}{\parskip}
\titlespacing*{\chapter}{-3cm}{\parskip}{\parskip}


\begin{document}
\chapter{Model chapter for a report}
This is the first chapter of the report.

\section{Model section}
\marginnote{This is a marginal}This is the first section of the first chapter of the report

\end{document}

问题是,虽然段落增加了 3 厘米的边距,但边距不会与标题对齐,甚至会被页面边框切断。我知道我可以简单地更改几何设置,但这并不是我所需要的,因为节和章节标题也会被移动到页面中。

答案1

我认为可以通过以下方式实现这些目标:titlesec 包(毫无疑问其他人也是如此!)。我发现它有点巫术色彩(而且,对于像我这样的人来说,文档中应该有更多示例),但这似乎有效:

对于本节

\newcommand{\titlebox}[1]{%
\parbox[t]{2.5cm}{\raggedright #1}}

\titleformat{\section}
           [leftmargin]% type is "marginal"
           {\bfseries}%  format
           {}%           no label used
           {0pt}%        no need for any separation
           {\titlebox}%  command to set title

\titlespacing{\section}
             {3cm}%      width of marginal
             {*1}%       space before
             {*0}%       and after

我们\titlebox{}简单地将其定义为一种方便的方法,即使用一个参数宏将材料排版在适当的框中,右边距不齐。关键(我认为)是第一个参数,\titlespacing它控制边距的宽度。(我假设在边距上增加了额外的 3 厘米以允许标题——在示例中,我设置了 5 厘米的左边距和 2 厘米的右边距。)

对于章节标题,我们使用稍微不同的方法使其适当地悬挂在左边距,但我认为从下面的例子中这一点是显而易见的。

\documentclass{report}
\usepackage[left=5cm,right=2cm,bottom=2cm,top=1cm,includeheadfoot]{geometry}

\usepackage{titlesec}

\newcommand{\titlebox}[1]{%
  \parbox[t]{2.5cm}{\raggedright #1}}

\titleformat{\section}
            [leftmargin]
            {\bfseries}
            {}
            {0pt}
            {\titlebox}

\titleformat{\chapter}
            [hang]
            {\bfseries\Large}
            {}
            {0pt}
            {}
            [{\titlerule[1pt]}]

\titlespacing{\section}
            {3cm}
            {*1}
            {*0}

\titlespacing{\chapter}
            {-3cm}
            {*2}
            {*2}


\setlength{\parindent}{0pt}
\setlength{\parskip}{1ex}


\begin{document}

\chapter{Chapter Heading}

\section{Summary of Work}


The object of this report is to show how one can produce marginal section headings, in this fashion. Similar things could and would need to be done for subsections and the like.

\section{Date}
May 10, 2013, London.

\section{Author}
Paul Stanley.

\end{document}

最终结果:

Revised titles

请注意,我手动设置\parskip只是为了演示目的:对于真实文档,您可能希望使用包来处理此类事情。

答案2

非常感谢大家。我已经知道如何将章节标题移到左边距。titlesec 包中写道:

注意。 \titlespacing 不适用于 \chapter 和 \part,除非您通过 \titleformat、简单设置或 \titleclass 更改其标题格式。

在以下 MWE 中,我设法使一切按应有的方式运行:

\documentclass[10pt,twoside,a4paper,fleqn]{report}
\usepackage[utf8]{inputenc}
\usepackage[centering,left=5cm,right=1cm,top=1cm,bottom=1cm,includeheadfoot]{geometry}
\usepackage[german]{babel,varioref}
\usepackage{marginnote, scrextend, etoolbox, titlesec}

%always put marginals on the left side of the page
\makeatletter
\patchcmd{\@mn@margintest}{\@tempswafalse}{\@tempswatrue}{}{}
\patchcmd{\@mn@margintest}{\@tempswafalse}{\@tempswatrue}{}{}
\reversemarginpar 
\makeatother
\setlength{\parindent}{0cm}

\titlespacing*{\section}{-4.2cm}{\parskip}{\parskip}
\titleformat{\chapter}[display]{\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge}
\titlespacing*{\chapter}{-4.2cm}{\parskip}{\parskip}[{\titlerule[1pt]}]


\begin{document}


\chapter{Model chapter for a report}
This is the first chapter of the report.

\section{Model section}
\marginnote{This is a marginal}This is the first section of the first chapter of the report


\end{document}

enter image description here

这几乎就是我需要的文档结构

至于你的回答,保罗·斯坦利,我知道你做了什么,你将章节和章节标题移到了页边距,这是一种将这种结构引入文档的好方法。我也试过这样做,但教授告诉我们,页边距注释应该是块标题,不应该是出现在目录中或其他地方的标题,而应该是应该为文档带来某种结构的标题。不过我喜欢这种方式,我肯定会考虑在大学之外或为其他教授写一份这样的文档。

再次感谢您的所有帮助,我希望这也能帮助其他人。

编辑:不幸的是,这也会影响文档的目录、总目录、参考书目和索引,但不会影响标题页、目录和词汇表,它们不会移动到文档的左侧。

相关内容