I'd like to add symbols/rules/tikz drawing at the end of a title to obtain something like:
or
I tried to define something like:
\titleformat{\section}[runin]{\normalfont\Large\bfseries}{\thesection}{1em}{}[{\xrfill[1pt]{8pt}[secondaryColor]}\\]
(the {} seems to be necessary or it wont compile), but the spacing and indentation is wrong after the section:
the proper indentation and spacing being:
what is the proper way to get a proper spacing with \titlesec?
MWE: Note that for the tikz drawing, I've no idea if it's the best way to proceed (I use 3 tikz pictures, 2 with remember picture spaced with hfill, and one overlay in charge of the drawing), but I can't find any better way to get the position of the start/end of the current line. Let me know if you know one.
\documentclass[]{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\usepackage{lipsum}
\newcommand{\mytikzDrawing}{%
% Ugly trick to find start/end of line... happy to hear better solutions.
\begin{tikzpicture}[remember picture]
\node[inner sep=0pt] (startPosition) {\phantom{X}};
\end{tikzpicture}\hfill\begin{tikzpicture}[remember picture]
\node[inner sep=0pt] (endPosition) {\phantom{X}};
\end{tikzpicture}%
\begin{tikzpicture}[remember picture,overlay]
% \node[fill=blue!50,minimum width=\linewidth,minimum height=3mm] {AAA};
\fill[left color=red!30, right color=yellow!30] (startPosition.north west) -- (endPosition.north east) -- (endPosition.south east) -- (startPosition.south west) -- cycle;
\draw[decorate,decoration=snake,draw=blue!50] (startPosition.east) -- (endPosition.west);
\end{tikzpicture}%
}
\usepackage{verbatim}
\usepackage{xhfill} % To draw color \hrulefill https://tex.stackexchange.com/a/155960/
\usepackage{xcolor}
\definecolor{secondaryColor}{RGB}{255,236,209}
\usepackage{titlesec}
%% Bad spacing after:
%\titleformat{\section}[runin]{\normalfont\Large\bfseries}{\thesection}{1em}{}[{\xrfill[1pt]{8pt}[secondaryColor]}\]
% or with the tikz version:
% \titleformat{\section}[runin]{\normalfont\Large\bfseries}{\thesection}{1em}{}[\ \mytikzDrawing\]
\begin{document}
Here is what I get when using nothing:
\section{Hello}
I'd prefer to get something like that (the problem being the spacing):\
\noindent{\normalfont\Large\bfseries 2 \hspace{.3em} A simple version \xrfill[1pt]{8pt}[secondaryColor]}\
Or something like that:
\noindent{\normalfont\Large\bfseries 3 \hspace{.3em} A complex version \mytikzDrawing{}}
\lipsum[1]
\end{document}




