编辑

编辑

我四处寻找,但令人惊讶的是,我还没有找到这个问题的明确答案。我用 tikz 绘制了一些框。我希望框D的文本(在本例中)bigbox位于右下角,而不必逐个提供任何坐标。相反,文本出现在框的中心。我似乎无法控制这一点,除非在文本前留出大量空白。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows, decorations.markings,shapes,arrows,fit}
\tikzstyle{box}=[draw, minimum size=2em, text width=4.5em, text centered]
\tikzstyle{bigbox}=[draw, inner sep=20pt]

\begin{document}
\begin{tikzpicture}
    \node[box] (A) at ( -2,1) {$A$};
    \node[box] (B) at ( 1,1) {$B$};
    \node[box] (C) at ( 4,1) {$C$};
    \node[bigbox, fit=(A)(B)(C)] (D) {D};
\end{tikzpicture}
\end{document}

答案1

您可以添加标签,然后将其移至内部,例如

label={[shift={(-3ex,3ex)}]south east:#1}

在定义中bigbox

bigbox/.style={draw, inner sep=20pt,label={[shift={(-3ex,3ex)}]south east:#1}}

然后bigbox=D

\node[bigbox=D, fit=(A)(B)(C)] (D) {};

完整代码:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows, decorations.markings,shapes,arrows,fit}
\tikzset{box/.style={draw, minimum size=2em, text width=4.5em, text centered},
         bigbox/.style={draw, inner sep=20pt,label={[shift={(-3ex,3ex)}]south east:#1}}
}

\begin{document}
\begin{tikzpicture}
    \node[box] (A) at ( -2,1) {$A$};
    \node[box] (B) at ( 1,1) {$B$};
    \node[box] (C) at ( 4,1) {$C$};
    \node[bigbox=D, fit=(A)(B)(C),] (D) {};
\end{tikzpicture}
\end{document}

在此处输入图片描述

编辑

回复评论:

这里为edlabel节点绘制了a ,label={[shift={(-3ex,3ex)}]south east:#1}是标签的内容。有关更多信息,请参阅。至于复杂的内容,我希望下面的内容足够复杂:-)shift#1pgfmanual

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows, decorations.markings,shapes,arrows,fit}
\tikzset{box/.style={draw, minimum size=2em, text width=4.5em, text centered},
         bigbox/.style={draw, inner sep=20pt,label={[align=right,shift={(-1.5ex,3ex)}]south east:\llap{#1}}}
}

\begin{document}
\begin{tikzpicture}
    \node[box] (A) at ( -2,1) {$A$};
    \node[box] (B) at ( 1,1) {$B$};
    \node[box] (C) at ( 4,1) {$C$};
    \node[bigbox={$x^n + y^n = z^n$},label=south east:D, fit=(A)(B)(C)] (D) {};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

您可以添加一个额外的节点来设置D文本:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows, decorations.markings,shapes,arrows,fit}
\tikzstyle{box}=[draw, minimum size=2em, text width=4.5em, text centered]
\tikzstyle{bigbox}=[draw, inner sep=20pt]

\begin{document}
\begin{tikzpicture}
    \node[box] (A) at ( -2,1) {$A$};
    \node[box] (B) at ( 1,1) {$B$};
    \node[box] (C) at ( 4,1) {$C$};
    \node[bigbox, fit=(A)(B)(C)] (D) {};
    \node[above left] at (D.south east) {D};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容