# Section like heading with Tikz

I'm trying to make a new section-like heading with TikZ. I basically want it to look like this (nevermind the funky background):

But I can only get something like this:

In my LaTeX document I call this with:

\problems


And here is the code I use to produce the (unsatisfactory) result above:

\RequirePackage{tikz}

\makeatletter
\pgfdeclareshape{topbot}{
\inheritsavedanchors[from=rectangle]
\inheritanchorborder[from=rectangle]
\inheritanchor[from=rectangle]{center}
\inheritanchor[from=rectangle]{north}
\inheritanchor[from=rectangle]{south}
\inheritanchor[from=rectangle]{west}
\inheritanchor[from=rectangle]{east}
\inheritanchor[from=rectangle]{north east}
\inheritanchor[from=rectangle]{south east}
\inheritanchor[from=rectangle]{north west}
\inheritanchor[from=rectangle]{south west}
\inheritanchor[from=rectangle]{base}
\backgroundpath{%
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@yb}} %left hand vertical line
\pgfpathmoveto{\pgfpoint{\pgf@xb}{\pgf@yb}} %top vertical line
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@ya}}
\pgfpathclose
}%
}
\makeatother

\newcommand{\problems}{
\begin{tikzpicture}
\node[draw,shape=topbot,very thick, minimum width=\paperwidth, text width=.8\paperwidth]
{\large\textbf{Problems for Section~\thesection}};
\end{tikzpicture}}
\titlespacing*{\problems}{-0.25in}{50pt}{0pt}


I was trying to make the bottom left hand corner of the rectangle, and then make left hand side really thick.

Also, I'd like the rectangle to be the width of the page. (This will not be printed – hence I'm not too concerned about margins.)

-
Does this have to be in tikz/pgf? –  Werner Sep 7 '11 at 21:28
@Werner, nope but it should be something pdflatex can use. –  Bart Snapp Sep 7 '11 at 21:39
Both answers below are fantastic!!! –  Bart Snapp Sep 8 '11 at 18:00

Here's a TikZ-free solution using the titlesec package (I wasn't sure about the length intended for the horizontal rule and its overhang, but you can easily change the dimensions):

\documentclass{book}
\usepackage[explicit]{titlesec}
\usepackage{lipsum}

\newcommand\problems{
\begingroup
\titleformat{\chapter}[display]
{\normalfont\large\filright\bfseries}{\Huge}{0pt}
{\hspace*{-1.7cm}##1\vskip-6ex}[\hspace*{-3cm}\rlap{\rule{4ex}{4ex}\rule{\paperwidth}{2pt}}]
\titlespacing*{\chapter}{0pt}{50pt}{20pt}
\chapter*{Problems for section~\thesection}
\endgroup
}

\begin{document}

\setcounter{chapter}{1}\setcounter{section}{1}% just for the example
\problems
\lipsum[1]

\end{document}


-
+1. This is probably The Correct Way to do it, particularly as it will almost certainly compile more quickly than anything done with TiKZ. –  Niel de Beaudrap Sep 7 '11 at 22:53

You can do this best in TiKZ, I think, by using a simple \fill command and using relative co-ordinates, like so:

Source:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}

% Various lengths, vary to taste
\newlength\tablength        \setlength\tablength{20pt}
\newlength\ruledepth        \setlength\ruledepth{2pt}
\newlength\rulelength       \setlength\rulelength{0.95\textwidth}
\newlength\raisetitle       \setlength\raisetitle{1ex}
\newlength\insettitle       \setlength\insettitle{1.5em}

\newcommand\problems{%
\par\noindent
\begin{tikzpicture}
\node [inner sep=0pt] (title) at (0,0) {\bfseries Problems for Section~\thesection};
\coordinate (inner corner) at ($(title.south west) + (-\insettitle,-\raisetitle)$);
\coordinate (outer corner) at ($(inner corner) + (-\tablength,-\ruledepth)$);
\fill [black] (outer corner) -- +(\rulelength,0) -- +(\rulelength,\ruledepth)
-- (inner corner) -- +(0,\tabheight) -- +(-\tablength,\tabheight)
-- cycle;
\end{tikzpicture}%