在目錄中使用 Tikz 製作的圖標

在目錄中使用 Tikz 製作的圖標

在此輸入影像描述

這張圖片提供了我想在我的書的目錄中做的事情的粗略近似值。我希望只有一章中的章節使用唯一的圖標,而不是章節編號。

目前,我正在使用我收到的建議這個問題。然而,.png 影像很難處理並且總是變得模糊。我想嘗試使用 TikZ 來製作這些圖像,以便它們在任何尺寸下都保持清晰。

由於時間關係,我僅提供第一部分的範例。但是,我希望為一章中的每個部分使用一個唯一的圖示。這些圖示非常基本:只是一個圓圈,裡面有一個字母。我想用蒂克茲這樣可以避免將這些圖示製作為圖像。

我不知道該怎麼做。任何幫助表示讚賞。謝謝。

答案1

一般來說,使用該套件tikzscale會改變\includegraphics命令以便能夠讀取和排版tikz-graphics。因此你可以做類似的事情

  • 使用 tikz 建立圖像
  • 將每個圖像保存在單獨的檔案中
  • 使用連結答案的程式碼並載入tikzscale
  • \includegraphics[height=10pt]{mytikzimage}在適當的地方使用。

這種方法有一個額外的好處,可以tikzscale自動將tikz圖像縮放到絕對大小,我認為這對於這個想法至關重要?不過,您可能想查看tikzexternalize庫,因為tikzscale每個圖像都會排版幾次才能實現這種縮放。否則,在目錄中使用多個圖示可能會顯著減慢文件的編譯速度。

看下面我借來的程式碼這裡,您已經連結了:

\documentclass{book}
\usepackage{titletoc}
\usepackage{graphicx}
\usepackage{tikz}      % to draw the symbols
\usepackage{tikzscale} % to include tikz graphics as image files and scale them

\makeatletter
\newcommand\stdsectioninToC{
\titlecontents{section}
  [3.8em]
  {}
  {\contentslabel{2.3em}}
  {\hspace*{-2.3em}}
  {\titlerule*[1em]{.}\contentspage}
}
\newcommand\iconsectioninToC{
\titlecontents{section}
  [3.8em]
  {}
  {\contentslabel{2.3em}%
    \smash{\includegraphics[height=10pt]{image}}\hspace{0.5em}% change here 
  }
  {\hspace*{-2.3em}}
  {\titlerule*[1em]{.}\contentspage}
}
\AtBeginDocument{\stdsectioninToC}
\makeatother

\begin{document}

\tableofcontents

\chapter{A test chapter}
\section{First test section}
\section{Second test section}
\section{Third test section}
\section{Fourth test section}

\iconsectioninToC
\chapter{A test chapter}
\section{First test section}
\section{Second test section}
\section{Third test section}
\section{Fourth test section}

\stdsectioninToC
\chapter{A test chapter}
\section{First test section}
\section{Second test section}
\section{Third test section}
\section{Fourth test section}

\end{document}

image.tikz在這裡,我使用了包含以下內容的附加文件:

% image.tikz
\begin{tikzpicture}
    \draw [fill=red!30] (-1,0) -- (0,1) -- (1,0) -- (0,-1) -- cycle;
\end{tikzpicture}

正如下面的螢幕截圖所示,這就像一個魅力:

在此輸入影像描述

為了完整性:如果您想要各個部分的單獨圖片,您必須更改裡面的程式碼\iconsectioninToC(這不是我的大腦工作,從連結的答案複製)。將註釋部分修改為:

\stepcounter{mysecimage}
\smash{\includegraphics[height=10pt]{image-\the\value{mysecimage}}}\hspace{0.5em}

並命名您的圖像image-1.tikzimage-2.tikz等等。

相關內容