How to remove Section, SubSection titles?
You can define a \fakesection
that does all the things the regular \section
does except print the actual heading:
\newcommand{\fakesection}[1]{%
\par\refstepcounter{section}% Increase section counter
\sectionmark{#1}% Add section mark (header)
\addcontentsline{toc}{section}{\protect\numberline{\thesection}#1}% Add section to ToC
% Add more content here, if needed.
}
A similar macro for \fakesubsection
would be
\newcommand{\fakesubsection}[1]{%
\par\refstepcounter{subsection}% Increase subsection counter
\subsectionmark{#1}% Add subsection mark (header)
\addcontentsline{toc}{subsection}{\protect\numberline{\thesubsection}#1}% Add subsection to ToC
% Add more content here, if needed.
}
The uses would be \fakesection{some section}
and \fakesubsection{some subsection}
.
I can't see any application for this setting: without any visual clue in the text, a table of contents containing inexistent titles doesn't make sense.
However, one can do it with titlesec
, ensuring that the references will be correct, both in the table of contents and with the \label
-\ref
mechanism.
\documentclass{book}
\usepackage{lipsum}
\usepackage{titlesec}
\makeatletter
\titleformat{\section}[runin]{}{}{0pt}{\@gobble}
\titleformat{\subsection}[runin]{}{}{0pt}{\@gobble}
\makeatother
\titlespacing{\section}{\parindent}{0pt}{0pt}
\titlespacing{\subsection}{\parindent}{0pt}{0pt}
\begin{document}
\tableofcontents
\chapter{Chapter 1}
\section{Section 1}
\subsection{Subsection 1}
Here is lovely paragraph. And notice there is a ``subsection title''
right above me. How do I get rid of that title thingy?
\subsection{Subsection 2}
More stuff:
\[
1+2+3+\cdots+\infty=-\frac{1}{12}
\]
\lipsum[1-10]
\section{Section 2}
\lipsum[1-10]
\end{document}