如何并排放置使用 TikZ 创建的两个图形

如何并排放置使用 TikZ 创建的两个图形

如何将图 1 和图 2 并排放置?代码如下。非常感谢!在此处输入图片描述

    \usepackage{tikz}
    \usetikzlibrary{shapes,arrows}
    \usetikzlibrary{positioning}
    
    
    
    \begin{figure}[H]
        \centering
        \caption{Figure 1}
        \label{fig_1}
        \vspace{0.3cm}
         
         
              
    
        \tikzset{ 
        bBlock/.style={rectangle, draw, fill=red!20, 
        text width=6em, text centered, rounded corners, minimum height=4em},
        rBlock/.style={rectangle, draw, fill= white, 
        text width=6em, text centered, rounded corners, minimum height=4em}, 
        arr/.style={line width=.5pt , draw, -latex'}        
        }

        \begin{tikzpicture}[node distance = 1cm, auto]
        
       
        \begin{scope}[xshift=8cm]
         \node [bBlock] (1) {Paper B};
         \node [rBlock, below left = of 1] (2) {Paper C};      
         \node [bBlock, above left =  of 2] (3) {Paper A};
    \end{scope}  


        \draw [arr] (1) -- node[anchor=west] {TEXT} (2);
         \draw [arr] (3) -- node[anchor=east] {TEXT} (2);

                      
             
        \end{tikzpicture}
    \end{figure} 


\begin{figure}[H]
        \centering
        \caption{Figure 2}
        \label{fig_2}
        \vspace{0.3cm}
         
         
       \tikzset{ 
        bBlock/.style={rectangle, draw, fill=red!20, 
        text width=6em, text centered, rounded corners, minimum height=4em},
        rBlock/.style={rectangle, draw, fill= white, 
        text width=6em, text centered, rounded corners, minimum height=4em}, 
        arr/.style={line width=.5pt , draw, -latex'}        
        }


    
        \begin{tikzpicture}[node distance = 1cm, auto]



      \begin{scope}[xshift=8cm]
         \node [bBlock] (1) {Paper Y};
         \node [rBlock, below left = of 1] (2) {Paper X};      
         \node [bBlock, above left =  of 2] (3) {Paper Z};
             \end{scope}  


        \draw [arr] (2) -- node[anchor=west]{TEXT} (1);
         \draw [arr] (2) -- node[anchor=east]{TEXT}  (3);


                  
        \end{tikzpicture}
    \end{figure} 

答案1

在此网站上,您可以找到许多有关如何并行设置两个数字的示例,因此就这个问题而言,您的问题是重复的......

除了这个问题之外,您的图还存在其他一些问题:图像太宽,无法放在一行中。要做到这一点,您需要放大\textwidth和缩小节点形状大小并减少节点之间的距离。例如,如以下 MWE 中所做的那样:

\documentclass{article}
\usepackage{geometry}
%--------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage[skip=1ex]{caption}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                positioning,
                quotes}


\begin{document}
    \begin{figure}[ht]
\tikzset{
    box/.style = {draw, rounded corners, fill=#1, 
                  text width=5em, align=center, 
                  minimum height=3em},
    box/.default  = red!30,
every edge/.style = {draw, thick, -Latex},
every edge quotes/.append style = {auto, font=\footnotesize\scshape}
        }
\begin{minipage}{0.5\linewidth}\centering
    \caption{Figure 1}
    \label{fig_1}
\begin{tikzpicture}[
node distance = 8mm and 4mm
                    ]
\node [box] (1) {Paper A};
\node [box=white,   below right = of 1] (2) {Paper C};
\node [box,         above right = of 2] (3) {Paper B};
%
\draw   (1) edge["TEXT" ']  (2)
        (3) edge["TEXT"]    (2);
\end{tikzpicture}
\end{minipage}%
\begin{minipage}{0.5\linewidth}\centering
    \caption{Figure 2}
    \label{fig_2}
\begin{tikzpicture}[
node distance = 9mm and 3mm
                    ]
\node [box] (1) {Paper A};
\node [box=white,   below right = of 1] (2) {Paper C};
\node [box,         above right = of 2] (3) {Paper B};
%
\draw   (2) edge["TEXT"] (1)
        (2) edge["TEXT" '] (3);
\end{tikzpicture}
\end{minipage}
    \end{figure} 
\end{document}

在此处输入图片描述

(红线表示页面布局)

相关内容