# Have a picture on the right of a section title in ConTeXt

I am trying to set a picture to the right of a section title. Like this (bad ASCII-Art rendering):

1.2 Section Title           +---------+
| Picture |
Lorem Ipsum                 +---------+


So far, I found the \starthanging command, which curiously exists but is not documented in the wiki at all, although several posts on this site describe it and refer to the wiki.

I tried this:

\section{Section Title}
\starthanging[right]{\tikz{\node[rectangle,draw]{picture};}}
Lorem Ipsum
\stophanging


This works, but puts the picture below the section title. So I tried this instead:

\starthanging[right]{\tikz{\node[rectangle,draw]{picture};}}
\section{Section Title}

Lorem Ipsum
\stophanging


Now the picture just vanishes without a trace. So I tried an alternative approach:

\defineparagraphs[sectionandpicture][n=2]

\startsectionandpicture
\section{Section Title}
\sectionandpicture
\raggedleft
\tikz{\node[rectangle,draw]{picture};}
\stopsectionandpicture

Lorem Ipsum


This works, but shifts all the text after the heading below the picture. Is there a way to do this properly?

• Why not put the picture in the margin? I don't think that you can do the hanging next to the section title without extensive hacking of the core macros. – Henri Menke Jul 31 '18 at 21:41
• @HenriMenke I will try that, I'm not sure that every picture I use fits there. – flyx Aug 1 '18 at 8:51
• Looks like I was wrong :) – Henri Menke Aug 3 '18 at 23:58

To get side floats at a section title you have to change the value for the aligntitle key to float.

\usemodule [visual]

\useMPlibrary [dum]

[section]
[aligntitle=float]

\showframe

\starttext

\startplacefigure [location={right,none}]
\externalfigure [dummy] [width=0.3\textwidth,height=5\lineheight]
\stopplacefigure

\startsection [title=\fakewords{4}{6}]
\fakewords{60}{100}
\stopsection

\stoptext


• This works in general and I will accept it as answer. However, it does not work when the content of the section starts with {\bf whatever} for some reason. – flyx Aug 3 '18 at 12:54
• @flyx When you use side floats with paragraphs which starts with a font switch you have to add \dontleavehmode at the begin of the paragraph, e.g. \dontleavehmode{\bf ...} .... – Wolfgang Schuster Aug 3 '18 at 13:11
• @flyn: Or you \bold{whatever}. – Aditya Aug 3 '18 at 14:53
• @flyx Never start a paragraph with a group. That is a well known problem because TeX will happily insert the contents of \everypar inside this group, reverting the effects when the group is over. – Henri Menke Aug 3 '18 at 23:59
• @Aditya Please undelete your answer. It might not be the optimal solution in this case but might be a viable (if not the only) solution in another. – Henri Menke Aug 4 '18 at 0:00

Wolfgang's solution is the right way to go. I am leaving my older answer here in case someone in a slightly different situation finds this useful.

If you are willing to do some manual tweaks, then the you can use a side float after the section title and move the figure a few lines above. If the section title is large, then you will have to manually break it using \\.

\useMPlibrary[dum]
\usemodule[visual]

\showframe

\starttext
\startsection[title=\fakewords{4}{6}]
\startplacefigure[location={right,none,-3*line}]
\externalfigure[dummy][width=0.3\textwidth,height=5\lineheight]
\stopplacefigure

\fakewords{60}{100}
\stopsection
\stoptext