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}
Educ
  • 4,362
  • Maybe related: https://www.sharelatex.com/learn/Sections_and_chapters, https://tex.stackexchange.com/questions/288966, https://tex.stackexchange.com/questions/292001or https://tex.stackexchange.com/questions/301185 – Dr. Manuel Kuehner May 01 '18 at 08:06
  • 3
    The original file (founded by googling the file name) was created with PDFLaTeX. Probably the best thing to do is to try to contact the authors (look at the IREM website). – Kpym May 01 '18 at 08:09
  • Yes, I know I took it from there, but don't forget that in this community there are many capable people who can do better than those authors. – Educ May 01 '18 at 08:17
  • 3
    @Educ It would be helpful if you post the source if it's known. That saves the people time and effort and shows respect to the original author. – Dr. Manuel Kuehner May 01 '18 at 08:28
  • Okay I'll do that – Educ May 01 '18 at 08:32

1 Answers1

20

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

Skillmon
  • 60,462
  • +1: I should consider soul more often :). How did you come up with \setul{.97ex}{.3ex} (the exact values)? – Dr. Manuel Kuehner May 01 '18 at 08: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 01 '18 at 09:00
  • 5
    @Dr.ManuelKuehner honesty is good for the soul – David Carlisle May 01 '18 at 10:11
  • @DavidCarlisle Perfect play on words. – Dr. Manuel Kuehner May 01 '18 at 10:15
  • I tired to add \includegraphics[width=1cm]{1.jpg} inside the section but it's gives me error – Educ May 01 '18 at 11:16
  • 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 01 '18 at 11:18
  • yes because I want to Illustrate some command of geogebra that's why I have to add picture of tools in argument of \section and subsection – Educ May 01 '18 at 11:19
  • @Educ though I explicitly don't recommend this: If you don't use a ToC, you can include an image in the section's title by using \section{\protect\includegraphics{example-image-duck}}. – Skillmon May 01 '18 at 11:19
  • I would like to use ToC – Educ May 01 '18 at 11:20
  • Should I post new question ? – Educ May 01 '18 at 11:20
  • @Educ turns out using \protect does also work if you use a ToC. But I get another error from my code as soon as I use \tableofcontents. I'll investigate. Asking a new question might be a good idea though. – Skillmon May 01 '18 at 11:23
  • @Educ please ask a new question. There seem to be more issues than I thought in combination of \tableofcontents. – Skillmon May 01 '18 at 11:32
  • https://tex.stackexchange.com/questions/429490/error-adding-includegraphics-in-argument-of-section-or-subsection-with-tableofc – Educ May 01 '18 at 11:35
  • Please edit my english in my above question to be clear – Educ May 01 '18 at 11:35
  • very nice :) and beautifully indented source code – cmhughes May 01 '18 at 11:53
  • @cmhughes thanks, coding style is important for readability. – Skillmon May 01 '18 at 14:05
  • Could you add code which will fix the bibliography header? Right now it just appears as a box. – Isomorphic Twin Feb 22 '19 at 14:00
  • @IsomorphicTwin Could you please add a follow up question which references this answer? The solution might be dependent on the used bibliography packages. – Skillmon Feb 22 '19 at 15:05
  • @Skillmon I've asked a separate question and included the code here: https://tex.stackexchange.com/questions/476173/title-formatting-the-section-makes-the-bibliography-header-disappear?noredirect=1#comment1201961_476173 – Isomorphic Twin Feb 22 '19 at 15:13