12

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}
5

1 Answer 1

22

If you're using LuaLaTeX, use the version below with lua-ul.

soul based solution

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

lua-ul based solution

This is practically the same, but using lua-ul instead of soul:

\documentclass{article}
\usepackage{xcolor}
\usepackage[explicit]{titlesec}
\usepackage{lua-ul}

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

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

\newbox\TitleUnderlineTestBox
\newcommand*\TitleUnderline[1]
  {%
    \begingroup
      \setbox\TitleUnderlineTestBox\hbox{\colorbox{titleblue}\strut}%
      \underLine[height=.3ex, bottom=-\dp\TitleUnderlineTestBox]{#1}%
    \endgroup
  }
\newcommand*\SectionNumberBox[1]
  {%
    \colorbox{titleblue}
      {%
        \makebox[2.5em][c]
          {%
            \color{white}%
            \strut
            \csname the#1\endcsname
          }%
      }%
    \kern-.1em\TitleUnderline{\kern.1em\ \ \ \kern.1em}\kern-.1em
  }
\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

19
  • +1: I should consider soul more often :). How did you come up with \setul{.97ex}{.3ex} (the exact values)? Commented May 1, 2018 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
    Commented May 1, 2018 at 9:00
  • 5
    @Dr.ManuelKuehner honesty is good for the soul Commented May 1, 2018 at 10:11
  • @DavidCarlisle Perfect play on words. Commented May 1, 2018 at 10:15
  • 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
    Commented May 1, 2018 at 11:18

You must log in to answer this question.

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