2

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}
\geometry{verbose,tmargin=0cm,bmargin=0cm,lmargin=0cm,rmargin=0cm,headheight=0cm,headsep=0cm,footskip=0cm}
\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: resulting output

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: enter image description here

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
2

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}
\geometry{verbose,tmargin=1cm,bmargin=1cm,lmargin=1cm,rmargin=1cm,headheight=0cm,headsep=0cm,footskip=0cm}
\usepackage{color}
\usepackage[explicit]{titlesec}
\usepackage{tikz}

\titleformat{\section}[runin]{\normalfont}{}{1em}{\tikz[baseline=-3pt]%
\node[inner sep=2pt,draw, text width=94mm]{before #1 after};}

\begin{document}
\thispagestyle{empty}
\section{test section}
\section{xxx in section yyy} \lipsum[1]
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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