在底部添加额外的空间,其中包含图像的矩形,TikZ

在底部添加额外的空间,其中包含图像的矩形,TikZ

为了在图像周围绘制边框,我使用了 TikZ 中的矩形。在矩形内,我想标记图表。但是图像占据了矩形的整个空间,因此没有剩余空间来写标签。如果我增加内部分离,它会在所有 4 个方向上增加空间,而我不希望发生这种情况。我只想在底部添加额外的空间。如果我为矩形设置最小高度,则图像将居中,因此顶部会有额外的空间。我也不希望这种情况发生。我找不到将图像与矩形底部对齐的选项。任何帮助都将不胜感激。

PS:目前,我正在添加一个空矩形,然后单独添加图像。因此,矩形的内部分隔将为零。我有三个类似的图表,我必须将其他两个矩形的内部分隔也设置为零。结果,对于第一个图表,图表内的块与边框矩形重叠。

% Contains figures for the presentation
%! Author = Nagabhushan

% Preamble
\documentclass[11pt]{article}

% Packages
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{makecell}
\usepackage{media9}
\usepackage{pgfplots}
%\pgfplotsset{compat=1.17}
\usepackage{tikz}
\usetikzlibrary{shapes, arrows, positioning, calc, decorations.pathreplacing, external}
\tikzexternalize[prefix=figures/]
\newcommand{\etal}{\textit{et al.}}

% --------------------------- TikZ blocks - Start --------------------------------%
\tikzstyle{container} = [rectangle, rounded corners, draw=black, dashed]
\tikzstyle{circle-label} = [circle, text centered, draw=black]
% --------------------------- TikZ blocks - End --------------------------------%

% Document
\begin{document}
    \tikzsetnextfilename{Model_BlockDiagrams}
    \begin{tikzpicture}[node distance=2cm]
        \node (main) [container, inner sep=0] at (current page.north) {\includegraphics[width=\linewidth]{../../images/MainArchitecture_BlockDiagram.pdf}};
        \node (mcs) [container, below of=main, yshift=-4.5cm, inner sep=0] {\includegraphics[width=\linewidth]{../../images/MCS_BlockDiagram.pdf}};
        \node (rfd) [container, below of=mcs, minimum height=4.5cm, minimum width=\linewidth, yshift=-4cm] {};
        \node (rf-image) [below of=rfd, yshift=2.5cm]{\includegraphics[width=\linewidth]{../../images/RFD_BlockDiagram.pdf}};
        \node [circle-label, align=center, below of=main, right of=main, xshift=3.5cm] {A};
        \node [circle-label, align=center, below of=mcs, right of=mcs, xshift=3.5cm, yshift=-0.3cm] {B};
        \node [circle-label, align=center, below of=rfd, right of=rfd, xshift=3.5cm, yshift=0.3cm] {C};
    \end{tikzpicture}
    \newpage
\end{document}

输出:

输出

答案1

像这样?

在此处输入图片描述

我对您的 MWE 做了一些更改:

  • 而是\tikzstyle使用过时的\tikzset
  • 对于容器使用节点,它使用 TikZ 库fit封装您的图像和图像标签
  • 首先是插入图片,然后跟在circle-label节点中的图片标签后面,最后都封装在container使用fit库中
  • positioning节点定位使用库中定义的相对坐标
\documentclass[11pt]{article}

% Packages
\usepackage{amsmath}
\usepackage[demo]{graphicx}
\usepackage{makecell}
\usepackage{media9}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\usetikzlibrary{%external,
                fit,
                positioning}
%\tikzexternalize[prefix=figures/]
%\newcommand{\etal}{\textit{et al.}}

