2

I'm looking for something similar to this example screenshot I took of what my notes (written in Markdown, turned into HTML with pandoc) look like in HTML.

enter image description here

I'd like to have a somewhat similar look when I convert these Notes to PDF, so I'd like to either move the section headings slightly outward (ideally such that subsections are less far out than sections) or of course move all non-section-heading stuff slightly inward, whichever is simpler.

1 Answer 1

1

Solution 1) The most simple way consists in \usepackage{titlesec} and its command \titleformat \titlespacing command.

Option 1 If you want an hard-coded number, you will have to use the starred versions of the sectioning commands and the MWE is :

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[vmargin=25mm,right=25mm,left=50mm,verbose=false]{geometry}
\usepackage{blindtext} % for demonstration only
\usepackage{titlesec}
\titlespacing*{\section}{-5em}{3.5ex plus -1ex minus -.2ex}{2.3ex plus .2ex}
\titlespacing*{\subsection}{-3em}{3.25ex plus -1ex  minus -.2ex}{1.5ex plus .2ex}   
\titlespacing*{\subsubsection}{-1em}{3.25ex plus -1ex  minus -.2ex}{1.5ex plus .2ex}
\begin{document}
\section*{Header one}
\blindtext
\subsection*{Header two}
\blindtext
\subsubsection*{Header three}
\blindtext
\end{document}

where the lengths used are the default values for article class.

Result:sol1pt1

Option 2 If oppositely you want a variable caption and an automatically incremented number, you will also use (i) the explicit option of the package, (ii) an additional counter (iii) \titleformat to put this number after the caption,

The code becomes:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[vmargin=25mm,right=25mm,left=50mm,verbose=false]{geometry}
\usepackage{blindtext}   % for demonstration only
\usepackage[explicit]{titlesec}
\newcounter{flatnum}
\titleformat{\section}[hang]{\normalfont\bfseries\Large}{\relax}{0pt}{\stepcounter{flatnum} #1 \theflatnum}
\titleformat{\subsection}[hang]{\normalfont\bfseries\large}{\relax}{0pt}{\stepcounter{flatnum} #1 \theflatnum}
\titleformat{\subsubsection}[hang]{\normalfont\bfseries\normalsize}{\relax}{0pt}{\stepcounter{flatnum} #1 \theflatnum}

\titlespacing*{\section}{-5em}{3.5ex plus -1ex minus -.2ex}{2.3ex plus .2ex}
\titlespacing*{\subsection}{-3em}{3.25ex plus -1ex  minus -.2ex}{1.5ex plus .2ex}
\titlespacing*{\subsubsection}{-1em}{3.25ex plus -1ex  minus -.2ex}{1.5ex plus .2ex}    
\begin{document}
\section{Section}
\phantomsection
\blindtext
\subsection{Subsection}
\blindtext
\subsubsection{Subsubsection}
\blindtext
\end{document}

where the styles ans lengths used are the default values for article class.

Result:sol1opt2

Solution 2) A more involved solution, but more compatible, will use \usepackage{etoolbox} and its command \patchcmd to change the spacings in the corresponding \@startsection-s. To know which is the default setting, look in latex.tex ( or .ltx), or simpler put \meaning\section and \meaning\subsection etc. in your body text. For the explanation of this command you'd have look to the accepted answer of this question

2
  • titlesec seems sufficient. I actually just used \titlespacing{\section}{-3cm}{1em}{1em} where the -3cm argument indicates 'adding' -3cm to the margin, and then for subsection -2cm and subsubsection -1cm.
    – zaep
    Commented Aug 27, 2019 at 13:59
  • I wasn't quite able to get anything like I wanted with \titleformat so if You had something specific in mind, feel free to expand your answer.
    – zaep
    Commented Aug 27, 2019 at 14:00

You must log in to answer this question.

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