Improved version
Here is a possibility using the xkeyval
package and a key-value approach:

The code (explanations below):
\documentclass{article}
\usepackage[explicit]{titlesec}
\usepackage{xkeyval}
\usepackage{tikz}
\usetikzlibrary{tikzmark,calc}
\usepackage{lipsum}
\newlength\LeftSep
\newlength\RightSep
\newlength\TitleWd
\newlength\VertLineWd
\newlength\SpaceBefore
\newlength\SpaceAfter
\newlength\RuleAddition
\newcommand\SectionFont{\normalfont\Large\bfseries}
\newsavebox\TitleBox
\newcounter{tmp}
\setlength\LeftSep{\marginparsep}
\setlength\RightSep{\marginparsep}
\setlength\TitleWd{0.6666\textwidth}
\setlength\VertLineWd{1pt}
\setlength\SpaceBefore{3.5ex plus 1ex minus .2ex}
\setlength\SpaceAfter{2.3ex plus .2ex}
\setlength\RuleAddition{0pt}
\makeatletter
\define@key{fctaylor}{leftsep}{\setlength\LeftSep{#1}}
\define@key{fctaylor}{rightsep}{\setlength\RightSep{#1}}
\define@key{fctaylor}{titlewidth}{\setlength\TitleWd{#1}}
\define@key{fctaylor}{verticalrulewidth}{\setlength\VertLineWd{#1}}
\define@key{fctaylor}{spacebefore}{\setlength\SpaceBefore{#1}}
\define@key{fctaylor}{spaceafter}{\setlength\SpaceAfter{#1}}
\define@key{fctaylor}{sectionfont}{\renewcommand\SectionFont{#1}}
\define@key{fctaylor}{ruleaddition}{\setlength\RuleAddition{#1}}
\newcommand\FCsectionformat[1][]{%
\setkeys{fctaylor}{#1}
\titleformat{\section}
{\SectionFont}{}{0em}
{%
\parbox[t]{1em}{\thesection}\hspace{\LeftSep}%
\stepcounter{tmp}%
\tikz[remember picture]
\draw[overlay,line width=\VertLineWd]
([xshift=-\RightSep,yshift=\dimexpr\ht\strutbox+\RuleAddition\relax]pic cs:start-\thetmp) --
( $ ({pic cs:start-\thetmp}|-{pic cs:end-\thetmp}) + (-\RightSep,\dimexpr+\ht\strutbox-\baselineskip-\RuleAddition\relax)$ );%
\hspace{\RightSep}%
\parbox[t]{\TitleWd}{%
\SectionFont\raggedright\strut%
\tikzmark{start-\thetmp}##1\tikzmark{end-\thetmp}\strut}%
}
\titleformat{name=\section,numberless}
{\SectionFont}{}{0em}
{%
\hspace*{\dimexpr1em+\LeftSep\relax}%
\stepcounter{tmp}%
\tikz[remember picture]
\draw[overlay,line width=\VertLineWd]
([xshift=-\RightSep,yshift=\dimexpr\ht\strutbox+\RuleAddition\relax]pic cs:start-\thetmp) --
( $ ({pic cs:start-\thetmp}|-{pic cs:end-\thetmp}) + (-\RightSep,\dimexpr+\ht\strutbox-\baselineskip-\RuleAddition\relax)$ );%
\hspace{\RightSep}%
\parbox[t]{\TitleWd}{%
\SectionFont\raggedright\strut%
\tikzmark{start-\thetmp}##1\tikzmark{end-\thetmp}\strut}%
}
}
\titlespacing*{\section}
{0pt}{\SpaceBefore}{\SpaceAfter}
\titlespacing*{name=\section,numberless}
{0pt}{\SpaceBefore}{\SpaceAfter}
\makeatother
\FCsectionformat
\begin{document}
\section{This is a test numbered section with a long title}
\lipsum[4]
\section*{This is a test unnumbered section with a long title}
\lipsum[4]
\section{This is a test numbered section}
\lipsum[4]
\section*{This is a test unnumbered section}
\lipsum[4]
\FCsectionformat[
leftsep=30pt,
rightsep=20pt,
verticalrulewidth=4pt,
titlewidth=\dimexpr\textwidth-2.5em-\RightSep-\LeftSep-\VertLineWd\relax,
spacebefore=1cm,
spaceafter=0.5cm,
sectionfont=\normalfont\LARGE\itshape,
ruleaddition=10pt
]
\section{This is a test numbered section with a long title}
\lipsum[4]
\section*{This is a test unnumbered section with a long title}
\lipsum[4]
\section{This is a test numbered section}
\lipsum[4]
\section*{This is a test unnumbered section}
\lipsum[4]
\end{document}
Explanation:
The main command is \FCsectionformat
which can be used anywhere in the document (in the preamble, or in the body of the document), as many times as desired; the command has an optional argument to change the title attributes by using a comma separated list of <key>=<value>
options.
The available keys are:
leftsep=<length>
, the separation between the number and the vertical rule; default: \marginparsep
.
rightsep=<length>
, the separation between the vertical rule and the title; default: \marginparsep
.
verticalrulewidth=<length>
, the thickness of the vertical rule; default: 1pt
.
titlewidth=<length>
, the width of the box to typeset the title; default: 0.6666\textwidth
.
spacebefore=<length>
, space before the title; default: 3.5ex plus 1ex minus .2ex
.
spaceafter==<length>
, space after the title; default: 2.3ex plus .2ex
.
sectionfont=
, the font specification for the title; default: \normalfont\LARGE\itshape
.
ruleaddition=<length>
, the additional length to be added above and below to the vertical rule; default: 0pt
.