在中心向下画一条线,并在tikz的任一侧绘制文字

问题描述 投票:0回答:1

我想创建一个圆形节点,该节点的线完全在中心下方,并且在该线的两边都带有文本。到目前为止,下面的代码绘制的条形图与文本的高度相同,但并未延伸到整个圆心。我该怎么做?

\begin{tikzpicture}
\node (y) [shape=circle,draw] at (0,0) {$\Sigma | f$};
\end{tikzpicture}
latex tikz
1个回答
0
投票

有很多方法可以做到这一点。

在tikz中有多部分节点和圆形分割形状的概念,该形状允许在圆形中具有双部分。问题在于,仅允许水平分割,而垂直分割则需要1 /旋转形状以具有垂直分割,并需要2 /沿相反方向旋转内部文本。

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes.multipart}

\begin{document}
\begin{tikzpicture}
\node [circle split,draw,rotate=90] (y) {\rotatebox{-90}{$\sigma$}
     \nodepart{lower} \rotatebox{-90}{$f$}};
\end{tikzpicture}
\end{document}

enter image description here

但是使用常规tikz命令执行此操作非常容易,并且可以更好地控制节点外观和文本对齐。

我建议,首先放置您的文本节点。然后使用拟合库确定最佳圆的大小。最后绘制垂直线。

这里是相应的代码。

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{fit}

\begin{document}
\begin{tikzpicture}
\node[anchor=east,baseline] (sigma) at (0,0) {$\sigma$} ;
\node[anchor=west,baseline] (f) at (0,0) {$f$} ;
\node[circle,draw,fit={(sigma)(f)}] (y) {} ;
\draw (y.south) -- (y.north) ;
\end{tikzpicture}
\end{document}

enter image description here

您可以使用节点y上的inner sep参数修改文本和圆之间的间距。

如果需要几个直径相同的圆,请用fit=(或其他)替换minimum width=1cm

最后,如果您需要更近的节点,请将inner sep=0.5pt(或任何其他值)添加到前两个节点。

这里是具有不同参数的结果。

\begin{tikzpicture}
\node[anchor=east,baseline,inner sep=0.5pt] (sigma) at (0,0) {$\sigma$} ;
\node[anchor=west,baseline,inner sep=0.5pt] (f) at (0,0) {$f$} ;
\node[circle,draw,fit={(sigma)(f)},inner sep=1pt] (y) {} ;
\draw (y.south) -- (y.north) ;
\end{tikzpicture}

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.