# How to set different length for different borderline of a box using tcolorbox?

I would like to create box of example using tcolorbox as the picture below:

and so far this what i got

Here is my code :

\documentclass[justified]{tufte-book}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\newtcolorbox[auto counter, number within=chapter]{example}[1][]{
enhanced,
breakable,
left=0.5em,right=0pt,top=1pt,bottom=1pt,
attach title to upper={},
coltitle={black},
fonttitle={\bfseries},
title={EXAMPLE \thetcbcounter\ },
sharp corners,
frame hidden,
boxrule=0pt,
borderline north={1pt}{0pt}{gray},
borderline west={1pt}{0pt}{blue},
borderline south={1pt}{0pt}{red},
colback={white},
#1
}
\newcommand\solution{\par\textsf\bfseries{\textbf{\textcolor{black}{SOLUTION }}}}

\begin{document}
\begin{example}
\lipsum[2]
\solution \lipsum[4]
\end{example}
\end{document}


I want the length of borderline north as long as the "example 0.1" text and the length of borderline south just arbitrary horizontal line.

Could someone please improve my code to create the same picture as I post on top. Thanks!

Unless you use a boxed title, there's no node title to be used as reference. Therefore I've changed your style to use a boxed title an inserted a hspace before upper part instead of attach title to upper option. This way has been possible to draw the line over title box. The line below the box is added with a overlay command.

\documentclass[justified]{tufte-book}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\newtcolorbox[auto counter, number within=chapter]{example}[1][]{
enhanced,
breakable,
left=0.5em, right=0pt, top=1pt, bottom=1pt,
attach boxed title to top left={yshift=-\tcboxedtitleheight},
boxed title style={%
empty,
right=0pt,
frame code={\draw[line width=1pt, gray] (frame.north west)--(frame.north east);}},
before upper=\hspace{\tcboxedtitlewidth},
colbacktitle=white,
coltitle={black},
colback={white},
fonttitle={\bfseries},
title={EXAMPLE \thetcbcounter\ },
sharp corners,
frame hidden,
boxrule=0pt,
borderline west={1pt}{0pt}{blue},
overlay unbroken and last={%
\draw[line width=1pt, red] (frame.south west)   -- ++(0:1cm);},
#1
}
\newcommand\solution{\par\textsf\bfseries{\textbf{\textcolor{black}{SOLUTION }}}}

\begin{document}
\begin{example}
\lipsum[2]
\solution \lipsum[4]
\end{example}
\end{document}


• wow thanks @Ignasi, thats exactly what i was looking for. btw if you dont mind, i have another question. What to do if i want to fill the boxed title with some color? – alitob Sep 11 '18 at 1:31
• Comment empty inside boxed title style and change colbacktitle to something not white. – Ignasi Sep 11 '18 at 6:38
• oh i see, thx @Ignasi! – alitob Sep 16 '18 at 13:33