TeX - LaTeX Asked by Addison Klinke on July 29, 2020
I have two tasks I’m trying to accomplish, both of which I found independent solutions for on other threads. However, when the solutions are used in combination they conflict so I’m looking for an approach that is compatible with both
Task 1: use alpha labels for subsections (i.e. A, B, C, etc). This can be accomplished with renewcommandthesubsection{Alph{subsection}}
as suggested in @GonzaloMedina’s answer
Task 2: automatically add section*
entries to the TOC. This answer by @egreg suggests sticking with plain section
and using setcounter{secnumdepth}{0}
to remove the numbering in the TOC
If I were able to successfullly combine these two tasks (which I haven’t), my desired rendering would look like the following
However, using @egreg’s solution for task 2 causes the A, B, C subsection labels to disappear. I tried another suggestion from the same thread by @MikeRenfro to add renewcommand{thesection}{}
, but as the author mentions, it leaves unnecessary indents which are not aesthetically pleasing. On a separate thread, @Vser suggests addcontentsline{toc}{section}{nameref{sec:intro}}
, but in my testing this left a line of pure ...
without auto-populating the section name. The manual work to enter each name without the help of nameref
would be too time-consuming and difficult to maintain.
EDIT 7/28/20: In my actual document, I’m using tcolorbox
to help visually define the section headers. For instance, the following MWE along with it’s rendering
documentclass[a4paper,10pt,twocolumn]{book}
usepackage{cuted}
usepackage{tcolorbox}
usepackage[explicit]{titlesec}
setcounter{tocdepth}{1}
titlespacing*{section}{0pt}{0pt}{0pt}
titleformat{name=section, numberless}{setcounter{subsection}{0}normalfontLargebfseries}{}{0pt}{}[addcontentsline{toc}{section}{#1}#1]
renewcommandthesubsection{Alph{subsection}} % Accomplishes task 1
begin{document}
tableofcontents
chapter{Chapter}
begin{strip}
begin{tcolorbox}[title=section*{An unnumbered section}]
Other content here..
end{tcolorbox}
end{strip}
subsection{First Subsection}
subsection{Second Subsection}
end{document}
Originally, I had included titlespacing*{section}{0pt}{0pt}{0pt}
in the preamble to ensure there was no extra space above, below, or left of the section title text. However, the current solution by @Bernard adds an extra blank row above the section header as seen in the rendering
You can get what you want with titleformat
, the numberless
key and the explicit
option from titlesec:
documentclass{book}
usepackage[explicit]{titlesec,}
setcounter{tocdepth}{1}
titlespacing*{section}{0pt}{0pt}{0pt}
titleformat{name=section, numberless}{setcounter{subsection}{0}normalfontLargebfseries}{}{0pt}{}[addcontentsline{toc}{section}{#1}#1]
renewcommandthesubsection{Alph{subsection}} % Accomplishes task 1
begin{document}
tableofcontents
chapter{Chapter}
section{A numbered section}
subsection{Subsection}
section*{An unnumbered section}
end{document}
Answered by Bernard on July 29, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP