如何使用来自不同轴上的两个不同节点的 tkiz 点?

如何使用来自不同轴上的两个不同节点的 tkiz 点?

我知道我需要使用节点中的 xcounter和节点中的 y rectangle,但到目前为止我还没有找到正确的语法。

绿色表示我想要填充的内容,红色表示线条应延伸到的位置。

在此处输入图片描述

\documentclass{scrbook}
\usepackage[letterpaper,asymmetric,left=108pt,right=54pt,top=41pt,bottom=41pt,headsep=13pt,headheight=14pt,footskip=23pt,marginparwidth=72pt]{geometry}
\usepackage[compact,explicit,calcwidth]{titlesec}
\usepackage{tikz,lipsum}
\usetikzlibrary{calc}

\setkomafont{section}{\normalfont\bfseries}

\pgfdeclarelayer{background}
\pgfsetlayers{background,main}

\newlength\titlemarginwidth
\setlength\titlemarginwidth{54pt}

\newcommand\boxedsection[1]{{%
  \usekomafont{sectioning}\usekomafont{section}%
  \begin{tikzpicture}[x=1pt,y=1pt,inner sep=0, inner ysep=0.7ex]
    \node[anchor=base west,text width=\titlemarginwidth-\columnsep,color=white] at (0,0) (counter) {\hspace{1ex}\thesection};
    \node[anchor=base west,text width=\textwidth] at ($(counter.base east)+(\columnsep,0)$) (rectangle) {#1};
    \begin{pgfonlayer}{background}
        \fill[color=black] let \p1=(counter.north), \p2=(counter.north) in (0,{max(\y1,\y2)}) rectangle (counter.south east);
        \draw[black,thick] let \p1=(counter.north), \p2=(counter.north) in (0,{max(\y1,\y2)}) -- (rectangle.north east);
        \draw[black,thick] (rectangle.south west) -- (rectangle.south east);
    \end{pgfonlayer}
  \end{tikzpicture}
}}

\titlespacing{\section}{-\titlemarginwidth}{1em}{0em}
\titleformat{\section}[block]
  {}%
  {}{0pt}{\boxedsection{#1}}

\begin{document}
\chapter{Testing One Two Three!}
\section{Extremely long section title that is absolutely absurd and obnoxious that goes on forever and ever and ever and ever!}
\lipsum[1]
\end{document}

在遇到仅使用规则和框来tikz进行间距处理的问题后,我改用了。titlesec

这个答案对我开始非常有帮助。

答案1

let您可以使用垂直坐标系(请参阅 PGF 文档(第 130-131 页));事实上,您根本不需要语法。我还从您的示例中删除了一些冗余代码:

\documentclass{scrbook}
\usepackage[letterpaper,asymmetric,left=108pt,right=54pt,top=41pt,bottom=41pt,headsep=13pt,headheight=14pt,footskip=23pt,marginparwidth=72pt]{geometry}
\usepackage[compact,explicit,calcwidth]{titlesec}
\usepackage{tikz,lipsum}
\usetikzlibrary{calc}

\setkomafont{section}{\normalfont\bfseries}

\pgfdeclarelayer{background}
\pgfsetlayers{background,main}

\newlength\titlemarginwidth
\setlength\titlemarginwidth{54pt}

\newcommand\boxedsection[1]{{%
  \usekomafont{sectioning}\usekomafont{section}%
  \begin{tikzpicture}[x=1pt,y=1pt,inner sep=0, inner ysep=0.7ex]
    \node[anchor=base west,text width=\titlemarginwidth-\columnsep,color=white] at (0,0) (counter) {\hspace{1ex}\thesection};
    \node[anchor=base west,text width=\textwidth] at ($(counter.base east)+(\columnsep,0)$) (rectangle) {#1};
    \begin{pgfonlayer}{background}
        \fill[color=black] (0,0|-counter.north) rectangle (counter.south east|-rectangle.south east);
        \draw[black,thick] (0,0|-counter.north) -- (rectangle.north east);
        \draw[black,thick] (0,0|-rectangle.south west) -- (rectangle.south east);
    \end{pgfonlayer}
  \end{tikzpicture}
}}

\titlespacing{\section}{-\titlemarginwidth}{1em}{0em}
\titleformat{\section}[block]
  {}%
  {}{0pt}{\boxedsection{#1}}

\begin{document}
\chapter{Testing One Two Three!}
\section{Extremely long section title that is absolutely absurd and obnoxious that goes on forever and ever and ever and ever!}
\lipsum[1]
\end{document}

在此处输入图片描述

相关内容