我有一组使用 tikz 或 pifont 包制作的带有一些装饰(圆形或圆角)的数字。问题是它们看起来很丑,因为它们看起来不像对齐的。有没有办法将它们垂直对齐(或移动)以看起来更好?
\documentclass{article}
\usepackage{tikz}
\usepackage{pifont}
\newcommand{\round}[1]{%
\tikz[baseline=(char.base)]\node[anchor=south west, draw,rectangle, rounded corners, inner sep=1pt, minimum size=3mm,
text height=2mm](char){\ensuremath{#1}} ;}
\let\oldding\ding% Store old \ding in \oldding
\renewcommand{\ding}[2][1]{\scalebox{#1}{\oldding{#2}}}
\newcommand{\circled}[1]{\ding[1.2]{\numexpr171 + #1}}
\begin{document}
1\round{2,4}\circled{3}5\circled{6}\circled{7}\circled{8}
\end{document}
答案1
我会为两者(单个数字与多个数字)使用相同的设置,以便字体和轮廓相同。TikZrounded rectangle
在shapes.misc
库中提供了形状。
,
通过设置特定的 ,可以忽略 增加的巨大深度text depth
。这与数字的正常高度相结合看起来不错。如果要将其用于其他东西,最好添加text height=\heightof{0}
或font=\vphantom{0}
。
代码
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.misc}
\tikzset{
every round node/.style={
draw,
shape=rounded rectangle,
rounded rectangle arc length=180,
inner sep=+.333em,
text depth=+.1ex},
light/.style={fill=none, text=black},
dark/.style={fill=black, text=white}}
\newcommand{\round}[2][]{%
\tikz[baseline]
\node[
every round node,
anchor=base,
#1]{$#2$};}
\begin{document}
1\round{2,4}\round{3}5\round{6}\round[fill=blue, text=green]{7}\round{8}
{\tikzset{every round node/.append style={dark}}
1\round{2,4}\round{3}5\round{6}\round{7}\round[text=red]{8}}
1\round{2,4}\round{3}5\round{6}\round{7}\round{8}
\end{document}
输出
答案2
你根据装饰形状使用不同的字体,这总是看起来很奇怪。由于你使用 tikz 进行复合,因此你也需要将其用于简单的圆形装饰:
\documentclass{article}
\usepackage{tikz}
\usepackage{pifont}
\newcommand{\round}[1]{%
\tikz[baseline=(char.base)]\node[anchor=south west, draw,rectangle, rounded corners, inner sep=2pt](char){\ensuremath{#1}} ;}
\newcommand{\circled}[1]{%
\tikz[baseline=(char.base)]\node[anchor=south west, draw,circle, inner sep=1pt,](char){\ensuremath{#1}} ;}
\begin{document}
1\round{2,4}\circled{3}5\circled{6}\circled{7}\circled{8}
\end{document}
答案3
您可以\raisebox
在的定义中使用\circled
来获得:
\documentclass{article}
\usepackage{tikz}
\usepackage{pifont}
\newcommand{\round}[1]{%
\tikz[baseline=(char.base)]\node[anchor=south west, draw,rectangle, rounded corners, inner sep=1pt, minimum size=3mm,
text height=2mm](char){\ensuremath{#1}} ;}
\let\oldding\ding% Store old \ding in \oldding
\renewcommand{\ding}[2][1]{\scalebox{#1}{\oldding{#2}}}
%\newcommand{\circled}[1]{\ding[1.2]{\numexpr171 + #1}}
\newcommand{\circled}[1]{\raisebox{-1.5pt}{\ding[1.2]{\numexpr171 + #1}}}
\begin{document}
1\round{2,4}\circled{3}5\circled{6}\circled{7}\circled{8}
\end{document}
这样,数字的基线就可以垂直对齐了。
但是,为了避免改变字体,您可以这样做:
\documentclass{article}
\usepackage{tikz}
\usepackage{pifont}
\newcommand{\round}[1]{%
\tikz[baseline=(char.base)]\node[anchor=south west, draw,rectangle,
rounded corners, inner sep=1pt, minimum size=3mm,
text height=2.5mm](char){\ensuremath{\,#1\,}} ;}
\let\oldding\ding% Store old \ding in \oldding
\renewcommand{\ding}[2][1]{\scalebox{#1}{\oldding{#2}}}
%\newcommand{\circled}[1]{\ding[1.2]{\numexpr171 + #1}}
\newcommand{\circled}[1]{\round{\!#1\!}}
\begin{document}
1\round{2,4}\circled{3}5\circled{6}\circled{7}\circled{8}
\end{document}