
면책조항: 본질적으로 어떤 코드도 나에게 원본이 아닙니다. 온라인의 여러 곳에서 얻었습니다(예를 들어 보기 좋은 TOC는 다음에서 가져왔습니다.이 답변.)
내 문제:내 문서에 섹션 번호가 표시되지 않습니다. 나는 그것이 매우 간단한 수정이라고 확신하지만 찾을 수 없습니다! (titlesec 패키지 문서를 확인했지만 성공하지 못했습니다.)
암호:
\documentclass{article}
\usepackage{array}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{tikz}
\usepackage[T1]{fontenc}
\usepackage[left=20mm, right=20mm,top=15mm,bottom=15mm,includehead=true,headsep=3pt]{geometry}
\usepackage{etoolbox}
\usetikzlibrary{calc}
\usepackage{enumitem}
\usepackage{scalerel}
\usepackage{titlesec}
\usepackage[pdfview=FitB,hidelinks]{hyperref}
%Format the section titles/headings
\newcommand{\colorsection}[1]{%
\colorbox{blue!20}{\parbox{\dimexpr\textwidth}{#1}}}
\titleformat{name=\section}[hang]
{\Large}
{}
{0pt}
{\colorsection}
\titlespacing{\section}{-5mm}{10mm}{\baselineskip}
%change how the TOC appears
\makeatletter
\patchcmd{\l@section}{\begingroup}{\begingroup\hacknumberline}{}{}
\newcommand\hacknumberline{\let\numberline\my@numberline}
\def\my@numberline #1%
{\vbox{\hbox{\kern-\fboxsep
\color{blue!20}%
\rlap{\rule{\dimexpr\linewidth+\fboxsep}{1pt}}%
\kern\fboxsep
}%
\nointerlineskip
\hb@xt@ \@tempdima
{\kern-\fboxsep\colorbox{blue!20}{\color{black}#1.}% I added a dot here
\hfil}%
}%
}
\makeatother
\makeatletter
\renewcommand{\tableofcontents}{\@starttoc{toc}}
\makeatother
\title{MyTOC}
\date{}
\begin{document}
\fontfamily{bch}\selectfont
\maketitle
\tableofcontents
\clearpage
\section{Section 1}
This is Section 1
\subsection{Subsection 1}
Hello
\end{document}
답변1
package 문서에 따르면 titlesec
명령은 \colorsection
섹션 제목만 인수로 가져오므로 번호 매기기를 직접 처리해야 합니다. 아래에 \arabic{section}\quad
; 필요에 따라 수정하세요.
\newcommand{\colorsection}[1]{%
\colorbox{blue!20}{\parbox{\dimexpr\textwidth}{\arabic{section}\quad#1}}}