想要向下一个矩形添加文本。还想在下一个矩形的右侧绘制另一个矩形,共享边界。
\documentclass[10pt,journal,compsoc]{IEEEtran}
\usepackage{pgfplots}
\usepackage{subfig}
\usepackage{tcolorbox}
\usetikzlibrary{positioning,shapes,arrows,shadows,patterns,calc}
\hyphenation{op-tical net-works semi-conduc-tor}
\begin{document}
\begin{figure}
%\centering
% \captionsetup{justification = centering}
\begin{tikzpicture}[x=0.5mm,y=0.5mm]
\coordinate (a1);
\coordinate[right=150 of a1](a2);
\coordinate[below=90 of a1](a3);
\coordinate[right=150 of a3](a4);
\draw[ultra thick,rounded corners=10,green] ($(a4)-(80,20)$)
rectangle +(80*2,20*2);%Rectangle rounded
\end{tikzpicture}
\end{figure}
答案1
改编:
- 删除未使用的包、未使用的 tikzlibraries 并添加所需的包(
tikz
)。 - (旧:在添加文本居中
node{\Large text}
后立即添加rectangle
或仅使用节点,如下所示...) - 用于
node
绘制带有文本的矩形节点,因此您不需要计算任何坐标。 - 您可以设置
minimum width=160, minimum height=40
为所需的大小。 - 要让节点 B 共享 A 的右边界,您可以设置选项
right=0 of a
。
代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{figure}
\begin{tikzpicture}[
myrectangle/.style={rectangle, draw, minimum width=160, minimum height=40, ultra thick, rounded corners=10, green}
]
\node[myrectangle] (a) at (0,0) {\Large text};
\node[myrectangle, right=0 of a] (b) {\Large B};
\end{tikzpicture}
\end{figure}
\end{document}
结果:
答案2
\documentclass[tikz,border=4mm]{standalone}
\usetikzlibrary{fit}
\begin{document}
\begin{tikzpicture}[every fit/.style={inner sep=0pt, outer sep=0pt, draw}]
\begin{scope}[yshift=2cm,y=0.8cm]
\node [fit={(0,0) (4,1)}, label=center:{first rectangle}] {};
\node [fit={(4,0) (8,1)}, label=center:{second rectangle}] {};
\end{scope}
\end{tikzpicture}
\end{document}
答案3
微小的变化右手回答:
\documentclass[10pt,journal,compsoc]{IEEEtran}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{lipsum}
\begin{document}
\lipsum[11]
\begin{figure}[htb]
\begin{tikzpicture}[
node distance=0pt,
every node/.style={draw=green, ultra thick, rounded corners=10,
minimum width=0.5\linewidth, minimum height=40, outer sep=0pt,
font=\large\bfseries, text=red}
]
\node (n1) {A};
\node [right=of n1] {B};
\end{tikzpicture}
\end{figure}
\end{document}
两个节点的宽度等于一个文本列的宽度: