编辑

编辑

我想要一些“翻盖”(实际上,在印刷术中这些是如何称呼的?是“拇指索引”吗?),它是一种填充,延伸到边缘;这样当你“弯曲”一本书时,你可以更容易地看到某个部分在哪里——类似于:

...除了部分 - 所以类似部分标题的垂直颜色背景,除了只有部分的第一行(或一般而言,具有固定宽度的填充,与部分的第一行对齐)。

我认为我可以用tikz它来做这件事,所以我准备了这个 MWE:

\documentclass[10pt,twoside,openright]{book}

\usepackage{titlesec}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{fit}
\usetikzlibrary{external}

\titleformat*{\section}{%
  \normalfont\Large\bfseries\color{black!90}%
  \tikzexternaldisable%
  %\tikz\node(AA){A};% ! Package titlesec Error: Entered in horizontal mode.
  \tikzexternalenable%
}

\begin{document}
\frontmatter
\mainmatter

\part{Introduction}
\chapter*{The first chapter - without thinking anything else}

\section{The first section - and some more text inside; and some more text inside; and some more text inside}

Blah, blah, blah...

\end{document}

输出 - 以及我想要的效果(我:)用红色标记)看起来像这样(单击可获得完整分辨率):

测试.png

正如消息来源所述,一旦我开始放入\tikz\node(AA){A};节点进行测试,我就会得到! Package titlesec Error: Entered in horizontal mode.

是否可以解决这个问题,而不必包含tikzmarktikzpagenodes包?

作为一个子问题,是否可以解决,以便“翻盖”从部分延伸到外纸边缘 - 无论部分最终位于左手边还是右手边页面?(我仍然主要对“完整”的行边距到边距感兴趣,除了沿着中断\textwidth- 这意味着两个矩形节点)...

答案1

如果您愿意使用tikzpagenodes,您可以使用如下方法:

\documentclass[10pt,twoside,openright]{book}

\usepackage{titlesec}
\usepackage{tikz}
\usetikzlibrary{external}
\usepackage{tikzpagenodes}

\titleformat{\section}[hang]{\normalfont\Large\bfseries\color{black!90}}{\thesection}{1.5em}{\tikzexternaldisable\sectioncolouration{A}}[\tikzexternalenable]

\newcommand*\sectioncolouration[1]{%
  \begin{tikzpicture}[baseline=(a.base), overlay, remember picture, inner xsep=0pt, outer sep=0pt]
    \node  (a) {\phantom{\normalfont\Large\bfseries Xy}};
    \path [fill=blue, fill opacity=.2, even odd rule] (current page.west |- a.north) -| (current page.east |- a.south) -| cycle (current page text area.west |- a.north) -| (current page text area.east |- a.south) -| cycle;
  \end{tikzpicture}}

\begin{document}
  \frontmatter
  \mainmatter

  \part{Introduction}
  \chapter*{The first chapter - without thinking anything else}

  \section{The first section - and some more text inside; and some more text inside; and some more text inside}

  Blah, blah, blah...

\end{document}

边缘着色部分

编辑

这是添加了与部分对应的字母标记的版本:

\documentclass[10pt,twoside,openright]{book}

\usepackage{titlesec}
\usepackage{tikz}
\usetikzlibrary{external,calc}
\usepackage{tikzpagenodes}

\titleformat{\section}[hang]{\normalfont\Large\bfseries\color{black!90}}{\thesection}{1.5em}{\tikzexternaldisable\sectioncolouration{\Alph{section}}}[\tikzexternalenable]

\newcommand*\sectioncolouration[1]{%
  \begin{tikzpicture}[baseline=(a.base), overlay, remember picture, inner xsep=0pt, outer sep=0pt]
    \node  (a) {\phantom{\normalfont\Large\bfseries Xy}};
    \path [fill=blue, fill opacity=.2, even odd rule] (current page.west |- a.north) -| (current page.east |- a.south) -| cycle (current page text area.west |- a.north) -| (current page text area.east |- a.south) -| cycle;
    \ifodd\value{page}
    \node at (a -| {$(current page text area.east)!1/2!(current page.east)$}) {#1};
    \else
    \node at (a -| {$(current page text area.west)!1/2!(current page.west)$}) {#1};
    \fi
  \end{tikzpicture}}

\begin{document}
  \frontmatter
  \mainmatter

  \part{Introduction}
  \chapter*{The first chapter - without thinking anything else}

  \newpage

  \section{The first section - and some more text inside; and some more text inside; and some more text inside}

  Blah, blah, blah...

  \newpage
  \section{This section starts on an even page}
  Some text\dots

\end{document}

字母标记

答案2

@cfr 的解决方案很棒,但由于我正在研究这个问题,所以我将发布一个替代解决方案;它基于:

...我用的技巧是\vadjust如何在横屏和竖屏模式间切换?)摆脱“以水平模式进入”(请注意,它是根据宽度等手动调整的,因此@cfr 的解决方案要好得多):

\documentclass[10pt,twoside,openright]{book}

\usepackage{titlesec}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{fit}
\usetikzlibrary{external}
\usepackage{lua-visual-debug}

\newcommand{\tikzmarkS}[1]{\tikz[overlay, remember picture]\coordinate(#1){};}

\titleformat*{\section}{%
  \normalfont\Large\bfseries\color{black!90}%
  \tikzexternaldisable%
  %\tikz\node(AA){A};% ! Package titlesec Error: Entered in horizontal mode.
  \tikzmarkS{s\arabic{section}}\typeout{s\arabic{section}}%
  \begin{tikzpicture}[remember picture,overlay]
  \typeout{s\arabic{section}}
  \node[rotate=90,minimum width=\baselineskip,minimum height=5.6cm,fill=gray!30,text=white,anchor=south west] at ([yshift=-1.35\baselineskip]s\arabic{section}-|current page.north east) {\arabic{section}};
  \node[rotate=90,minimum width=\baselineskip,minimum height=3.6cm,fill=gray!30,text=white,anchor=north east] at ([yshift=-0.28\baselineskip]s\arabic{section}-|current page.south west) {};
  \end{tikzpicture}%
  \vadjust%
  \tikzexternalenable%
}

\begin{document}
\frontmatter
\mainmatter

\part{Introduction}
\chapter*{The first chapter - without thinking anything else}

\section{The first section - and some more text inside; and some more text inside; and some more text inside}
% can be used outside of section, too:
% \begin{tikzpicture}[remember picture,overlay]
% \typeout{s\arabic{section}}
% \node[rotate=90,minimum width=\baselineskip,minimum height=3cm,fill=gray!30,font=\large\bfseries,text=white,anchor=south west] at ([yshift=-2em]s\arabic{section}-|current page.north east) {\arabic{section}};
% \end{tikzpicture}%


Blah, blah, blah...

\end{document}

...输出为(单击可查看完整分辨率):

测试.png

相关内容