Titlesec:章节位于顶部边缘

Titlesec:章节位于顶部边缘

我怎样才能将章节或节标题放入页边距,以使其位于页面顶部?

这就是我要的:

在此处输入图片描述

但以下 MWE 产生

\documentclass{book}
\usepackage{lipsum,titletoc,marginnote}
\usepackage[explicit]{titlesec}

\usepackage{geometry}
% page layout
\geometry{%
    showframe,
    top=4cm,
    headsep=1.5cm,
    bottom=3cm,
    innermargin=3.0cm,
    textwidth=300pt,
    marginparwidth=4.0cm,
    marginparsep=1.5cm,
    heightrounded,
}%

\titleformat{\chapter}[rightmargin]{\Large}{Chapter~\thechapter}{10pt}{#1}


\begin{document}


\chapter{Background}

\lipsum[1]

% the following is needed or the chapter will not be displayed at all
\section{Related Work} 
\lipsum[99]

\end{document}

在此处输入图片描述

答案1

以下是基于display风格的解决方案:

\documentclass{book}
\usepackage{lipsum,titletoc,marginnote, array}
\usepackage[explicit]{titlesec}
\usepackage[x11names]{xcolor}

\usepackage{geometry}
% page layout
\geometry{%
    showframe,
    top=4cm,
    headsep=1.5cm,
    bottom=3cm,
    innermargin=3.0cm,
    textwidth=300pt,
    marginparwidth=4.0cm,
    marginparsep=1.5cm,
    heightrounded,
}%

\titleformat{\chapter}[display]{\LARGE\filleft\sffamily\bfseries\color{SlateGray3}}{}{0pt}{\leavevmode%
\rlap{\hskip\marginparsep\smash{\begin{tabular}[t]{@{} >{\centering}p{\marginparwidth}@{}}Chapter~\thechapter\\#1\end{tabular}}}}[\vskip-2.63ex]%
\titlespacing{\chapter}{0pt}{-9ex}{0pt}

\begin{document}


\chapter{Background}

\lipsum[1]

% the following is needed or the chapter will not be displayed at all
\section{Related Work}
\lipsum[99-102]

\end{document}

在此处输入图片描述

答案2

你可以使用该rightmargin安置,但你需要成为\chapter该班级的成员straight

\documentclass{book}
\usepackage{titlesec,marginnote}
\usepackage{etoolbox}
\usepackage{lipsum}

\usepackage{geometry}
% page layout
\geometry{%
    showframe,
    top=4cm,
    headsep=1.5cm,
    bottom=3cm,
    innermargin=3.0cm,
    textwidth=300pt,
    marginparwidth=4.0cm,
    marginparsep=1.5cm,
    heightrounded,
}%

\titleclass{\chapter}{straight}
\titleformat{\chapter}[rightmargin]
  {\Large}
  {\makebox[0pt][l]{Chapter~\thechapter}}
  {10pt}
  {\marginchapter}
\preto\chapter{\cleardoublepage}
\newcommand{\marginchapter}[1]{%
  \makebox[0pt][l]{%
    \parbox[t]{\marginparwidth}{%
      \raggedright#1%
    }%
  }%
}

\begin{document}

\chapter{Background}

\lipsum[1]

\section{Related Work} 
\lipsum[99]

\end{document}

在此处输入图片描述

相关内容