在 Tikzpicture 中增加文本大小而不增加块大小

在 Tikzpicture 中增加文本大小而不增加块大小

我注意到,每个块中的文本越多,块本身的大小就越大,这可以从block与其他块相关的 n-1 标签中看到。

我想要的是

  1. 我想要相同大小的块,无论文本长度如何。

  2. 我希望每个块中刻写的文字占据每个block尺寸的 80%,而块尺寸不会增加。

  3. 我想要更大的,2, 3, 4, ..., n-1同时我希望块大小与前三个块相同。

\documentclass{article}
\usepackage{tikz}

\begin{document}
   \begin{tikzpicture}[
       block/.style={
           rectangle,
           rounded corners,
           inner sep=1em
       }
       ]
    
       \path node[block,black,fill=yellow] (1st) {2\strut};
       \path (1st.east) ++(2pt,0) node[block,anchor=west,black,fill=green] 
       (2nd) {3\strut};
       \path (2nd.east) ++(2pt,0) node[block,anchor=west,black,fill=red] 
       (3rd) {4\strut};
       \path (3rd.east) ++(2pt,0) node[block,anchor=west,black,fill=white] 
       (4th) {...\strut};
       \path (4th.east) ++(2pt,0) node[block,anchor=west,black,fill=yellow] 
       (5th) {n-1\strut};
    
   \end{tikzpicture}

\结束{文档}

彩色块

答案1

正如我上面的评论所述:

没有font=\huge

增加无

font=\huge

增加文本大小

\documentclass{article}
%https://tex.stackexchange.com/q/631402/204164
\usepackage{tikz}

\begin{document}
   \begin{tikzpicture}[
       block/.style={
           rectangle,
           rounded corners,
           inner sep=0pt,
           minimum width=1cm,
           minimum height=1cm ,
           font=\huge         
       }
       ]
    
       \path node[block,black,fill=yellow] (1st) {2\strut};
       \path (1st.east) ++(2pt,0) node[block,anchor=west,black,fill=green] 
       (2nd) {3\strut};
       \path (2nd.east) ++(2pt,0) node[block,anchor=west,black,fill=red] 
       (3rd) {4\strut};
       \path (3rd.east) ++(2pt,0) node[block,anchor=west,black,fill=white] 
       (4th) {...\strut};
       \path (4th.east) ++(2pt,0) node[block,anchor=west,black,fill=yellow] 
       (5th) {n-1\strut};
    
   \end{tikzpicture}
\end{document}

相关内容