LaTeX 缩放 tikzpicture 不起作用

LaTeX 缩放 tikzpicture 不起作用

以下代码中的 TikZ 图片无法正确缩放。它与文本重叠。如果我注释掉transform canvas={scale=0.5}它,它就可以正常工作(但我想缩放所有内容)。

\documentclass{article}
\usepackage{subfig}
\usepackage{tikz}
\usepackage{graphicx}


\usetikzlibrary{calc,trees,positioning,arrows,chains,shapes.geometric,
  decorations.pathreplacing,decorations.pathmorphing,shapes,matrix,shapes.symbols}

\tikzset{
  >=stealth',
  punktchain/.style={
    rectangle, 
    rounded corners, 
    % fill=black!10,
    draw=black, very thick,
    text width=8em, 
    minimum height=3em, 
    text centered, 
    on chain},
  line/.style={draw, thick, <-},
  element/.style={
    tape,
    top color=white,
    bottom color=blue!50!black!60!,
    minimum width=7em,
    draw=blue!40!black!90, very thick,
    text width=7em, 
    minimum height=3.5em, 
    text centered, 
    on chain},
  every join/.style={->, thick,shorten >=1pt},
  decoration={brace},
  tuborg/.style={decorate},
  node/.style={scale=0.45},
  tubnode/.style={midway, right=4pt},
}



\newcommand\schema{

  \begin{tikzpicture}[node distance=.8cm, start chain=going below,transform canvas={scale=0.5}]
  %\begin{tikzpicture}[node distance=.8cm, start chain=going below]
    \node (preprocessing) [punktchain ]  {text text};

    \begin{scope}[start branch=venstre,
      every join/.style={->, thick, shorten <=1pt}, ]
      \node[punktchain, on chain=going left, join=by {<-}]
      (landmarks) {
        \begin{tabular}{l}
          text \\
          text \\ 
        \end{tabular}
      };
    \end{scope}

    \node[punktchain, join,] (potentialfunction) {
      \begin{tabular}{l}
        text \\
        text \\ 
      \end{tabular}
    };
    \node[punktchain, join,] (query) {text};
    \begin{scope}[start branch=venstre,
      every join/.style={->, thick, shorten <=1pt}, ]
      \node[punktchain, on chain=going left, join=by {<-}]
      (input) {
        text };
    \end{scope}

    \draw[tuborg, decoration={brace}] let \p1=(preprocessing.north), \p2=(preprocessing.south) in
    ($(1.5, \y1)$) -- ($(1.5, \y2)$) node[tubnode] {
      \begin{tabular}{l}
        text \\
        text \\
      \end{tabular}
    };

    \draw[tuborg, decoration={brace}] let \p1=(potentialfunction.north), \p2=(query.south) in
    ($(1.5, \y1)$) -- ($(1.5, \y2)$) node[tubnode] {
      \begin{tabular}{l}
        text \\
        text \\ 
      \end{tabular}
    };    
  \end{tikzpicture}
}


\begin{document}

\begin{figure}

  \centering
  \subfloat[1 ] {  \schema }
  \hspace{0.5cm}
  \subfloat[2 ] {  \schema }

  \caption{Comparison }  


\end{figure}

\end{document}

答案1

transform canvas通常应该是最后手段:它使得 TikZ 失去对节点位置的跟踪,因此造成的危害大于好处。

就你的情况而言,scale=0.5如果你让节点也可扩展,那么一个简单的方法就可以了。默认情况下,TikZ 假定你不想缩放节点,因为这会改变文本大小。你可以tikzpicture通过添加来更改此行为every node/.append style={transform shape}

或者,你可以使用\scalebox{0.5}{ \schema }


第一个例子的代码

\documentclass{article}
\usepackage{subfig}
\usepackage{tikz}
\usepackage{graphicx}


\usetikzlibrary{calc,trees,positioning,arrows,chains,shapes.geometric,
  decorations.pathreplacing,decorations.pathmorphing,shapes,matrix,shapes.symbols}

\tikzset{
  >=stealth',
  punktchain/.style={
    rectangle, 
    rounded corners, 
    % fill=black!10,
    draw=black, very thick,
    text width=8em, 
    minimum height=3em, 
    text centered, 
    on chain},
  line/.style={draw, thick, <-},
  element/.style={
    tape,
    top color=white,
    bottom color=blue!50!black!60!,
    minimum width=7em,
    draw=blue!40!black!90, very thick,
    text width=7em, 
    minimum height=3.5em, 
    text centered, 
    on chain},
  every join/.style={->, thick,shorten >=1pt},
  decoration={brace},
  tuborg/.style={decorate},
  node/.style={scale=0.45},
  tubnode/.style={midway, right=4pt},
}



