意外地将框做得过大,无法在没有其他坐标问题的情况下删除边距

意外地将框做得过大,无法在没有其他坐标问题的情况下删除边距

我把盒子弄得太大了

看起来像这样

d

如果我把最后一个矩形缩小一点,它最终会变成这样

    \node[shape=rectangle,minimum height= 8cm] {};& & & & & &\\
& & & & & &\\ -> 2cm

ff

我该怎么做才能达到想要的效果?

\documentclass{article}
\usepackage{amsfonts}
\usepackage[normalem]{ulem}
\usepackage{geometry}
\usepackage{xeCJK}
\usepackage{atbegshi}% http://ctan.org/pkg/atbegshi
\AtBeginDocument{\AtBeginShipoutNext{\AtBeginShipoutDiscard}}
 \geometry{
 a4paper,
 total={170mm,257mm},
 left=20mm,
 top=20mm,
 }
\usepackage{adjustbox}
\usepackage{tabularx}
\usepackage[table]{xcolor}
\usepackage{amsmath}
\usepackage{graphicx} % Required for inserting images
\usepackage{tikz}
\usepackage{amsthm}
\usetikzlibrary {calc,positioning,shapes.misc}
\usetikzlibrary{matrix}
\usepackage[a4paper, total={6in, 8in}]{geometry}
\usetikzlibrary {arrows.meta}
\usetikzlibrary {shapes.geometric}
 \usepackage{algorithm}
 \usepackage{mathrsfs}
\usepackage{algpseudocode}
\usepackage{stmaryrd}
\usetikzlibrary {automata,positioning}
\usetikzlibrary{bending}
\usetikzlibrary{shapes.geometric, positioning, decorations.pathreplacing, calc}

\tikzset{
  fnode/.style={
    draw,
    % Define labels for the "f" and brackets
    label={[name=fnode-f]left:$f$},
    label={[name=fnode-leftBracket]left:$[$},
    label={[name=fnode-rightBracket]right:$]$},
    % Ensure the node content is visually centered
    label={[align=center,inner sep=1pt]center:#1},
  }
  fnode2/.style={
    draw,
    % Define labels for the "f" and brackets
    label={[name=fnode2-f]left:$extract_right$},
    label={[name=fnode2-leftBracket]left:$[$},
    label={[name=fnode2-rightBracket]right:$]$},
    % Ensure the node content is visually centered
    label={[align=center,inner sep=1pt]center:#1},
  }
}

\theoremstyle{definition}
\newtheorem{definition}{Definition}
\newtheorem{theorem}{Theorem}
\newtheorem{corollary}{Corollary}
\newtheorem{lemma}{Lemma}

\theoremstyle{remark}
\newtheorem*{remark}{Remark}

\algnewcommand\algorithmicforeach{\textbf{for each}}
\algdef{S}[FOR]{ForEach}[1]{\algorithmicforeach\ #1\ \algorithmicdo}

\title{Comparing the query complexity of active learning algorithms for deterministic finite automata}
\author{zzzz}
\date{March 2024}

\begin{document}
% Define membership queries and equivalence queries properly (what is their return value), regarding the pseudocode





\maketitle

\section{Introduction}
\addtocounter{page}{-1}
\begin{adjustbox}{width=\textwidth}
\begin{tikzpicture}


% Nodes
% \draw[help lines] (0,0) grid (14,12);
\node [matrix,draw=black] (my matrix) at (7,6)
  {
     \node[shape=rectangle, minimum width= 8.5cm,minimum height= 8cm,draw, text width=8cm, font={\fontsize{14}{15}\selectfont}, scale=0.6] {\begin{itemize}
         \item The Learner usually uses certain datastructures to maintain the observations gathered with the membership queries.
         \item By aiming for certain observations the Learner creates the automaton $\mathcal{H}$
         \item After constructing $\mathcal{H}$ an equivalence query is made, if a counter example is returned it is used to refine the hypothesis.
     \end{itemize}}; & & & & & &\node[shape=rectangle, minimum width= 8.5cm,minimum height= 8cm,draw, text width=8cm, font={\fontsize{14}{15}\selectfont}, scale=0.6] {\begin{itemize}
         \item The Teacher answers Membership- and Equivalence Querries by accessing the target automata $\mathcal{A}$ that is unknown to the Learner
         \item In a black-box-setting where $\mathcal{A}$ is unknown, membership queries and or equivaelence querries can only be approximated. We assume that the answers to the querries are correct.
     \end{itemize}}; \\
    \node[name=s,shape=diamond, minimum width= 2cm,minimum height= 2cm] {};
    & \node[shape=rectangle, minimum width= 1cm,minimum height= 2cm] {};
    &
    & \node[shape=rectangle, minimum width= 3cm,minimum height=5cm] {};
    &
    & \node[shape=rectangle, minimum width= 1cm,minimum height= 5cm] {};
    &\node[name=s2,shape=diamond, minimum width= 2cm,minimum height= 2cm] {};\\
    \node[shape=rectangle,minimum height= 8cm] {};& & & & & &\\
    & & & & & &\\
    \node[shape=rectangle,minimum height= 0.2cm] {};& & & & & &\\
  };
    \node[scale=0.8] at (7,6.8) {Mem($x$),$x\in\Sigma^*$};
    \node[scale=0.8,shape=rectangle, minimum width= 8cm,minimum height= 2cm, text width=8cm] at (7.4,5.62){\begin{itemize}
        \item $1\iff x\in\mathcal{L}(\mathcal{A}) \iff \mathcal{A}(x)=1$
        \item $0\iff x\notin\mathcal{L}(\mathcal{A}) \iff \mathcal{A}(x)= 0$
    \end{itemize}};
    \node[scale=0.8] at (7,4.3) {EQ($\mathcal{H}),\mathcal{H}\in\ \text{DFA}(\Sigma)$};
    \node[scale=0.8,shape=rectangle, minimum width= 8cm,minimum height= 2cm, text width=8cm] at (7.4,2.65){\begin{itemize}
        \item $1\iff \mathcal{H} = \mathcal{A}$
        \item $0\text{ and }c,\mathcal{H}(c)\neq \mathcal{A}(c)\iff \mathcal{H}\neq \mathcal{A}$
    \end{itemize}};


  \draw[line width=1pt,arrows = {-Latex[line width=1pt, fill=white, length=10pt]},dotted] (2.7,8) .. controls (3.2, 8.2) and (3,10) .. (2.5,10.2);

  
    \draw[line width=1pt,arrows = {-Latex[line width=1pt, fill=white, length=10pt]}, dotted] (11.3,8) .. controls (10.8, 8.2) and (11,10) .. (11.5,10.);

    


\draw[line width=0.8pt,arrows = {-Latex[line width=0.9pt, length=4pt]}] (10.34,7.43) -- (11.29,9.07);
\draw[line width=0.8pt,arrows = {-Latex[line width=0.9pt, length=4pt]}] (12.16,8.57) -- (11.21,6.93);
\draw[line width=0.8pt,arrows = {-Latex[line width=0.9pt, length=4pt]}] (2.71,9.07) -- (3.66,7.43);
\draw[line width=0.8pt,arrows = {-Latex[line width=0.9pt, length=4pt]}] (2.79,6.93) -- (1.84,8.57);

      \node[rectangle,draw, minimum width=1cm, minimum height=1cm] at (0.5,9) {$\mathcal{H}$};

      \node[rectangle,draw, minimum width=1cm, minimum height=1cm] at (13.5,9) {$\mathcal{A}$};
\node[rectangle,draw, minimum width=2.5cm, minimum height=2cm] at (12,5) {Teacher};
\node[rectangle,draw, minimum width=2.5cm, minimum height=2cm] at (2,5) {Learner};



      \draw[line width=0.8pt,arrows = {-Latex[line width=0.9pt, length=4pt]}] (4,6.5) -- (10,6.5);
      \draw[line width=0.8pt,arrows = {-Latex[line width=0.9pt, length=4pt]}] (10,6) -- (4,6);
      \draw[line width=0.8pt,arrows = {-Latex[line width=0.9pt, length=4pt]}] (4,4) -- (10,4);
      \draw[line width=0.8pt,arrows = {-Latex[line width=0.9pt, length=4pt]}] (10,3.5) -- (4,3.5);
      \node[circle, fill=black, inner sep=0pt, minimum size=4pt] at (11.3,8) {};
      \node[circle, fill=white, inner sep=0pt, minimum size=2pt] at (11.3,8) {};
      \node[circle, fill=black, inner sep=0pt, minimum size=4pt] at (2.7,8) {};
      \node[circle, fill=white, inner sep=0pt, minimum size=2pt] at (2.7,8) {};      
      
\end{tikzpicture}
\end{adjustbox}
\end{document}

答案1

这是一种更简洁的绘图方法并将其包含在主文档中。

绘画

主要观点:

  • 将一些节点放在绝对坐标中
  • 以相对的方式导出其他坐标,即与其中一些坐标相关
  • 尝试尽可能长时间地遵循默认设置
  • 引入一些专用风格

我省略了旋转的箭头,因为它们对我来说并没有真正的意义。

% ~~~ drawing ~~~~~~~~~~~~~~~~~~~~~~~~~~~
\documentclass[10pt,border=3mm]{standalone}% more useful for development
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary {arrows.meta}

% ~~~ shortcuts: texts ~~~~~~~~~
\newcommand\txtA[0]{\begin{itemize}%
         \item The Learner usually uses certain datastructures to maintain the observations gathered with the membership queries.%
         \item By aiming for certain observations the Learner creates the automaton $\mathcal{H}$%
         \item After constructing $\mathcal{H}$ an equivalence query is made, if a counter example is returned it is used to refine the hypothesis.%
     \end{itemize}}
% .............................................
\newcommand\txtB[0]{\begin{itemize}%
         \item The Teacher answers Membership- and Equivalence Querries by accessing the target automata $\mathcal{A}$ that is unknown to the Learner%
         \item In a black-box-setting where $\mathcal{A}$ is unknown, membership queries and or equivaelence querries can only be approximated. We assume that the answers to the querries are correct.%
     \end{itemize}%
}
% .............................................
\newcommand\txtC[0]{\begin{itemize}%
        \item $1\iff x\in\mathcal{L}(\mathcal{A}) \iff \mathcal{A}(x)=1$%
        \item $0\iff x\notin\mathcal{L}(\mathcal{A}) \iff \mathcal{A}(x)= 0$%
    \end{itemize}}
% .............................................
\newcommand\txtD[0]{\begin{itemize}%
        \item $1\iff \mathcal{H} = \mathcal{A}$%
        \item $0\text{ and }c,\mathcal{H}(c)\neq \mathcal{A}(c)\iff \mathcal{H}\neq \mathcal{A}$%
    \end{itemize}}
    
% ~~~ shortcuts: constants ~~~~~~~~~
\def\a{ 6mm}
\def\b{20mm}
\def\c{12mm}

% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    
\begin{document}

 \begin{tikzpicture}[
    >={Stealth},
    LT/.style   ={draw,minimum size=2cm},
    TXT/.style  ={anchor=south,draw,inner sep=6mm,minimum height=7cm},
    BX/.style   ={LT},
    arrd/.style={{Circle[open]}-{Triangle[open]},dashed,thick},
 ]
    % ~~~ nodes: formulas ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    \node (A) at (0, 0  ) {\parbox{6.5cm}{\txtC{}}};
    \node (B) at (0,-3.5) {\parbox{6.5cm}{\txtD{}}};
    
    % ~~~ nodes: L+R ~~~~~~~~~~~~~~~~~~~~~~~~~~
    \node[LT] (LE) at (-5.5,0) {Learner};
    \node[LT] (TE) at ( 5.5,0) {Teacher};
    
    % ~~~ lower arrows (relative coordinates) ~~~~~~~~~~~~~~~~~~~~~
    \draw[->]            (A.north east) -- (A.north west);  
    \draw[->] ([yshift=\a]A.north west) -- 
                        node[anchor=south]{Mem($x$),$x\in\Sigma^*$}
                        ([yshift=\a]A.north east);  
                        
    \draw[->]            (B.north east) -- (B.north west);  
    \draw[->] ([yshift=\a]B.north west) -- 
                        node[anchor=south]{EQ($\mathcal{H}),
                                \mathcal{H}\in\ \text{DFA}(\Sigma)$}
                        ([yshift=\a]B.north east);  
    
    % ~~~ nodes: upper text ~~~~~~~~~~~~~~~~~~~~~~~~~~
    \node[TXT] (L) at (-8,5) {\parbox{6cm}{\txtA{}}};
    \node[TXT] (R) at ( 8,5) {\parbox{6cm}{\txtB{}}};
    
    %  (relative coordinates)
    \node[BX] at ([yshift=-\b]L.250)    {$\mathcal{H}$};
    \node[BX] at ([yshift=-\b]R.290)    {$\mathcal{A}$};
    
    % ~~~ dashed arrow  (relative coordinates) ~~~~~~~~
    \draw[arrd] ([yshift=\c]LE. 80) to[out= 70,in=- 30] (L.300);
    \draw[arrd] ([yshift=\c]TE.110) to[out=110,in=-150] (R.240);
    
 \end{tikzpicture}

\end{document}

绘画

主要文件

和以前一样的想法。

主要.tex:

\documentclass[10pt,a4paper]{article}

\usepackage{graphicx}

\begin{document}
    Here we go:\bigskip

    \includegraphics[width=\textwidth]{tikzMarginProblems-MS}
    
    \hrule
\end{document}

主要的

答案2

以下是我的评论插图。

1. 主文件,即整个最终文件

main.tex随便你怎么称呼它。它包括tikzMarginProblems.pdf。尽可能简单和顺利。

\documentclass[10pt,a4paper]{article}

\usepackage{graphicx}

\begin{document}
    Here we go:\bigskip

    \includegraphics[width=\textwidth]{tikzMarginProblems}
\end{document}

结果

2. 麻烦制造者,外包

不幸的是,现在那幅画简直就是一场噩梦。以下是我所做的tikzMarginProblems.tex

  • 删除(注释掉)此绘图不需要的所有内容
  • 为长文本创建了一些快捷方式\txtA{}\txtD{}使您的 Tikz 代码更容易掌握
  • 切换到standalone,根据需要调整纸张大小
  • 重构了许多内联样式,以便重复使用和提高可读性,如LT..mthbx
  • 完成后只需编译,将其包含在编译主文档中

CODE,现在更清楚地发现您的问题:

% ~~~ REFACTORING ~~~~~~~~~~~~~~~~~
% documentclass standalone
% styles for cleaner code (seeing the forest again ...)
% giving up: hopeless design decisions were made ...


% ~~~ shortcuts ~~~~~~~~~
\newcommand\txtA[0]{\begin{itemize}%
         \item The Learner usually uses certain datastructures to maintain the observations gathered with the membership queries.%
         \item By aiming for certain observations the Learner creates the automaton $\mathcal{H}$%
         \item After constructing $\mathcal{H}$ an equivalence query is made, if a counter example is returned it is used to refine the hypothesis.%
     \end{itemize}}
% .............................................
\newcommand\txtB[0]{\begin{itemize}%
         \item The Teacher answers Membership- and Equivalence Querries by accessing the target automata $\mathcal{A}$ that is unknown to the Learner%
         \item In a black-box-setting where $\mathcal{A}$ is unknown, membership queries and or equivaelence querries can only be approximated. We assume that the answers to the querries are correct.%
     \end{itemize}%
}
% .............................................
\newcommand\txtC[0]{\begin{itemize}%
        \item $1\iff x\in\mathcal{L}(\mathcal{A}) \iff \mathcal{A}(x)=1$%
        \item $0\iff x\notin\mathcal{L}(\mathcal{A}) \iff \mathcal{A}(x)= 0$%
    \end{itemize}}
% .............................................
\newcommand\txtD[0]{\begin{itemize}%
        \item $1\iff \mathcal{H} = \mathcal{A}$%
        \item $0\text{ and }c,\mathcal{H}(c)\neq \mathcal{A}(c)\iff \mathcal{H}\neq \mathcal{A}$%
    \end{itemize}}

% ~~~ drawing ~~~~~~~~~~~~~~~~~~~~~~~~~~~
%\documentclass{article}
\documentclass[10pt,border=3mm]{standalone}% more useful for development
%\usepackage{amsfonts}
%\usepackage[normalem]{ulem}
%\usepackage{geometry}
%\usepackage{xeCJK}
%\usepackage{atbegshi}% http://ctan.org/pkg/atbegshi
%\AtBeginDocument{\AtBeginShipoutNext{\AtBeginShipoutDiscard}}
% \geometry{
% a4paper,
% total={170mm,257mm},
% left=20mm,
% top=20mm,
% }
%\usepackage{adjustbox}
%\usepackage{tabularx}
%\usepackage[table]{xcolor}
\usepackage{amsmath}
%\usepackage{graphicx} % Required for inserting images
\usepackage{tikz}
%\usepackage{amsthm}
%\usetikzlibrary {calc,positioning,shapes.misc}
%\usetikzlibrary{matrix}
%\usepackage[a4paper, total={6in, 8in}]{geometry}
\usetikzlibrary {arrows.meta}
\usetikzlibrary {shapes.geometric}
% \usepackage{algorithm}
% \usepackage{mathrsfs}
%\usepackage{algpseudocode}
%\usepackage{stmaryrd}
%\usetikzlibrary {automata,positioning}
%\usetikzlibrary{bending}
%\usetikzlibrary{shapes.geometric, positioning, decorations.pathreplacing, calc}

%\tikzset{
%  fnode/.style={
%    draw,
%    % Define labels for the "f" and brackets
%    label={[name=fnode-f]left:$f$},
%    label={[name=fnode-leftBracket]left:$[$},
%    label={[name=fnode-rightBracket]right:$]$},
%    % Ensure the node content is visually centered
%    label={[align=center,inner sep=1pt]center:#1},
%  }
%  fnode2/.style={
%    draw,
%    % Define labels for the "f" and brackets
%    label={[name=fnode2-f]left:$extract_right$},
%    label={[name=fnode2-leftBracket]left:$[$},
%    label={[name=fnode2-rightBracket]right:$]$},
%    % Ensure the node content is visually centered
%    label={[align=center,inner sep=1pt]center:#1},
%  }
%}

%\theoremstyle{definition}
%\newtheorem{definition}{Definition}
%\newtheorem{theorem}{Theorem}
%\newtheorem{corollary}{Corollary}
%\newtheorem{lemma}{Lemma}
%
%\theoremstyle{remark}
%\newtheorem*{remark}{Remark}
%
%\algnewcommand\algorithmicforeach{\textbf{for each}}
%\algdef{S}[FOR]{ForEach}[1]{\algorithmicforeach\ #1\ \algorithmicdo}

%\title{Comparing the query complexity of active learning algorithms for deterministic finite automata}
%\author{zzzz}
%\date{March 2024}

\begin{document}
% Define membership queries and equivalence queries properly (what is their return value), regarding the pseudocode


%\maketitle

%\section{Introduction}
%\addtocounter{page}{-1}
%\begin{adjustbox}{width=\textwidth}


\begin{tikzpicture}[
    LT/.style={draw, minimum width=2.5cm, minimum height=2cm},
    txtbx/.style={shape=rectangle, minimum width= 8.5cm,minimum height= 8cm,draw, 
                  text width=8cm, font={\fontsize{14}{15}\selectfont}, scale=0.6},
    dmnd/.style={shape=diamond, minimum width= 2cm,minimum height= 2cm},
    rec2/.style={shape=rectangle, minimum width= 1cm,minimum height= 2cm},
    lne/.style={line width=0.8pt,arrows = {-Latex[line width=0.9pt, length=4pt]}},
    crc/.style={circle, fill=black, inner sep=0pt,},
    mthbx/.style={draw, minimum width=1cm, minimum height=1cm},
]

% Nodes
% \draw[help lines] (0,0) grid (14,12);
\node [matrix,draw=blue] (my matrix) at (7,6) % <<< better use matrix here, see Ch. 59 and the Petrinet tutorial
  { % ~~~ row 1 ~~~~~~~~~~~~~~~~~~~~
     \node[txtbx] {\txtA{}}; & & & & & &
     \node[txtbx] {\txtB{}}; \\
     
    % ~~~ row 2 ~~~~~~~~~~~~~~~~~~~~
    \node[name=s,dmnd] {};
    & \node[rec2] {};
    &
    & \node[shape=rectangle, minimum width= 3cm,minimum height=5cm] {};
    &
    & \node[rec2] {};
    &\node[name=s2,dmnd] {};\\
    
    % ~~~ empty (?) rows 3+4+5 ~~~~~~~~~~~~~~~~~~~~
    \node[shape=rectangle,minimum height= 8cm] {};& & & & & &\\
    & & & & & &\\
    \node[shape=rectangle,minimum height= 0.2cm] {};& & & & & &\\
  };
    \node[scale=0.8] at (7,6.8) {Mem($x$),$x\in\Sigma^*$};
    \node[scale=0.8,shape=rectangle, minimum width= 8cm,minimum height= 2cm, text width=8cm] at (7.4,5.62){\txtC{}};
    \node[scale=0.8] at (7,4.3) {EQ($\mathcal{H}),\mathcal{H}\in\ \text{DFA}(\Sigma)$};
    \node[scale=0.8,shape=rectangle, minimum width= 8cm,minimum height= 2cm, text width=8cm] at (7.4,2.65){\txtD{}};


  \draw[line width=1pt,arrows = {-Latex[line width=1pt, fill=white, length=10pt]},dotted] (2.7,8) .. controls (3.2, 8.2) and (3,10) .. (2.5,10.2);
  
    \draw[line width=1pt,arrows = {-Latex[line width=1pt, fill=white, length=10pt]}, dotted] (11.3,8) .. controls (10.8, 8.2) and (11,10) .. (11.5,10.);


\draw[lne] (10.34,7.43) -- (11.29,9.07);
\draw[lne] (12.16,8.57) -- (11.21,6.93);
\draw[lne] (2.71,9.07) -- (3.66,7.43);
\draw[lne] (2.79,6.93) -- (1.84,8.57);

      \node[mthbx] at (0.5,9) {$\mathcal{H}$};
      \node[mthbx] at (13.5,9) {$\mathcal{A}$};
    \node[LT] at (12,5) {Teacher};% <<<
    \node[LT] at (2,5) {Learner};% <<<


      \draw[lne] (4,6.5) -- (10,6.5);
      \draw[lne] (10,6) -- (4,6);
      \draw[lne] (4,4) -- (10,4);
      \draw[lne] (10,3.5) -- (4,3.5);
      \node[crc, minimum size=4pt] at (11.3,8) {};
      \node[crc, minimum size=2pt] at (11.3,8) {};
      \node[crc, minimum size=4pt] at (2.7,8) {};
      \node[crc, minimum size=2pt] at (2.7,8) {};      
      
\end{tikzpicture}
%\end{adjustbox}
\end{document}

绘画

3. 批评者

不幸的是,很多事情并没有Tikz得到应有的改善。以下是您可以且应该改进的几件事(按任意顺序):

  • 你不使用matrix库;你的方法在pgfmanual,但最好在开始时调整它Ch. 59Petri.net教程;它将使你更好地控制行和列分离
  • 我不确定你是否需要一个矩阵;大多数事情都可以通过锚定来实现,例如,[anchor=TEXT.south]TEXT 是一个现有的坐标,比如来自\node (TEXT) at (0,0){};;参见手册
  • 我建议消除所有scale=选项;直接删除它们
  • 您可以用绝对坐标绘制箭头,但如果您使用这样的坐标和节点会更容易:\coordinate (A) (1,2); \node[whatever] (W) at (2,3) {}; \draw (A) -- (B);
  • 重新设计并简化所有样式;如此多的重复等等;您真的需要它们全部吗?
  • Tikz 策略:1) place nodes, 2) draw connections, 3) introduce intermeidate points where needed (not here) ... 10) do some fine tuning on fonts
  • 大量使用重构来保持代码干净、一目了然

重构:

  1. 写几行代码;编译并修改,直到你满意为止
  2. 概括事物,例如常用的风格等。
  3. 重复,直到完成

相关内容