下面有一个例子。我试图强制文本位于节点的中心。
\documentclass[tikz]{standalone}
\usepackage{mwe} % For dummy images
\usepackage{mathtools}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}[node distance=5mm and 5mm,
input_circle/.style={
draw,
ellipse,
minimum size=2cm,
minimum height=1cm,
text width=1cm,
fill=white!30!yellow,
font=\tiny,
align=center
}]
\node (r_t_k) [input_circle] {$r_{t-K+1}$ \\ $\log[r_{t-K+1}^2]$};
\node (r_t_k_1) [input_circle,right=of r_t_k] {$r_{t-K+2}$ \\ $\log[r_{t-K+2}^2]$};
\node (dots) [minimum size=2cm,right=of r_t_k_1] {\huge $\cdots$};
\node (r_t_1) [input_circle,right=of dots] {$r_{t-1}$ \\ $\log[r_{t-1}^2]$};
\node (r_t) [input_circle,right=of r_t_1] {$r_t$ \\ $\log[r_t^2]$};
\end{tikzpicture}
\end{document}
答案1
不要覆盖自然text width
\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}[
node distance=5mm and 5mm,
input_circle/.style={
draw,
ellipse,
minimum size=2cm,
minimum height=1cm,
fill=white!30!yellow,
font=\tiny,
align=center
}]
\node[input_circle] (r_t_k) {$r_{t-K+1}$ \\ $\log[r_{t-K+1}^2]$};
\node[input_circle, right=of r_t_k] (r_t_k_1) {$r_{t-K+2}$ \\ $\log[r_{t-K+2}^2]$};
\node[minimum size=2cm, right=of r_t_k_1] (dots) {\huge $\cdots$};
\node[input_circle, right=of dots] (r_t_1) {$r_{t-1}$ \\ $\log[r_{t-1}^2]$};
\node[input_circle, right=of r_t_1] (r_t) {$r_t$ \\ $\log[r_t^2]$};
\end{tikzpicture}
\end{document}
答案2
- 您的 elpse 样式定义不一致:
minimum size2=cm
被覆盖minimum height=1cm
,text width=1cm
对于节点中的文本来说太小了- 更明智的做法是定义
text width=15mm
,,,minimum height=9mm
align=center
- 无关:
- 对于节点的定位我将使用
chains
库 - 为了使数学看起来更美观,我会增加字体大小
- 对于节点的定位我将使用
\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\usepackage{mathtools}
\usetikzlibrary{positioning}
\usetikzlibrary{calc, chains,
positioning,
shapes.geometric}
\begin{document}
\begin{tikzpicture}[
node distance = 5mm and 5mm,
start chain = going right,
IC/.style = {ellipse, draw, fill=yellow!30, % input_circle
text width=15mm, minimum height=9mm, align=center, % < ---
inner xsep=0pt, font=\scriptsize}
]
\begin{scope}[nodes={on chain}]
\node (r_t_k) [IC] {$r_{t-K+1}$ $\log\Bigl[r_{t-K+1}^2\Bigr]$};
\node (r_t_k_1) [IC] {$r_{t-K+2}$ $\log\Bigl[r_{t-K+2}^2\Bigr]$};
\node (dots) [font=\huge] {$\cdots$};
\node (r_t_1) [IC] {$r_{t-1}$ $\log\Bigl[r_{t-1}^2\Bigr]$};
\node (r_t) [IC] {$r_t$\\ $\log\Bigl[r_t^2\Bigr]$};
\end{scope}
\end{tikzpicture}
\end{document}