titlesec 包中的子节问题

titlesec 包中的子节问题

我想框出部分编号,但我搜索了所有地方,但没有找到解决方案在此处输入图片描述

\documentclass{book}
\usepackage{lipsum}
\usepackage{titlesec}
\usepackage{tikz}

\titleformat{\section}%
    {\bfseries\LARGE }%
    {\begin{tikzpicture}[overlay]
     \node[xshift=-0.25cm,fill=blue,circle,text=white] {\bfseries\LARGE{}\thesection};
    \end{tikzpicture}}%
    {.75cm}{\textcolor{blue}{#1}}{}
    \renewcommand*{\thesection}{\Roman{section}}
\titleformat{\subsection}%
    {\bfseries\Large}%
    {\begin{tikzpicture}[overlay]
\node[xshift=0.25cm,fill=olive,circle,text=white] {\sffamily\bfseries\Large{}\thesubsection};
    \end{tikzpicture}}%
    {1.5cm}{\textcolor{olive}{#1}}{}
\renewcommand*{\thesubsection}{\arabic{subsection}}
\titleformat{\subsubsection}%
    {\bfseries\Large}%
    {\begin{tikzpicture}[overlay]
\node[xshift=1cm,fill=orange,circle,text=white] {\sffamily\bfseries\Large{}\thesubsubsection};
    \end{tikzpicture}}%
    {2.5cm}{\textcolor{orange}{#1}}{}
\renewcommand*{\thesubsubsection}{\alph{subsubsection}}

\begin{document}
\chapter{chapter chapter}
\section{ section section section}
\subsection{subsection subsection }
\subsubsection{subsubsection subsubsection}

\lipsum[1]

\end{document} 

期望结果 在此处输入图片描述

答案1

尝试这个:

\documentclass{book}
\usepackage{lipsum}
\usepackage{titlesec}
\usepackage{tikz}

\titleformat{\section}%
    {\bfseries\LARGE }%
    {\begin{tikzpicture}[overlay, baseline=(x.base)]
     \node[xshift=-0.25cm,fill=blue,circle,text=white] (x) {\bfseries\LARGE{}\thesection};
    \end{tikzpicture}}%
    {.75cm}{}
\renewcommand*{\thesection}{\Roman{section}}

\titleformat{\subsection}%
    {\bfseries\Large}%
    {\begin{tikzpicture}[overlay, baseline=(x.base)]
    \node[xshift=0.25cm,fill=olive,circle,text=white] (x) {\sffamily\bfseries\Large{}\thesubsection};
    \end{tikzpicture}}%
    {1.5cm}{}
\renewcommand*{\thesubsection}{\arabic{subsection}}

\titleformat{\subsubsection}%
    {\bfseries\Large}%
    {\begin{tikzpicture}[overlay, baseline=(x.base)]
    \node[xshift=1cm,fill=orange,circle,text=white] (x) {\sffamily\bfseries\Large{}\thesubsubsection};
    \end{tikzpicture}}%
    {2.5cm}{}
\renewcommand*{\thesubsubsection}{\alph{subsubsection}}

% make \subsubsection numberd
\addtocounter{secnumdepth}{1}

\begin{document}

\chapter{chapter chapter}
\section{section section section}
\subsection{subsection subsection}
\subsubsection{subsubsection subsubsection}

\lipsum[1]

\end{document}

在此处输入图片描述

解释一下你的例子中哪里出了问题以及我做了哪些改变

  1. \titleformat只接受五个强制参数,而你似乎给了它六个(第六个参数是一对空括号)。此外,在第五个参数中你不能使用。我将 的每个第五个参数(表示在分段命令之前执行的代码)#1更改为空。\titleformat
  2. 默认情况下,\subsubsection是最高分段级别,没有编号。分段编号深度由计数器控制secnumdepth,因此我在该数字上加 1。
  3. 我使用 调整了 的基线tikzpicturebaseline=(x.base)其中x是节点的名称。这使得分段编号与基线上的标题对齐。

相关内容