1

(I'll use $+$ for the "symbol" in question).

What I want to achieve:

+1. Section

Lorem ipsum

1.1. Subsection

Lorem ipsum

That is,

  • Have every section name after a $+$ and the section number
  • Have every subsection name after the section number and the subsection number (no $+$ before the section number).

I'm using a report type document and I currently have a code that uses

\titleformat{\section}[hang]{\bfseries}{\LARGE\thesection}{1em}{\LARGE #1}
\renewcommand{\thesection}{$+ \,$\arabic{section}}
\titleformat{\subsubsection}[hang]{\bfseries}{\large\thesubsubsection}{1em}{\large #1}

which compiles documents of the form

+1. Section

Lorem ipsum

+1.1. Subsection

Lorem ipsum

Not the desired result.

How can I make my document look like the first example?

5
  • Are you using titlesec?
    – Bernard
    Mar 13, 2022 at 20:47
  • @Bernard , yes, I'm using titlesec. Mar 13, 2022 at 20:52
  • 1
    In this case, add the symbol at the relevant place of \titleformat{\section}{…}
    – Bernard
    Mar 13, 2022 at 20:58
  • @Bernard, well, that was pretty easy lol. Thanks :) Mar 13, 2022 at 21:01
  • 2
    It depends on whether you want the + also when you reference to sections with \ref.
    – egreg
    Mar 13, 2022 at 21:15

1 Answer 1

2

The following solution, which does not require loading any external packages, has the added advantage of not messing up the ability to create cross-references to section-level headers via the standard LaTeX \label-\ref approach. (A command such as \renewcommand{\thesection}{$+ \,$\arabic{section}} does affect how cross-references look -- probably not the intended outcome, though.) Instead, it relies on some code I learned about years ago, when I studied the book "The LaTeX Companion".

enter image description here

\documentclass{article} % or some other suitable document class

% See p. 21 of "The LaTeX Companion", 2nd ed.
\makeatletter 
\def\@seccntformat#1{\@ifundefined{#1@cntformat}%
   {\csname the#1\endcsname\quad}%    default
   {\csname #1@cntformat\endcsname}}% enable individual control
\newcommand\section@cntformat{$+$\thesection.\quad}    % section level 
\newcommand\subsection@cntformat{\thesubsection.\quad} % subsection level 
\makeatother

\begin{document}
\section{Section} \label{sec:uno}
Lorem ipsum.
\subsection{Subsection}
A cross-reference to section \ref{sec:uno}.
\end{document}

You must log in to answer this question.

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