\section
我已使用该包自定义了命令的外观,还使用该包
titlesec
自定义了目录的外观。 但是,似乎新的定义将目录和参考列表都视为章节,导致为它们分配了错误的章节标签。具体来说,目录显示多余的零标签,而参考列表采用与文档中最后一节相同的数字,而不是将计数器增加一。 为了说明这个问题,我提供了一个最小的工作示例。我将不胜感激任何帮助或建议来解决这个问题。感谢您的专业知识。
titletoc
\section
\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{titlesec,titletoc}
\usepackage{tikz}
%======= ToC Contents Style ========%
%======= ========%
\renewcommand{\contentsname}{%
\tikz[baseline={([yshift=-1ex]current bounding box.center)}]
\node[
rectangle,
rounded corners=6pt,
fill=black!85,
inner sep=5pt,
minimum width=30pt, minimum height=25pt]
{\textcolor{white}{Contents} };
}
%======= Section Style ========%
%======= ========%
\titleformat{\section}[block]{\Large\bfseries}{}{0pt}{%
\tikz[baseline={([yshift=-1ex]current bounding box.center)}]
\node[
rectangle,
rounded corners=7pt,
fill=cyan!30!blue,
inner sep=6pt,
minimum width=25pt,
minimum height=8pt]
{
\textcolor{white}{\textbf{\thesection}}
};
}
\numberwithin{equation}{section}
%\numberwithin{figure}{section}
%\numberwithin{table}{section}
\begin{document}
\tableofcontents
\section{Sec 1}
\begin{equation}
1+1=2
\end{equation}
\section{Sec 2}
...
\begin{thebibliography}{1}
\bibitem{Ref} Reference
\end{thebibliography}
\end{document}
输出如下:
答案1
常见问题:您需要对未编号的部分进行单独的设置。
同时,我建议对代码进行一些改进:将特殊的格式分离到专门的宏中有助于保持代码\titleformat
的可读性。
\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{titlesec,titletoc}
\usepackage{tikz}
%======= ToC Contents Style ========%
%======= ========%
\renewcommand{\contentsname}{%
\tikz[baseline={([yshift=-1ex]current bounding box.center)}]
\node[
rectangle,
rounded corners=6pt,
fill=black!85,
inner sep=5pt,
minimum width=30pt, minimum height=25pt]
{\textcolor{white}{Contents} };
}
%======= Section Style ========%
%======= ========%
\titleformat{\section}[block]{\Large\bfseries}{}{0pt}{%
\tikz[baseline={([yshift=-1ex]current bounding box.center)}]
\node[
rectangle,
rounded corners=7pt,
fill=cyan!30!blue,
inner sep=6pt,
minimum width=25pt,
minimum height=8pt]
{
\textcolor{white}{\textbf{\thesection}}
};
}
\numberwithin{equation}{section}
%\numberwithin{figure}{section}
%\numberwithin{table}{section}
\begin{document}
\tableofcontents
\section{Sec 1}
\begin{equation}
1+1=2
\end{equation}
\section{Sec 2}
...
\begin{thebibliography}{1}
\bibitem{Ref} Reference
\end{thebibliography}
\end{document}
我相信你想要全部未编号的章节标题以与“目录”相同的方式排版。您可以通过将上面的代码修改为以下内容来实现这一点。诀窍是最后一个强制参数可以\titleformat
以需要参数的命令结尾:它将传递章节标题。
\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{titlesec,titletoc}
\usepackage{tikz}
%======= ToC Contents Style ========%
%======= ========%
\newcommand{\whiteonblack}[1]{%
\begin{tikzpicture}[baseline={([yshift=-1ex]current bounding box.center)}]
\node[
rectangle,
rounded corners=6pt,
fill=black!85,
inner sep=5pt,
minimum width=30pt,
minimum height=25pt
]{\textcolor{white}{#1}};
\end{tikzpicture}%
}
\newcommand{\whiteonblue}[1]{%
\begin{tikzpicture}[baseline={([yshift=-1ex]current bounding box.center)}]
\node[
rectangle,
rounded corners=7pt,
fill=cyan!30!blue,
inner sep=6pt,
minimum width=25pt,
minimum height=8pt,
]{\textcolor{white}{#1}};
\end{tikzpicture}%
}
%======= Section Style ========%
%======= ========%
\titleformat{\section}[block]
{\Large\bfseries}
{}
{0pt}
{\whiteonblue{\textbf{\thesection}} }
\titleformat{name=\section,numberless}[block]
{\Large\bfseries}
{}
{0pt}
{\whiteonblack}
\numberwithin{equation}{section}
%\numberwithin{figure}{section}
%\numberwithin{table}{section}
\begin{document}
\tableofcontents
\section{Sec 1}
\begin{equation}
1+1=2
\end{equation}
\section{Sec 2}
...
\begin{thebibliography}{1}
\bibitem{Ref} Reference
\end{thebibliography}
\end{document}