# How to place a section heading inside tikz figure using titlesec and the runin option

I am currently workin on a big tikz figure and I want to place a section heading inside a box, which leads to a problem. A minimal example is here:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage[a4paper]{geometry}
\usepackage{color}
\usepackage{titlesec}
\titleformat{\section}[runin]{\normalfont}{}{1em}{before}[after]
\usepackage{tikz}
\begin{document}
\thispagestyle{empty}
\section{testsection}
\begin{tikzpicture}[inner sep=1pt, scale=1]%
\node[inner sep=2pt, text width=94mm,draw] (0,0){\section{xxx in section yyy}};
\end{tikzpicture}%
\end{document}


The result looks as follows:

The result does not match my expectation. I was expecting, that the section heading is placed inside the box as depicted in the following figure:

The section heading is inside the box, if I replace the titlesec package option "runin" by "hang". But then, the section heading is sourrounded by spaces and boxes and I want to get rid of them, so that the section heading can freely be used as text in the tikz-environment.

Any hints are appreciated.

• I think better is the opposite, putting tikz environment for creating box inside \titleformat. – Salim Bou Jul 23 '15 at 10:13

If I understand what you want: putting section heading inside box with tikz, you can do this with \titleformat command from titlesec with the option explicit

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{lipsum}
\usepackage[a4paper]{geometry}