9

I came across to website of IREM which I found beautiful section style in the following file Original file was created with PDFLaTeX.

Could someone please create those styles for sections and subsections with Latex

enter image description here

enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}

\title{Sections and Chapters}
\author{Educ}
\date{\today}

\begin{document}

\maketitle

\section{Plya's Problem-Solving Cycle}
\subsection{Understand the problem}
\subsection{Devise a Plan}
\subsection{Carry Out the Plan}
\subsection{Look Back}
\section{Second Section}


\end{document}
15

Answer based on titlesec and soul:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage[explicit]{titlesec}
\usepackage{soul}

\definecolor{titleblue}{HTML}{4a7aa4}

\title{Sections and Chapters}
\author{Educ}
\date{\today}

\newbox\TitleUnderlineTestBox
\newcommand*\TitleUnderline[1]
  {%
    \bgroup
    \setbox\TitleUnderlineTestBox\hbox{\colorbox{titleblue}\strut}%
    \setul{\dimexpr\dp\TitleUnderlineTestBox-.3ex\relax}{.3ex}%
    \ul{#1}%
    \egroup
  }
\newcommand*\SectionNumberBox[1]
  {%
    \colorbox{titleblue}
      {%
        \makebox[2.5em][c]
          {%
            \color{white}%
            \strut
            \csname the#1\endcsname
          }%
      }%
    \TitleUnderline{\ \ \ }%
  }
\titleformat{\section}
  {\Large\bfseries\sffamily\color{titleblue}}
  {\SectionNumberBox{section}}
  {0pt}
  {\TitleUnderline{#1}}
\titleformat{\subsection}
  {\large\bfseries\sffamily\color{titleblue}}
  {\SectionNumberBox{subsection}}
  {0pt}
  {\TitleUnderline{#1}}

\begin{document}

\maketitle

\section{Plya's Problem-Solving Cycle}
\subsection{Understand the problem}
\subsection{Devise a Plan}
\subsection{Carry Out the Plan}
\subsection{Look Back}
\section{Second Section}

\section
  {Really long section name that is really long, so long it takes two rows}

\end{document}

enter image description here

  • Could you do the same thing for subsection – Educ May 1 '18 at 8:38
  • +1: I should consider soul more often :). How did you come up with \setul{.97ex}{.3ex} (the exact values)? – Dr. Manuel Kuehner May 1 '18 at 8:50
  • @Dr.ManuelKuehner to be honest: trial and error. Latest edit only has .3ex as a "guessed" value (which I think looks good -- one could change that). – Skillmon May 1 '18 at 9:00
  • 5
    @Dr.ManuelKuehner honesty is good for the soul – David Carlisle May 1 '18 at 10:11
  • 1
    @Educ you mean in the argument of \section? Don't do that. Ever. Is that picture supposed to end up in the page's header/footer and ToC, too? – Skillmon May 1 '18 at 11:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.