1

I would like to draw a circle around \section like in this picture below.

enter image description here

\documentclass[a4paper]{article}

\usepackage{fullpage} % Package to use full page


\title{Understanding Poisson Processes}
\author{Author}

\begin{document}

\maketitle
\section{Introduction}
Differentiation is a concept of Mathematics studied in Calculus. There is an ongoing discussion as to who was the first to define differentiation: Leibniz or Newton.
Differentiation allows for the calculation of the slope of the tangent of a curve at any given point as shown in Figure 1.
\end{document}
  • 3
    do you ever have more than 9 sections? – barbara beeton Oct 15 '17 at 3:06
2

Circling numbers of sections have a irresoluble problem when there are ten or more sections: Or the size of circles change, not very aesthetic if you see can see sections with one and two figures at the same time, (as in the Christian's answer) or your use big circles of fixed size for all the sections (although this is doubtfully elegant when it should be enough big for three digits, as in this answer). If I had to choose, I would choose the second, because seldomly I need write documents with a huge numbers of sections. Otherwise I will choose oval boxes instead of circles to avoid the excessive height of big circles.

To convert this comment into a true answer, here a solution without the predictable tikz approach but titlesec (to avoid \directly@touch\the@latex\@guts) and a classical picture for circles oval boxes. It is added also a simpler solution using fancybox (although their ability to round corners is limited).

mwe

\documentclass{article}
\usepackage{titlesec}
\usepackage{fancybox}
\def\a{Lore ipsum dolor sit amet\ldots}
\begin{document}

\setcounter{section}{4}\section{Introduction}\a  
\setcounter{section}{78}\section{Introduction}\a
\setcounter{section}{168}\section{Introduction}\a 

\titleformat{\section}{\Large\bfseries}{}{0em}{%
\begin{picture}(0,0)
\put(12,4){\circle{28}}
\end{picture}\makebox[1.45em][c]{\thesection}\quad}

\setcounter{section}{4}\section{Introduction}\a  
\setcounter{section}{78}\section{Introduction}\a
\setcounter{section}{168}\section{Introduction}\a 

\titleformat{\section}{\Large\bfseries}{}{0em}{%
\begin{picture}(0,0)
\put(12,4){\oval(28,22)}
\end{picture}\makebox[1.45em][c]{\thesection}\quad}

\setcounter{section}{4}\section{Introduction}\a  
\setcounter{section}{78}\section{Introduction}\a
\setcounter{section}{168}\section{Introduction}\a 


\titleformat{\section}{\Large\bfseries}{}{0em}%
{\fboxsep1ex\cornersize{.7}\ovalbox{\thesection}\quad}

\setcounter{section}{4}\section{Introduction}\a  
\setcounter{section}{78}\section{Introduction}\a
\setcounter{section}{168}\section{Introduction}\a 

\end{document}
  • Thanks for helping me. How do I make the circles/ovals thicker? – Ηλεκτρολόγος Μηχανικός Oct 15 '17 at 14:33
  • @ΗλεκτρολόγοςΜηχανικός Add \thicklines just before \put and change \ovalbox by \Ovalbox. – Fran Oct 15 '17 at 15:35
3

By hacking \@svsec it is possible to insert TikZ nodes that are drawn with circles. Since only section numbers should be circled, a test with \pdfstrcmp is done (works with pdflatex only) and then \circlednumber is called, applying the TikZ code here.

Please note that the numbers are not circled in the ToC this way.

\documentclass[a4paper]{article}

\usepackage{tikz}
\usepackage{xpatch}
\usepackage{fullpage} % Package to use full page

\newcommand{\circlednumber}[1]{%
  \begin{tikzpicture}[baseline=(A.base)]%
    \node[circle,draw,inner sep=1pt,outer sep=1pt] (A) {#1};
  \end{tikzpicture}%
}

\title{Understanding Poisson Processes}
\author{Author}

\makeatletter
\xpatchcmd{\@sect}{%
  \protected@edef\@svsec{\@seccntformat{#1}\relax}%
}{%
  \ifnum0=\pdfstrcmp{#1}{section}%
  \def\@svsec{\circlednumber{\number\value{section}}\quad\relax}%
  \else
  \protected@edef\@svsec{\@seccntformat{#1}\relax}%
  \fi
  }{}{}
\makeatother

\begin{document}

\maketitle
\section{Introduction}
Differentiation is a concept of Mathematics studied in Calculus. There is an ongoing discussion as to who was the first to define differentiation: Leibniz or Newton.
Differentiation allows for the calculation of the slope of the tangent of a curve at any given point as shown in Figure 1.
\subsection{Foo}

\setcounter{section}{9}
\section{Outroduction}
\end{document}

enter image description here

1

Two other possibilities, with titlesec and pstricks:

\documentclass[a4paper]{article}

\usepackage{fullpage} % Package to use full page
\usepackage{titlesec}
\usepackage{pstricks}
\usepackage{auto-pst-pdf} %% to compile with pdflatex

\title{Understanding Poisson Processes}
\author{Author}

\begin{document}

\maketitle

\titleformat{\section}[hang]{\Large\bfseries}{\raisebox{-0.29\height}{\pscirclebox{\thesection}}}{0.6em}{}
\section{Introduction}
Differentiation is a concept of Mathematics studied in Calculus. There is an ongoing discussion as to who was the first to define differentiation: Leibniz or Newton.
Differentiation allows for the calculation of the slope of the tangent of a curve at any given point as shown in Figure 1.


\titleformat{\section}[hang]{\Large\bfseries}{\makebox[0pt]{\raisebox{-0.32\height}{\pscirclebox[shadow=true, shadowsize=2pt]{\thesection}}}}{1.2em}{}
\section{Another Introduction}
Differentiation is a concept of Mathematics studied in Calculus. There is an ongoing discussion as to who was the first to define differentiation: Leibniz or Newton.
Differentiation allows for the calculation of the slope of the tangent of a curve at any given point as shown in Figure 1.


\end{document} 

enter image description here

  • I got an error when using pdflatex to compile. Package auto-pst-pdf Error: "shell escape" (or "write18") is not enabled: auto-pst-pdf will not work!. – Ηλεκτρολόγος Μηχανικός Oct 15 '17 at 14:11
  • @ΗλεκτρολόγοςΜηχανικός· That's right: I forgot to mention that. You have to configure your editor so that it adds this switch to the compiler. -shell-escape for TeX Live or MacTeX, --enable-write18 for MiKTeX. Other possibilities: remove the loading of auto-pst-pdf and compile the traditional way: latex -> dvips -> pstopdf, or compile with xelatex. – Bernard Oct 15 '17 at 16:22

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.