0

I wanted to incorporate the great looking section formatting from this answer but it gives overfull hboxes for every heading (see here in overleaf). I didn't want to abuse the comments under that answer so instead ask it here.

1 Answers1

1

The following should work without any overfull box warnings and end up with a rectangular box that is just as wide as the textwidth.

In comparison to the original, I replaced \tabcolsep with 2\fboxsep. (Since the default value for \tabcolsep and \fboxsep are 6pt and 3pt, respectively, this should not make any difference, but once you decide to redefine either of them, this will indeed make a difference.) I also substracted 2\fboxrule instead of just \fboxrule, since there is a vertical line on both sides of the table

enter image description here

\documentclass[10pt, a4paper,svgnames, twoside]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[showframe]{geometry}
\usepackage{blindtext}
\usepackage{array, tabulary}
\usepackage[explicit]{titlesec}
\usepackage{blindtext, xcolor}
\definecolor{seccolor}{RGB}{41,48,57}
\newcommand{\hsp}{\hspace{8pt}}
\titleformat{\section}[block]{\Large\bfseries\sffamily\setlength{\fboxrule}{1pt}\color{SlateGrey}}
                              {}
                              {0pt}
                              {\fbox{\begin{tabulary}{\dimexpr\linewidth-2\fboxsep-2\fboxrule}{@{}l!{\vline width 1.2pt}L}\thesection &#1 \end{tabulary}} }

\begin{document}

\setcounter{chapter}{2} \section{Section Title. Some more more text to have a really very very long section title.} \blindtext \section{A much shorter section title} \blindtext

\end{document}

leandriis
  • 62,593
  • Thank you for that answer. In the document, where I want to use this, I want to use \usepackage[headheight=2.6pt, includehead, includefoot, top = 1cm, bottom = 2cm, left = 3cm, right = 4cm]{geometry}. With this line included, your solution also gives a overfull hbox. Is my usage of the geometry package incorrect? – ViktorStein Jan 10 '21 at 21:03
  • If I take the code from my answer and replace \usepackage[showframe]{geometry} with \usepackage[headheight=2.6pt, includehead, includefoot, top = 1cm, bottom = 2cm, left = 3cm, right = 4cm]{geometry}, I get a document that still compiles without any warnings or errors. The reason for the overfull box must be somewhere else in your code. – leandriis Jan 10 '21 at 21:14
  • If I do the same in the above linked overleaf document, I get Overfull \hbox (3.67433pt too wide) in paragraph at lines 22--22. – ViktorStein Jan 11 '21 at 08:42