使 tikz 解決方案具有較小的圓圈數字工作

使 tikz 解決方案具有較小的圓圈數字工作

我想在文本中包含帶圓圈的數字並使用 TikZ 解決方案已發布這裡。但是,我想讓圓圈和文字小一點,所以我嘗試了以下方法:

\documentclass{article}
\usepackage{tikz}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
            \node[shape=circle,draw,inner sep=2pt] (char) {#1};}}
\begin{document}
Numbers aligned with the text:  \scriptsize{\circled{1}} end.
\end{document}

不幸的是,\scriptsize似乎“洩漏”,因為該命令之後的所有文字都很小(在文字中,“結束”也在腳本大小中),儘管花括號正確關閉。

我怎樣才能在沒有\scriptsize命令“leak”的情況下完成這項工作?

答案1

解決方案是正確更改字體大小。\scriptsize不接受參數並隨後更改所有文字的字體大小。如果它用大括號括起來(例如,在 的參數內\circled{·}),則字體大小變更只是局部的。

更改後的程式碼:

\documentclass{article}
\usepackage{tikz}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
            \node[shape=circle,draw,inner sep=2pt] (char) {#1};}}
\begin{document}
Numbers aligned with the text:  \circled{\scriptsize1}  \circled{1} end.
\end{document}

輸出如下圖所示:

在此輸入影像描述

如果您想要變更圓圈大小,可以變更inner sepAndréC 評論中提到的選項值。

答案2

我們可以在 TikZ 中插入 LaTeX 的許多內容(文字、公式、表格、圖像等),node並且有很多選項。最好的選擇之一是scale比 LaTeX 靈活得多:\tiny, \scriptsize, \footnotesize, \small, , \normalsize, \large, \Large, \LARGE, \huge\Huge也許 Stefan Kottwitz 在他的回答)。

綜上所述,我們scale針對node這種情況。

在此輸入影像描述

\documentclass{article}
\usepackage{tikz}
\newcommand*\circled[2]{\tikz[baseline=(char.base)]{
\node[circle,draw,scale=#2,inner sep=2pt] (char) {#1};}}
\begin{document}
Numbers aligned with the text:  \circled{1}{1}  \circled{\color{blue} 1}{1.5} end.
\end{document}

相關內容