\newcommand\schema{

  \begin{tikzpicture}[node distance=.8cm, start chain=going below,
  scale=0.5, every node/.append style={transform shape}]
  %\begin{tikzpicture}[node distance=.8cm, start chain=going below]
    \node (preprocessing) [punktchain ]  {text text};

    \begin{scope}[start branch=venstre,
      every join/.style={->, thick, shorten <=1pt}, ]
      \node[punktchain, on chain=going left, join=by {<-}]
      (landmarks) {
        \begin{tabular}{l}
          text \\
          text \\ 
        \end{tabular}
      };
    \end{scope}

    \node[punktchain, join,] (potentialfunction) {
      \begin{tabular}{l}
        text \\
        text \\ 
      \end{tabular}
    };
    \node[punktchain, join,] (query) {text};
    \begin{scope}[start branch=venstre,
      every join/.style={->, thick, shorten <=1pt}, ]
      \node[punktchain, on chain=going left, join=by {<-}]
      (input) {
        text };
    \end{scope}

    \draw[tuborg, decoration={brace}] let \p1=(preprocessing.north), \p2=(preprocessing.south) in
    ($(1.5, \y1)$) -- ($(1.5, \y2)$) node[tubnode] {
      \begin{tabular}{l}
        text \\
        text \\
      \end{tabular}
    };

    \draw[tuborg, decoration={brace}] let \p1=(potentialfunction.north), \p2=(query.south) in
    ($(1.5, \y1)$) -- ($(1.5, \y2)$) node[tubnode] {
      \begin{tabular}{l}
        text \\
        text \\ 
      \end{tabular}
    };    
  \end{tikzpicture}
}


\begin{document}

\begin{figure}

  \centering
  \subfloat[1 ] {  \schema }
  \hspace{0.5cm}
  \subfloat[2 ] {  \schema }

  \caption{Comparison }  


\end{figure}

\end{document}

第二个示例的代码

\documentclass{article}
\usepackage{subfig}
\usepackage{tikz}
\usepackage{graphicx}


\usetikzlibrary{calc,trees,positioning,arrows,chains,shapes.geometric,
  decorations.pathreplacing,decorations.pathmorphing,shapes,matrix,shapes.symbols}

\tikzset{
  >=stealth',
  punktchain/.style={
    rectangle, 
    rounded corners, 
    % fill=black!10,
    draw=black, very thick,
    text width=8em, 
    minimum height=3em, 
    text centered, 
    on chain},
  line/.style={draw, thick, <-},
  element/.style={
    tape,
    top color=white,
    bottom color=blue!50!black!60!,
    minimum width=7em,
    draw=blue!40!black!90, very thick,
    text width=7em, 
    minimum height=3.5em, 
    text centered, 
    on chain},
  every join/.style={->, thick,shorten >=1pt},
  decoration={brace},
  tuborg/.style={decorate},
  node/.style={scale=0.45},
  tubnode/.style={midway, right=4pt},
}



\newcommand\schema{

  \begin{tikzpicture}[node distance=.8cm, start chain=going below]
  %\begin{tikzpicture}[node distance=.8cm, start chain=going below]
    \node (preprocessing) [punktchain ]  {text text};

    \begin{scope}[start branch=venstre,
      every join/.style={->, thick, shorten <=1pt}, ]
      \node[punktchain, on chain=going left, join=by {<-}]
      (landmarks) {
        \begin{tabular}{l}
          text \\
          text \\ 
        \end{tabular}
      };
    \end{scope}

    \node[punktchain, join,] (potentialfunction) {
      \begin{tabular}{l}
        text \\
        text \\ 
      \end{tabular}
    };
    \node[punktchain, join,] (query) {text};
    \begin{scope}[start branch=venstre,
      every join/.style={->, thick, shorten <=1pt}, ]
      \node[punktchain, on chain=going left, join=by {<-}]
      (input) {
        text };
    \end{scope}

    \draw[tuborg, decoration={brace}] let \p1=(preprocessing.north), \p2=(preprocessing.south) in
    ($(1.5, \y1)$) -- ($(1.5, \y2)$) node[tubnode] {
      \begin{tabular}{l}
        text \\
        text \\
      \end{tabular}
    };

    \draw[tuborg, decoration={brace}] let \p1=(potentialfunction.north), \p2=(query.south) in
    ($(1.5, \y1)$) -- ($(1.5, \y2)$) node[tubnode] {
      \begin{tabular}{l}
        text \\
        text \\ 
      \end{tabular}
    };    
  \end{tikzpicture}
}


\begin{document}

\begin{figure}

  \centering
  \subfloat[1 ] {  \scalebox{0.5}{\schema} }
  \hspace{0.5cm}
  \subfloat[2 ] {  \scalebox{0.5}{\schema} }

  \caption{Comparison }  


\end{figure}

\end{document}

相关内容