Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I know I need to use the x from the counter node and the y from the rectangle node, but so far the right syntax has eluded me.

Green indicates what I'm trying to fill, and red indicates the where the line should extend to.

enter image description here

\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}

I switched to tikz after having trouble with spacing using just titlesec rules and boxes.

This answer was extremely helpful in getting me started.

share|improve this question
    
(counter|-rectangle) –  JLDiaz Mar 7 '13 at 23:34

1 Answer 1

up vote 7 down vote accepted

You can use the perpendicular coordinate system (refer to the PGF documenation (pp. 130-131)); in fact, you don't need here the let syntax at all. I also suppressed some redundant code from your example:

\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}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.