我想让第二个节点(包含复选标记的圆圈)的大小自动适应矩形(第一个节点)的高度。我希望它具有矩形的高度,我该如何提取它?谢谢
梅威瑟:
\documentclass{article}
\usepackage{tikz}
\usepackage{fontawesome5}
\newcommand{\teacher}[1]{
\tikz[baseline]{
\draw (0,0) node[left=0.35cm,align=center,fill=violet!20,draw=violet,rounded corners,line width=1pt,inner sep=5pt] {#1} node[circle,fill=violet!20,draw=violet,line width=1pt,inner sep=1pt] {\Large \color{red}\faCheck};
}
}
\begin{document}
\teacher{Hello\\World}
\end{document}
答案1
可能有更好的方法来实现这一点,但您可以通过获取节点锚点的坐标\pgfgetlastxy
,然后使用这些坐标来计算大小:
\documentclass{article}
\usepackage{tikz}
\usepackage{fontawesome5}
\newcommand{\teacher}[1]{%
\tikz[baseline]{
\node[
align=center,
fill=violet!20,
draw=violet,
rounded corners,
line width=1pt,
inner sep=5pt
] (n) {#1};
\path (n.north);
\pgfgetlastxy{\nNorthX}{\nNorthY};
\path (n.south);
\pgfgetlastxy{\nSouthX}{\nSouthY};
\node[
circle,
fill=violet!20,
draw=violet,
line width=1pt,
inner sep=1pt,
minimum height={\nNorthY-\nSouthY-\pgflinewidth},
anchor=west,
xshift={-\pgflinewidth}
] at (n.east) {\Large \color{red}\faCheck};
}%
}
\begin{document}
\teacher{Hello\\World}
\end{document}