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}

在此輸入影像描述

相關內容