我想使用与将 tikzpagenodes 与 crop 包一起使用?- 除了\titleformat*
,没有\titleformat
。为什么?因为在我使用真实文档模板获得的原始代码中,只有(例如):
\titleformat*{\section}{\normalfont\Large\bfseries\color{gray}}
...并且我想添加拇指索引而不显著改变该代码或其输出;并且\titleformat
我需要知道形状是否为[hang]
,以及 { sep } 参数是什么,然后我才能正确复制 - 而且我不知道如何检索这些值。
\titleformat*
因此,通过将下面的 MWE更改为,我得到:
! Package titlesec Error: Entered in horizontal mode.
...但是如果我继续按 ENTER 键,文档就会编译,而且它似乎就是我想要的(尽管可能与输出不一样\titleformat
);在图像上(单击可获得完整分辨率),左边是\titleformat*
,右边是\titleformat
:
通过这篇文章:tikzpicture 无需离开垂直模式,我得到了以下内容 - 它看起来与我相关,但我不确定:
我认为问题不在于 TeX 离开垂直模式 - 如果您将内容捕获到 \vbox 中,则“离开垂直模式”命令将被本地限制在该框中。
是的,但如果我这么做:
\titleformat*{\section}{%
\normalfont\Large\bfseries\color{gray}%
\tikzexternaldisable%
\vbox{\sectioncolouration{\Alph{section}}}%
\tikzexternalenable%
}
...然后插入一个新行;并且
...当我在它前面使用 \nointerlineskip 时我成功了。
... 我试过了\nointerlineskip
,似乎没用。唯一不插入新行的似乎是,\vbox to 0pt {\sectioncolouration{\Alph{section}}}
但这会以另一种方式弄乱布局。
那么 - 我怎样才能将 a\titleformat*
与 a 一起使用tikzpicture
而不出现“水平模式”错误?或者,如何“离开”水平模式而不产生伪影(由于某种原因,没有\leavehmode
,只有\leavevmode
)?
\documentclass[10pt,twoside,openright]{book}
\usepackage[
paperwidth=15cm,
paperheight=20cm,
outer=2.5cm,
inner=2.5cm,
top=2.5cm,
bottom=2.5cm
]{geometry}
\usepackage[a4,center]{crop} % `crop` line
\crop[cam,info] % `crop` line
\usepackage{titlesec}
\usepackage{tikz}
\usetikzlibrary{external,calc}
\usepackage{tikzpagenodes}
%\usepackage{lua-visual-debug}
% \titleformat{\section}[hang]{\normalfont\Large\bfseries\color{black!90}}{\thesection}{1.5em}{\tikzexternaldisable\sectioncolouration{\Alph{section}}}[\tikzexternalenable]
\titleformat*{\section}{%
\normalfont\Large\bfseries\color{gray}%
\tikzexternaldisable%
\vbox{\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}};
\ifx\stockwidth\undefined
\coordinate (b) at (0,0);
\else
\coordinate (b) at (.5\paperwidth-.5\stockwidth,.5\stockheight-.5\paperheight);
\fi
\begin{scope}
\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) + (b)$} |- a.north) -| ({$(current page text area.east) + (b)$} |- a.south) -| cycle;
\ifodd\value{page}
\node at (a -| {$(current page text area.east)!1/2!(current page.east) + .5*(b)$}) {#1};
\else
\node at (a -| {$(current page text area.west)!1/2!(current page.west) + .5*(b)$}) {#1};
\fi
\end{scope}
\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...
\begin{tikzpicture}[remember picture,overlay]
\draw[thick] (current page text area.north east) rectangle (current page text area.south west) ;
\end{tikzpicture}
\newpage
\section{This section starts on an even page}
Some text\dots
\end{document}
答案1
\titleformat
考虑到 的局限性,我不确定你为什么不想使用\titleformat*
。
嗯,这里有一个方法:
\documentclass[10pt,twoside,openright]{book}
\usepackage[
paperwidth=15cm,
paperheight=20cm,
outer=2.5cm,
inner=2.5cm,
top=2.5cm,
bottom=2.5cm
]{geometry}
\usepackage[a4,center]{crop} % `crop` line
\crop[cam,info] % `crop` line
\usepackage{titlesec}
\usepackage{tikz}
\usetikzlibrary{external,calc}
\usepackage{tikzpagenodes}
%\usepackage{lua-visual-debug}
% \titleformat{\section}[hang]{\normalfont\Large\bfseries\color{black!90}}{\thesection}{1.5em}{\tikzexternaldisable\sectioncolouration{\Alph{section}}}[\tikzexternalenable]
\titleformat*{\section}{%
\normalfont\Large\bfseries\color{gray}%
\tikzexternaldisable%
\toks0=\expandafter{\the\everypar}%
\everypar={\sectioncolouration{\Alph{section}}\everypar=\toks0}%
\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}};
\ifx\stockwidth\undefined
\coordinate (b) at (0,0);
\else
\coordinate (b) at (.5\paperwidth-.5\stockwidth,.5\stockheight-.5\paperheight);
\fi
\begin{scope}
\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) + (b)$} |- a.north) -| ({$(current page text area.east) + (b)$} |- a.south) -| cycle;
\ifodd\value{page}
\node at (a -| {$(current page text area.east)!1/2!(current page.east) + .5*(b)$}) {#1};
\else
\node at (a -| {$(current page text area.west)!1/2!(current page.west) + .5*(b)$}) {#1};
\fi
\end{scope}
\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...
\begin{tikzpicture}[remember picture,overlay]
\draw[thick] (current page text area.north east) rectangle (current page text area.south west) ;
\end{tikzpicture}
\newpage
\section{This section starts on an even page}
Some text\dots
\end{document}