如何改变图形环境的大小(不是里面的图像)

如何改变图形环境的大小(不是里面的图像)

我有一个复杂的图形(例如带有子图形)。有没有办法调整其大小,使所有图形保持相同的比例和位置?使它们一起变小等等,而不是在“包含图形”中更改大小(例如图片上方的图形)

   \documentclass{article}

    % if you need to pass options to natbib, use, e.g.:
    % \PassOptionsToPackage{numbers, compress}{natbib}
    % before loading nips_2017
    %
    % to avoid loading the natbib package, add option nonatbib:
    % \usepackage[nonatbib]{nips_2017}


    % to compile a camera-ready version, add the [final] option, e.g.:
    % \usepackage[final]{nips_2017}

    \usepackage{times}
    % For figures
    \usepackage{graphicx} % more modern
    %\usepackage{epsfig} % less modern
    %\usepackage{subfigure} 
    \usepackage{subcaption} 
    \usepackage{pgf}
    \usepackage{tikz}
    \usetikzlibrary{arrows,automata}

    \begin{document}

    \begin{figure}
    \centering
    \begin{subfigure}{\columnwidth}
        \centering
    \begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=1.5cm,semithick]
    \node[state] (A)                    {$s_0$};
    \node[state] (S) [below of=A] {$s$};
    \node[state,dashed,double] (B) [above of=A] {$\cdots$};
    \node[state,double] (C) [left of=B]         {$s_2$};
    \node[state,double] (D) [left of=C]         {$s_1$};
    \node[state,double] (E) [right of=B]        {$s_{k-1}$};
    \node[state,double] (F) [right of=E]        {$s_k$};
    \path
        (S) edge node {start} (A)
        (A) edge[dashed] (B)
        (A) edge (C)
        (A) edge (D)
        (A) edge (E)
        (A) edge (F);

    \end{tikzpicture}
    \caption{\label{fig:tree_mdp}}
    \end{subfigure}
    \begin{subfigure}{\columnwidth}
        \centering  
    %   \includegraphics[width=.8\linewidth]{tree}
        \caption{\label{fig:tree_results}}

    \end{subfigure}
    \end{figure}


    \end{document}

答案1

不幸的是,您的问题不清楚。您喜欢子图像显示在页面上吗?现在可以很好地设置成一个在另一个之上(见上图)。

在子图像必须平行的情况下,您有更多的可能性:

  • 全局更改页面布局,例如\usepackage{geometry}
  • 局部改变图形环境的宽度,如下图所示

在此处输入图片描述

在这两种情况下,我建议纠正 TikZ 图片,即考虑由库确定的定位语法positioning

   \documentclass{article}
%    \usepackage{geometry} % for global setting of page layout
%    \usepackage{times}
    % For figures
    \usepackage[demo]{graphicx} 
    \usepackage{subcaption}
%    \usepackage{pgf} % <-- unnecessary, it is loaded by tikz
    \usepackage{tikz}
    \usetikzlibrary{arrows,automata, 
                    positioning}% added, for better positioning of image elements

    \usepackage[strict]{changepage}% for local change of page layout
%---------------------------------------------------------------%
\usepackage{showframe}% to see page layout, in real document had to be removed
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

    \begin{document}
        \begin{figure}
    \centering
    \begin{subfigure}[b]{\columnwidth}
        \centering
    \begin{tikzpicture}[auto, 
    node distance=6mm and 3mm, semithick,
    state/.append style = {inner sep=2pt}
                        ]
    \node[state]        (A)                     {$s_0$};
    \node[state]        (S) [below=of A]        {$s$};
    \node[state,dashed,double] (B) [above=of A] {$\cdots$};
    \node[state,double] (C) [left=of B]         {$s_2$};
    \node[state,double] (D) [left=of C]         {$s_1$};
    \node[state,double] (E) [right=of B]        {$s_{k-1}$};
    \node[state,double] (F) [right=of E]        {$s_k$};
    \path[-stealth',shorten >=1pt]
        (S) edge node {start} (A)
        (A) edge[dashed] (B)
        (A) edge (C)
        (A) edge (D)
        (A) edge (E)
        (A) edge (F);
    \end{tikzpicture}
    \caption{\label{fig:tree_mdp}}
    \end{subfigure}
    \begin{subfigure}[b]{\columnwidth}
        \centering
    \includegraphics[width=0.8\linewidth]{tree}
        \caption{\label{fig:tree_results}}
    \end{subfigure}
        \caption{original figure}
        \end{figure}

        \begin{figure}
    \begin{adjustwidth}{}{-\dimexpr\marginparwidth+\marginparsep\relax}
    \centering
    \begin{subfigure}[b]{0.45\linewidth}
        \centering
    \begin{tikzpicture}[auto,
    node distance=7mm and 5mm, semithick,
    state/.append style = {inner sep=2pt}
                        ]
    \node[state]        (A)                     {$s_0$};
    \node[state]        (S) [below=of A]        {$s$};
    \node[state,dashed,double] (B) [above=of A] {$\cdots$};
    \node[state,double] (C) [left=of B]         {$s_2$};
    \node[state,double] (D) [left=of C]         {$s_1$};
    \node[state,double] (E) [right=of B]        {$s_{k-1}$};
    \node[state,double] (F) [right=of E]        {$s_k$};
    \path[-stealth',shorten >=1pt]
        (S) edge node {start} (A)
        (A) edge[dashed] (B)
        (A) edge (C)
        (A) edge (D)
        (A) edge (E)
        (A) edge (F);
    \end{tikzpicture}
    \caption{\label{fig:tree_mdp}}
    \end{subfigure}
        \hfill
    \begin{subfigure}[b]{0.5\linewidth}
        \centering
    \includegraphics[width=0.8\textwidth]{tree}
        \caption{\label{fig:tree_results}}
    \end{subfigure}
        \caption{modified figure}
    \end{adjustwidth}
        \end{figure}
    \end{document}

答案2

如果您确实想要扩展整个figure环境,则可以minipage在 a 中使用 a \scalebox,例如将其缩小到 70%:

\documentclass{article}

\usepackage{graphicx} % more modern
\usepackage{subcaption} 
\usepackage{tikz}
\usetikzlibrary{arrows,automata}

\begin{document}

\begin{figure}
  \centering
  \scalebox{.7}{%
    \begin{minipage}{\linewidth}
      \centering
      \begin{subfigure}{\columnwidth}
        \centering
        \begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=1.5cm,semithick]
          \node[state] (A)                    {$s_0$};
          \node[state] (S) [below of=A] {$s$};
          \node[state,dashed,double] (B) [above of=A] {$\cdots$};
          \node[state,double] (C) [left of=B]         {$s_2$};
          \node[state,double] (D) [left of=C]         {$s_1$};
          \node[state,double] (E) [right of=B]        {$s_{k-1}$};
          \node[state,double] (F) [right of=E]        {$s_k$};
          \path
          (S) edge node {start} (A)
          (A) edge[dashed] (B)
          (A) edge (C)
          (A) edge (D)
          (A) edge (E)
          (A) edge (F);

        \end{tikzpicture}
        \caption{\label{fig:tree_mdp}}
      \end{subfigure}
      \begin{subfigure}{\columnwidth}
        \centering  
        \includegraphics[width=.8\linewidth]{example-image}
        \caption{\label{fig:tree_results}}

      \end{subfigure}
    \end{minipage}
  }
\end{figure}

\end{document}

但请注意,这也会缩小线条粗细和字体粗细。所以不建议这样做。

相关内容