章节标题包含在书籍文档的双面中

章节标题包含在书籍文档的双面中
\documentclass[11pt,a4paper,twoside,openany]{scrbook}
\usepackage{tikz}
\usepackage[explicit]{titlesec}
\usepackage{blindtext}

\titleformat{\section}[hang]{\large\bfseries}{\thesection\quad}{0pt}{#1}
\titleformat{\subsection}[hang]{\large\bfseries}{\thesubsection\quad}{0pt}{#1}
\titleformat{\subsubsection}[hang]{\large\bfseries}{\quad}{0pt}{#1}
\titlespacing*{\section}{0pt}{0pt}{2pt}
\titlespacing*{\subsection}{0pt}{0pt}{0pt}
\titlespacing*{\subsubsection}{0pt}{0pt}{0pt}

%define chapter-title
\newcommand*\chapterlabel{}
\titleformat{\chapter}
  {\gdef\chapterlabel{}
   \normalfont\sffamily\Large\bfseries\scshape}
  {\gdef\chapterlabel{\thechapter\ }}{0pt}
  {\begin{tikzpicture}[remember picture,overlay]
    \node[yshift=-5cm] at (current page.north west)
      {\begin{tikzpicture}[remember picture, overlay]
        \draw[fill=gray!15, draw=gray] (0,0) rectangle (0.9\paperwidth,3cm);     
    \node[anchor=east,yshift=1.5cm,xshift=0.9\paperwidth, text width=1.05\textwidth]{\textnormal{\textbf{\huge{#1}}}};
       \end{tikzpicture}
      };
   \end{tikzpicture}
   }

\begin{document}
\chapter{One}
\chapter{Two}
\chapter{Three}

\end{document}

在此处输入图片描述

你好,

我希望灰色框始终以内侧页面的镜像如果连续页面上有两个章节(参见第 2 页和第 3 页)。有什么想法吗?

谢谢 Nico

答案1

使用\ifthispageodd{}{}Komma-Script 包的宏,您可以测试页面何时为奇数,从而更改章节的定义。

您没有说明如何处理章节名称。在这种情况下,保留在左侧。如果您想镜像位置,宏\node也应该更改。

\documentclass[11pt,a4paper,twoside,openany]{scrbook}

\usepackage{tikz}
\usepackage[explicit]{titlesec}
\usepackage{blindtext}

\titleformat{\section}[hang]{\large\bfseries}{\thesection\quad}{0pt}{#1}
\titleformat{\subsection}[hang]{\large\bfseries}{\thesubsection\quad}{0pt}{#1}
\titleformat{\subsubsection}[hang]{\large\bfseries}{\quad}{0pt}{#1}
\titlespacing*{\section}{0pt}{0pt}{2pt}
\titlespacing*{\subsection}{0pt}{0pt}{0pt}
\titlespacing*{\subsubsection}{0pt}{0pt}{0pt}

%define chaptertitle-style
\newcommand*\chapterlabel{}
\titleformat{\chapter}
  {\gdef\chapterlabel{}
   \normalfont\sffamily\Large\bfseries\scshape}
  {\gdef\chapterlabel{\thechapter\ }}{0pt}
  {\begin{tikzpicture}[remember picture,overlay]
    \node[yshift=-5cm] at (current page.north west)
      {\begin{tikzpicture}[remember picture, overlay]
        \ifthispageodd{%
          \draw[fill=gray!15, draw=gray] (0,0) rectangle
          (0.9\paperwidth,3cm);       
          \node[anchor=east,yshift=1.5cm,xshift=0.9\paperwidth, text width=1.05\textwidth]{\textbf{\huge{#1}}};
          }%
          {
          \draw[fill=gray!15, draw=gray] (0.1\paperwidth,0) rectangle
          (1\paperwidth,3cm);       
          \node[anchor=east,yshift=1.5cm,xshift=0.9\paperwidth, text width=1.05\textwidth]{\textbf{\huge{#1}}};
          }
        \end{tikzpicture}
      };
   \end{tikzpicture}
   }

\begin{document}
\chapter{One}
\chapter{Two}
\chapter{Three}

\end{document}

答案2

\documentclass[11pt,a4paper,twoside,openany]{scrbook}
\usepackage{tikz}
\usepackage[explicit]{titlesec}
\usepackage{blindtext}

\titleformat{\section}[hang]{\large\bfseries}{\thesection\quad}{0pt}{#1}
\titleformat{\subsection}[hang]{\large\bfseries}{\thesubsection\quad}{0pt}{#1}
\titleformat{\subsubsection}[hang]{\large\bfseries}{\quad}{0pt}{#1}
\titlespacing*{\section}{0pt}{0pt}{2pt}
\titlespacing*{\subsection}{0pt}{0pt}{0pt}
\titlespacing*{\subsubsection}{0pt}{0pt}{0pt}

%define chaptertitle-style
\newcommand*\chapterlabel{}
\titleformat{\chapter}
  {\gdef\chapterlabel{}
   \normalfont\sffamily\Large\bfseries\scshape}
  {\gdef\chapterlabel{\thechapter\ }}{0pt}
  {\begin{tikzpicture}[remember picture,overlay]
    \node[yshift=-5cm] at (current page.north west)
      {\begin{tikzpicture}[remember picture, overlay]
        \ifthispageodd{
          \draw[fill=gray!15, draw=gray] (0,0) rectangle (0.9\paperwidth,3cm);       
          \node[anchor=east,yshift=1.5cm,xshift=0.9\paperwidth, text width=1.05\textwidth]{\textbf{\huge{#1}}};
          }
          {
          \draw[fill=gray!15, draw=gray] (0.1\paperwidth,0) rectangle(1\paperwidth,3cm);       
          \node[anchor=east,yshift=1.5cm,xshift=0.9\paperwidth, text width=1.05\textwidth]{\textbf{\huge{#1}}};
          }
        \end{tikzpicture}
      };
   \end{tikzpicture}
   }

%adjust spacing for correct alignment of following text
\titlespacing*{\chapter}{0pt}{50pt}{0pt}

\begin{document}

\chapter{One}
\blindtext[4]
\chapter{Two}
\blindtext[4]
\chapter{Three}
\blindtext[4]

\end{document}

在此处输入图片描述

这是我的问题的一个工作示例,参考了 TeXtnik 给出的解决方案。

相关内容