TeX - LaTeX Asked by Cabin on February 24, 2021
Using all three tocloft, titlesec and tcolorbox packages result in a messed up formatting in the table of contents.
Here is a MWE
% !TEX program = xelatex
documentclass{article}
usepackage{tcolorbox}
usepackage[titles]{tocloft}
usepackage{titlesec}
begin{document}
begin{tcolorbox}[colback=gray!4,arc=5pt,opacityframe=0]
tableofcontents
end{tcolorbox}
section{FIRST SEC}
subsection{First subsection}
subsection{Second subsection}
section{SECOND SEC}
subsection{Third subsection}
end{document}
which results in the loss of vertical space between subsection and section entries in the ToC as you can see below
Now commenting out usepackage{titlesec} OR removing the tcolorbox environment fix the formatting issue:
I would like to keep using the titlesec package so I cannot comment it out.
Of course I also want to keep the colored background in my ToC.
I have no ideas how and why these packages conflict and would be grateful if someone could provide a solution or workaround.
Thanks in advance.
I don't really know what tcolorbox does to vertical spacing. It appears that you have to »protect« your tableofcontents
like so:
% !TEX program = xelatex
documentclass{article}
usepackage{tcolorbox}
usepackage[titles]{tocloft}
usepackage{titlesec}
begin{document}
begin{tcolorbox}[colback=gray!4,arc=5pt,opacityframe=0]
makeatletter
{cfttoctitlefont contentsname}{cftaftertoctitle}par@starttoc{toc}
makeatother
end{tcolorbox}
section{FIRST SEC}
subsection{First subsection}
subsection{Second subsection}
section{SECOND SEC}
subsection{Third subsection}
end{document}
Correct answer by phil-elkabat on February 24, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP