在標題中加入帶有圓圈的字母

在標題中加入帶有圓圈的字母

在我的課程中,我想使用圓圈中指示的等級來指定每個子部分的等級。

如果我使用該命令\section{title} \trf,帶有圓圈的字母將出現在標題下方。

如果我將它們放在 \section{XX} 命令中\section{title \trf},則該文檔不會編譯

\documentclass{article}
\usepackage{tikz}
 
\newcommand{\atrf}{\tikz[baseline=(letter.base)]\node[draw,circle,inner sep=1pt, shade,shading=ball,circle,ball color=black!10!red] (letter) {ATRF};}
\newcommand{\trf}{\tikz[baseline=(letter.base)]\node[draw,circle,inner sep=1pt, shade,shading=ball,circle,ball color=black!10!blue] (letter) {TRF};}
\newcommand{\asi}{\tikz[baseline=(letter.base)]\node[draw,circle,inner sep=1pt, shade,shading=ball,circle,ball color=black!10!orange] (letter) {ASI};}

\begin{document}
\section{Chapitre 1} \asi \trf
\section{Chapitre 2}
\subsection{Sous section 2.1}
\subsection{Sous section 2.2}

\end{document}

如何使等級出現在標題行中(因此也出現在目錄中)

答案1

在章節標題中使用巨集時需要小心,因為這些標題會出現在文件中的其他幾個位置,例如 PDF 書籤或頁首或頁尾中。

儘管如此,仍然可以使用宏,但您需要在宏的可選參數中提供替代的無宏版本的標題\section(這同樣適用於類似的宏,例如\chapter\subsection):

\documentclass{article}
\usepackage{tikz}
 
\newcommand{\atrf}{\tikz[baseline=(letter.base)]\node[draw,circle,inner sep=1pt, shade,shading=ball,circle,ball color=black!10!red] (letter) {ATRF};}
\newcommand{\trf}{\tikz[baseline=(letter.base)]\node[draw,circle,inner sep=1pt, shade,shading=ball,circle,ball color=black!10!blue] (letter) {TRF};}
\newcommand{\asi}{\tikz[baseline=(letter.base)]\node[draw,circle,inner sep=1pt, shade,shading=ball,circle,ball color=black!10!orange] (letter) {ASI};}

\begin{document}
\section[Chapitre 1 (ASI) (TRF)]{Chapitre 1 \asi \trf}
\section{Chapitre 2}
\subsection{Sous section 2.1}
\subsection{Sous section 2.2}

\end{document}

在此輸入影像描述

答案2

我會避免程式碼重複:您的命令可以根據兩個參數的命令來定義,該命令提供所需的 TikZ 指令在排版目錄時可以做成不同的東西(除非你想讓球也在那裡)。

接下來,將此類命令定義為穩健的命令,以便它們能夠在激烈的爭論中倖存下來。

\documentclass{article}
\usepackage{tikz}
 
\newcommand{\shadedball}[2]{% #1 = color, #2 = acronym
  \ifintoc
    (\textcolor{black!10!#1}{#2})%
  \else
    \begin{tikzpicture}[baseline=(letter.base)]
    \node[
      draw,
      circle,
      inner sep=1pt,
      shade,
      shading=ball,
      circle,
      ball color=black!10!#1,
      minimum width=3em,% <--- to get balls of the same width
    ] (letter) {#2};
    \end{tikzpicture}%
  \fi
}
\newif\ifintoc

\DeclareRobustCommand{\atrf}{\shadedball{red}{ARTF}}
\DeclareRobustCommand{\trf}{\shadedball{blue}{TRF}}
\DeclareRobustCommand{\asi}{\shadedball{orange}{ASI}}

\begin{document}

\intoctrue
\tableofcontents
\intocfalse

\section{Chapitre 1 \asi\ \trf\ \atrf}

\end{document}

在此輸入影像描述

無條件經營

\documentclass{article}
\usepackage{tikz}
 
\newcommand{\shadedball}[2]{% #1 = color, #2 = acronym
  \begin{tikzpicture}[baseline=(letter.base)]
    \node[
      draw,
      circle,
      inner sep=1pt,
      shade,
      shading=ball,
      circle,
      ball color=black!10!#1,
      minimum width=3em,% <--- to get balls of the same width
    ] (letter) {#2};
  \end{tikzpicture}%
}

\DeclareRobustCommand{\atrf}{\shadedball{red}{ARTF}}
\DeclareRobustCommand{\trf}{\shadedball{blue}{TRF}}
\DeclareRobustCommand{\asi}{\shadedball{orange}{ASI}}

\begin{document}

\tableofcontents

\section{Chapitre 1 \asi\ \trf\ \atrf}

\end{document}

在此輸入影像描述

相關內容