% --------------------------- TikZ blocks - Start --------------------------------%
\tikzset{
   container/.style = {rectangle, rounded corners, draw, dashed,
                       fit=#1, inner sep=2mm, node contents={}},
circle-label/.style = {circle, draw}
        }
% --------------------------- TikZ blocks - End --------------------------------%

% Document
\begin{document}
    \begin{tikzpicture}[node distance=4mm and 3mm]
\node (g1) [inner sep=0pt] {\includegraphics[width=\linewidth]{../../images/MainArchitecture_BlockDiagram.pdf}};
\node (cl-1)    [circle-label, below left=of g1.south east] {A};
\node (c1) [container=(g1) (cl-1)];

\node (g2) [inner sep=0pt, below=of c1] {\includegraphics[width=\linewidth]{../../images/MainArchitecture_BlockDiagram.pdf}};
\node (cl-2)    [circle-label, below left=of g2.south east] {B};
\node (c2) [container=(g2) (cl-2)];

\node (g3) [inner sep=0pt, below=of c2] {\includegraphics[width=\linewidth]{../../images/MainArchitecture_BlockDiagram.pdf}};
\node (cl-3)    [circle-label, below left=of g3.south east] {C};
\node (c3) [container=(g3) (cl-3)];
    \end{tikzpicture}
    \newpage
\end{document}

答案2

基于这个答案,我修改了我的代码如下,它成功了。关键是可以通过使用选项trim\includegraphics为底部提供负值来添加所需的额外空间。就像\includegraphics[width=\linewidth, trim=0 -1cm 0 0]{../../images/RFD_BlockDiagram.pdf}

修改后的代码:

% Contains figures for the presentation
%! Author = Nagabhushan

% Preamble
\documentclass[11pt]{article}

% Packages
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{makecell}
\usepackage{media9}
\usepackage{pgfplots}
%\pgfplotsset{compat=1.17}
\usepackage{tikz}
\usetikzlibrary{shapes, arrows, positioning, calc, decorations.pathreplacing, external}
\tikzexternalize[prefix=figures/]
\newcommand{\etal}{\textit{et al.}}

% --------------------------- TikZ blocks - Start --------------------------------%
\tikzstyle{container} = [rectangle, rounded corners, draw=black, dashed]
\tikzstyle{circle-label} = [circle, text centered, draw=black]
% --------------------------- TikZ blocks - End --------------------------------%

% Document
\begin{document}
    \tikzsetnextfilename{Model_BlockDiagrams}
    \begin{tikzpicture}[node distance=2cm]
        \node (main) [container] at (current page.north) {\includegraphics[width=\linewidth]{../../images/MainArchitecture_BlockDiagram.pdf}};
        \node (mcs) [container, below of=main, yshift=-4.5cm] {\includegraphics[width=\linewidth]{../../images/MCS_BlockDiagram.pdf}};
        \node (rfd) [container, below of=mcs, yshift=-3.65cm] {\includegraphics[width=\linewidth, trim=0 -1cm 0 0]{../../images/RFD_BlockDiagram.pdf} };
        \node [circle-label, align=center, below of=main, right of=main, xshift=3.5cm] {A};
        \node [circle-label, align=center, below of=mcs, right of=mcs, xshift=3.5cm, yshift=-0.3cm] {B};
        \node [circle-label, align=center, below of=rfd, right of=rfd, xshift=3.9cm, yshift=0.4cm] {C};
    \end{tikzpicture}
    \newpage
\end{document}

方法2: 基于Zarko 的回答,下面的也有效!

% Contains figures for the presentation
%! Author = Nagabhushan

% Preamble
\documentclass[11pt]{article}

% Packages
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{makecell}
\usepackage{media9}
\usepackage{pgfplots}
%\pgfplotsset{compat=1.17}
\usepackage{tikz}
\usetikzlibrary{shapes, arrows, positioning, calc, decorations.pathreplacing, external, fit}
\tikzexternalize[prefix=figures/]
\newcommand{\etal}{\textit{et al.}}

% --------------------------- TikZ blocks - Start --------------------------------%
\tikzset{
container/.style = {rectangle, rounded corners, draw, dashed, fit=#1, inner sep=2mm, node contents={}},
circle-label/.style = {circle, draw}
}
% --------------------------- TikZ blocks - End --------------------------------%

% Document
\begin{document}
    \tikzsetnextfilename{Model_BlockDiagrams}
    \begin{tikzpicture}[node distance=4mm and 3mm]
        \node (g1) [inner sep=0pt] {\includegraphics[width=\linewidth]{../../images/MainArchitecture_BlockDiagram.pdf}};
        \node (cl-1)    [circle-label, below left=of g1.south east, yshift=1.2cm] {A};
        \node (c1) [container=(g1)];

        \node (g2) [inner sep=0pt, below=of c1] {\includegraphics[width=\linewidth]{../../images/MCS_BlockDiagram.pdf}};
        \node (cl-2)    [circle-label, below left=of g2.south east, yshift=1.2cm] {B};
        \node (c2) [container=(g2)];

        \node (g3) [inner sep=0pt, below=of c2] {\includegraphics[width=\linewidth]{../../images/RFD_BlockDiagram.pdf}};
        \node (cl-3)    [circle-label, below left=of g3.south east] {C};
        \node (c3) [container=(g3) (cl-3)];
    \end{tikzpicture}
    \newpage
\end{document}

相关内容