
我正在使用以下基於 tikz 的命令圍繞字母創建一個圓圈。
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
\node[shape=circle,draw,minimum size=4mm, inner sep=0pt] (char)
{#1};}}
它工作正常,但每當我在同一行中使用多個字母時,它們就不會對齊。
我想這與基線有關,就像圓是參考質心創造的一樣。注意,b 和 d 比 a 和 c 稍高。我該如何解決這個問題?
更新
根據我從評論中得到的建議(謝謝大家),我將圓圈彼此對齊(這就是我想要的),但不幸的是沒有與文字對齊:
我看到另一篇文章提出了這個propnode
(粉紅色的a),我嘗試使用第一個參數將其移動到各處,但沒有效果。
\pgfmathsetmacro{\nodebasesize}{1} % A node with a value of one will have this diameter
\pgfmathsetmacro{\nodeinnersep}{0.05}
\newcommand{\propnode}[5]{% position, name, options, value, label
\begin{tikzpicture}
\pgfmathsetmacro{\minimalwidth}{sqrt(#4*\nodebasesize)}
\node[#3,minimum width=\minimalwidth*1cm,inner sep=\nodeinnersep*1cm,circle,draw] (#2) at (#1) {#5};
\end{tikzpicture}
}
事實上,propnode
有點太高了,圈起來有點太低了。這是調用所有內容的程式碼:
(\circled{b},\circled{a},\circled{c},\circled{d},\propnode{0,4}{n05}{fill=pink,text=black}{0.15}{a}).
答案1
這是一個使用支柱的範例:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
\node[shape=circle,draw,minimum size=4mm, inner sep=0pt] (char)
{\rule[-3pt]{0pt}{\dimexpr2ex+2pt}#1};}}
\begin{document}
\foreach \myn [count=\myc] in {a,b,c,d,e,p,q}
{%%
\circled{\myn}\ifnum\myc<7\relax,\fi
}%%
\end{document}
答案2
這是使用平均演算法:
\documentclass[]{article}\usepackage{amsmath,mathtools,amssymb,tikz}
\newlength\myheight
\newcommand*\ccircled[1]{\settowidth{\myheight}{#1}%
\raisebox{-.1\myheight}{\tikz[baseline=(char.base)]{%
\node[shape=circle,draw,minimum size=\myheight*\myheight*.4,inner sep=1pt](char){#1};}}}
\begin{document}
\ccircled{S}u\ccircled{z}u\ccircled{k}i
\end{document}
根據需要進行多少次平方計算,可以使其變得更平滑。