您好,我想在图片中添加一些文字。已经尝试了几种方法,但没有找到简单的解决方案。有人能帮我吗?
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows, calc}
%%% styles for Figure: Main areas of leadership affected by Digital Transformation %%%
\tikzstyle{digital} = [rectangle, rounded corners, align=left, draw=black, fill=gray!20, text width=3cm]
\tikzstyle{line} = [thick,-,>=stealth]
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[node distance=2.2cm]
%%% NODES %%%
\node (competitive)[digital] {Competitive Landscape};
\node (customer) [digital, left of=competitive, xshift=-2cm] {Customer relationship};
\node (work) [digital, right of=competitive, xshift=2cm] {People/Work environment};
%%% LINES %%%
\draw [line] (competitive) -- (customer);
\draw [line] (competitive) -- (work);
%%% RECTANGLES %%%
\draw[thick,dotted] ($(customer.north west)+(-0.25,0.25)$) rectangle ($(work.south east)+(0.25,-0.6)$);
\end{tikzpicture}
\caption{Three pillars} \label{fig:leadership_digital}
\end{figure}
\end{document}
答案1
您可以使用 fit-library 创建一个围绕其他框的节点,然后在南边位置创建另一个包含文本的节点。如果您愿意,此节点可以具有白色背景。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows, calc, fit}
%%% styles for Figure: Main areas of leadership affected by Digital Transformation %%%
\tikzstyle{digital} = [rectangle, rounded corners, align=left, draw=black, fill=gray!20, text width=3cm]
\tikzstyle{line} = [thick,-,>=stealth]
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[node distance=2.2cm]
%%% NODES %%%
\node (competitive)[digital] {Competitive Landscape};
\node (customer) [digital, left of=competitive, xshift=-2cm] {Customer relationship};
\node (work) [digital, right of=competitive, xshift=2cm] {People/Work environment};
%%% LINES %%%
\draw [line] (competitive) -- (customer);
\draw [line] (competitive) -- (work);
%%% RECTANGLES %%%
\node[draw, thick, dotted, rounded corners, inner xsep=1em, inner ysep=1em, fit=(work) (customer)] (box) {};
\node[fill=white] at (box.south) {Text Here};
\end{tikzpicture}
\caption{Three pillars} \label{fig:leadership_digital}
\end{figure}
\end{document}
如果您需要在文本之前和/或之后添加更多空白,一种简单(但可能不是那么好)的方法就是在\quad
文本之前和之后添加。
答案2
使用tikz
库chains
,fit
很positioning
简单:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, chains, fit, positioning}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[
node distance = 10mm and 5mm,
start chain = going right,
digital/.style = {rounded corners, draw, fill=gray!20,
text width=3cm, align=flush center, %left,
on chain, join=by line},
line/.style = {thick,-Stealth}
]
%%% NODES %%%
\node (n1) [digital] {Customer relationship};
\node (n2) [digital] {Competitive Landscape};
\node (n3) [digital] {People/Work environment};
%%% dotted RECTANGLE %%%
\node[draw, thick, dotted, inner sep=3ex, yshift=-1ex,
fit=(n1) (n3)] (box) {};
\node[fill=white, inner xsep=1ex] at (box.south) {Text Here};
\end{tikzpicture}
\caption{Three pillars}
\label{fig:leadership_digital}
\end{figure}
\end{document}
注意:您的代码假设“数字”节点由箭头连接,但在图像上是简单的线条。如果您只喜欢线条,则将line
样式更改为line/.style = {thick,-}