我怎样才能将文字放入方格中?
请查看我的代码:
\definecolor{MainRed}{rgb}{.6, .1, .1}
\def\bigrectangle{(-7,-1) rectangle (6.5,4.7)}
\def\firstrectangle{(-9,0) rectangle (-5,4)}
\def\secondrectangle{(-4,0) rectangle (0,4)}
\def\thirdrectangle{(1,0) rectangle (5,4)}
\def\fourthrectangle{(6,0) rectangle (10,4)}
\def\firsttriangle{(4.5,4.1)--(7,4)--(4.5,8)--cycle}
\def\secondtriangle{(4.5,0)--(7.1,0)--(4.5,-4)--cycle}
\begin{tikzpicture}[scale = 0.5]
\draw[fill= MainRed,color =MainRed!10]\bigrectangle;
\draw[fill= MainRed,color =MainRed!10]\firsttriangle;
\draw[fill= MainRed,color =MainRed!10]\secondtriangle;
\draw[fill= MainRed,color =MainRed,rounded corners]\firstrectangle;
\draw[fill= MainRed,color =MainRed,rounded corners]\secondrectangle;
\draw[fill= MainRed,color =MainRed,rounded corners]\thirdrectangle;
\draw[fill= MainRed,color =MainRed,rounded corners]\fourthrectangle;
\end{tikzpicture}
答案1
不要绘制矩形,而是定义如下节点:
\tikzset{mynode/.style={fill= MainRed,rounded corners,minimum
size=2cm,text width=2cm,text=white,align=center}
}
并使用它。
\documentclass[tikz,border=5]{standalone}
\begin{document}
\definecolor{MainRed}{rgb}{.6, .1, .1}
\def\bigrectangle{(-7,-1) rectangle (6.5,4.7)}
\def\firsttriangle{(4.5,4.1)--(7,4)--(4.5,8)--cycle}
\def\secondtriangle{(4.5,0)--(7.1,0)--(4.5,-4)--cycle}
\tikzset{mynode/.style={fill= MainRed,rounded corners,minimum size=2cm,text width=2cm,text=white,align=center}
}
\begin{tikzpicture}[scale = 0.5]
\draw[fill= MainRed,color =MainRed!10]\bigrectangle;
\draw[fill= MainRed,color =MainRed!10]\firsttriangle;
\draw[fill= MainRed,color =MainRed!10]\secondtriangle;
\node[mynode] at (-7,2) {my text comes here};
\node[mynode] at (-2,2) {my text comes here};
\node[mynode] at (3,2) {my text comes here};
\node[mynode] at (8,2) {my text comes here};
\end{tikzpicture}
\end{document}
您可以使用箭头代替绘制这些三角形:
\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{arrows.meta}
\begin{document}
\definecolor{MainRed}{rgb}{.6, .1, .1}
\tikzset{mynode/.style={fill= MainRed,rounded corners,minimum size=2cm,text width=2cm,text=white,align=center}
}
\begin{tikzpicture}[scale = 0.5]
\draw [line width=3cm,MainRed!10,arrows = {-Stealth[inset=0pt, angle=90:4cm, length=2cm]}] (-7,2) -- (8,2);
\node[mynode] at (-7,2) {my text comes here};
\node[mynode] at (-2,2) {my text comes here};
\node[mynode] at (3,2) {my text comes here};
\node[mynode] at (8,2) {my text comes here};
\end{tikzpicture}
\end{document}