0

I am using the package titlesec to format the titles in my document. As I don't want to have the titles in a closed box (we could use "frame" as format parameter of \titleformat for that), I use a \colorbox between two \titlerule:

\usepackage[explicit]{titlesec}

\titleformat{name=\section}[block]
  {\titlerule\normalfont\bfseries\large}
  {}
  {0pt}
  {\colorbox{LightSteelBlue!75}{\parbox{\dimexpr\columnwidth-2\fboxsep}{\strut\thesection .~#1\strut}}}[\titlerule]

The wanted result is the following: enter image description here

Unfortunately, a tiny white space sometimes appears between the \titlerule of the top and the \colorbox: enter image description here

Also, the \titlerule of the top is sometimes thinner as it should be :

enter image description here

As a reminder the \titleformat is defined as: enter image description here

Here is the tex file i'm working on:

https://www.overleaf.com/read/qwksdgfjgbjt

Can someone find a solution to this problem ? Thank you :)

2
  • Welcome to TeX SX! I have no such problem with the code you osted (after I've completed it with the loading of xcolor. Please post a code that reproduces your problem.
    – Bernard
    Apr 22, 2020 at 12:07
  • @Bernard I posted my code. I think the problem occures when latex try to distribute the content on the whole page length, i.e. on the whole column vertical length in my document.
    – Mathieu
    Apr 22, 2020 at 12:39

2 Answers 2

0

I finally use a the tcolorbox environment with boxrule instead of the colorbox + titlerule:

\usepackage[explicit]{titlesec}
\usepackage[svgnames]{xcolor}

\usepackage{tcolorbox}

\titleformat{name=\section}[block]
  {\vspace{0pt}\normalfont\bfseries\large}
  {}
  {0pt}
  {\begin{tcolorbox}[arc=0pt,outer arc=0pt,
  colback=LightSteelBlue!75,
boxsep=0pt,left=1pt,right=1pt,top=5pt,bottom=4pt, before=\hfill,after=\hfill,
boxrule=0pt,bottomrule=0.5pt,toprule=0.5pt]{\strut~\thesection .~#1\strut}\end{tcolorbox}}[]
0

I propose to do the framed section titles with the longfbox packages, which works with a system of keys, and sis easy to use, with is code in your preamble. In addition, if neede tou can choose the box height:

%%% Section titles %%%
\usepackage{longfbox} 
\usepackage[explicit]{titlesec}

\titleformat{name=\section}[block]
{\normalfont\bfseries\large}%\vspace{0pt}
{}
{0pt}
{\lfbox[border-style={solid, none, solid, none},background-color=LightSteelBlue!75,width =\linewidth-2\fboxsep]{\strut\thesection .~#1\strut}}%

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .